.mq4 to .cs ? how translate this code ? (Scalper robot)
16 Oct 2013, 19:03
Hi everybody,
On a russian forum, i found this robot. He looks profitable on a backtesting on mt4. But i'm not happy with mt4 when you can have a great platform like calgo.
So, i found this translater (http://2calgo.com) but mt4 robots are not supported yet.
Could someone helping me to translate this one to launch it on calgo ?
It would be great for the community.
Thx so far.
#property copyright "koingFx"
#property link ""
extern int StopLoss = 3;
extern int trailing = 2;
extern double timediff = 3.0;
extern double MaxSpread = 2.0;
extern double ManualLotsize = 0.1;
extern bool MoneyManagement = TRUE;
extern int Risk = 5;
extern bool SafetyMode = FALSE;
extern int Magic = 20102002;
double G_price_124;
int G_ticket_152;
int G_order_total_160;
bool Gi_168;
int G_count_172;
int G_count_176;
int G_datetime_180;
int G_datetime_184;
bool Gi_188;
bool Gi_192;
double Gd_200;
double Gd_208;
double G_pips_216 = 1.0;
double Gd_224;
double Gd_232;
int Gi_240;
double Gd_244;
double Gd_252;
// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
if (Digits == 3 || Digits == 5) Gi_240 = 10;
else Gi_240 = 1;
Gd_224 = MarketInfo(Symbol(), MODE_STOPLEVEL);
StopLoss = MathMax(StopLoss, Gd_224 / Gi_240);
trailing = MathMax(trailing, Gd_224 / Gi_240);
if (SafetyMode) G_pips_216 = 2;
else G_pips_216 = 1;
return (0);
}
// 52D46093050F38C27267BCE42543EF60
int deinit() {
return (0);
}
// EA2B2676C28C0DB26D39331A336C6B92
int start() {
double ask_0 = MarketInfo(Symbol(), MODE_ASK);
double bid_8 = MarketInfo(Symbol(), MODE_BID);
Gd_232 = (ask_0 - bid_8) / Point / Gi_240;
G_order_total_160 = OrdersTotal();
f0_2();
if (G_order_total_160 <= 0) {
if (Gd_244 > 0.0 || Gd_252 > 0.0) {
Gd_244 = 0;
Gd_252 = 0;
}
if (Gd_200 < Ask - G_pips_216 * Point) {
G_count_172++;
Gd_200 = NormalizeDouble(Ask, Digits);
if (Gi_188 == FALSE) {
G_datetime_180 = TimeCurrent();
Gi_188 = TRUE;
}
} else {
Gd_200 = 0;
G_count_172 = 0;
Gi_188 = FALSE;
G_datetime_180 = 0;
}
if (Gd_208 > Ask + G_pips_216 * Point) {
G_count_176++;
Gd_208 = NormalizeDouble(Ask, Digits);
if (Gi_192 == FALSE) {
G_datetime_184 = TimeCurrent();
Gi_192 = TRUE;
}
} else {
Gd_208 = 0;
G_count_176 = 0;
Gi_192 = FALSE;
G_datetime_184 = 0;
}
if (G_count_172 == G_pips_216 * Gi_240 || G_count_176 == G_pips_216 * Gi_240 && Gd_232 > MaxSpread) Print("Spread too large for ");
if (G_count_172 == G_pips_216 * Gi_240 || G_count_176 == G_pips_216 * Gi_240 && Gd_232 <= MaxSpread) {
Gi_168 = FALSE;
if (G_count_172 < G_count_176) {
if (TimeCurrent() - G_datetime_184 <= timediff) {
RefreshRates();
G_ticket_152 = OrderSend(Symbol(), OP_SELL, f0_3(), Bid, 10, 0, 0, "", Magic, 0, Red);
if (G_ticket_152 > 0) {
if (StopLoss * Gi_240 > Gd_224) {
if (OrderSelect(G_ticket_152, SELECT_BY_TICKET, MODE_TRADES)) {
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
G_price_124 = 0;
if (StopLoss * Gi_240 > Gd_224) G_price_124 = NormalizeDouble(Ask + StopLoss * Point * Gi_240, Digits);
if (!OrderModify(OrderTicket(), OrderOpenPrice(), G_price_124, 0, 0, Red)) Gi_168 = TRUE;
}
}
}
}
} else {
if (TimeCurrent() - G_datetime_180 <= timediff) {
RefreshRates();
G_ticket_152 = OrderSend(Symbol(), OP_BUY, f0_3(), Ask, 10, 0, 0, "", Magic, 0, Green);
if (G_ticket_152 > 0) {
if (StopLoss * Gi_240 > Gd_224) {
if (OrderSelect(G_ticket_152, SELECT_BY_TICKET, MODE_TRADES)) {
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
G_price_124 = 0;
if (StopLoss * Gi_240 > Gd_224) G_price_124 = NormalizeDouble(Bid - StopLoss * Point * Gi_240, Digits);
if (!OrderModify(OrderTicket(), OrderOpenPrice(), G_price_124, 0, 0, Green)) Gi_168 = TRUE;
}
}
}
}
}
Gd_200 = 0;
Gd_208 = 0;
G_count_172 = 0;
G_count_176 = 0;
Gi_188 = FALSE;
Gi_192 = FALSE;
G_datetime_180 = 0;
G_datetime_184 = 0;
}
if (Gd_200 == 0.0) Gd_200 = NormalizeDouble(Ask, Digits);
if (Gd_208 == 0.0) Gd_208 = NormalizeDouble(Ask, Digits);
} else f0_0();
return (0);
}
// CAF9B6B99962BF5C2264824231D7A40C
void f0_2() {
Comment("\n :: Server Date Time: ", Year(), ".", Month(), ".", Day(), " ", TimeToStr(TimeCurrent(), TIME_SECONDS),
"\n\n\n ------------------------------------------------------------",
"\n\n :: Broker : ", TerminalCompany(),
"\n :: Acc. Name : ", AccountName(),
"\n :: Acc, Number : ", AccountNumber(),
"\n :: Acc. Leverage: 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n\n ------------------------------------------------------------",
"\n\n :: StopLevel : ", DoubleToStr(Gd_224 / Gi_240, 1), " pips",
"\n :: Spread : ", DoubleToStr(Gd_232, 1), " pips",
"\n :: Next Lots : ", DoubleToStr(f0_3(), 2));
f0_1("z3JS" + Symbol() + "1", 15, 41, " J S", 14, "Arial Bold", Red, 0);
f0_1("z3JS" + Symbol() + "2", 15, 42, "** abrix calper EA **", 12, "Arial", DodgerBlue, 0);
}
// E82824DA3D96BDA05EEE1652D9A6C696
double f0_3() {
double Ld_0;
int Li_8;
double Ld_12;
double iopen_20 = 0;
string str_concat_28 = "";
int str_len_36 = StringLen(Symbol());
int Li_40 = StringFind(Symbol(), "USD");
double lotstep_44 = MarketInfo(Symbol(), MODE_LOTSTEP);
double Ld_52 = MarketInfo(Symbol(), MODE_MAXLOT);
double Ld_60 = MarketInfo(Symbol(), MODE_MINLOT);
if (lotstep_44 == 1.0) Li_8 = 0;
if (lotstep_44 == 0.1) Li_8 = 1;
if (lotstep_44 == 0.01) Li_8 = 2;
if (Li_40 >= 3) Ld_12 = MathMin(MarketInfo(Symbol(), MODE_MAXLOT), AccountFreeMargin() * AccountLeverage() / Bid / MarketInfo(Symbol(), MODE_LOTSIZE));
if (Li_40 == 0) Ld_12 = MathMin(MarketInfo(Symbol(), MODE_MAXLOT), AccountFreeMargin() * AccountLeverage() / MarketInfo(Symbol(), MODE_LOTSIZE));
if (Li_40 < 0) {
if (str_len_36 > 6) str_concat_28 = StringConcatenate(StringSubstr(Symbol(), 0, 3), "USD" + StringSubstr(Symbol(), 6, str_len_36));
else str_concat_28 = StringConcatenate(StringSubstr(Symbol(), 0, 3), "USD");
iopen_20 = iOpen(str_concat_28, PERIOD_H1, 0);
if (iopen_20 <= 0.0) {
if (str_len_36 > 6) str_concat_28 = StringConcatenate("USD", StringSubstr(Symbol(), 3, 3) + StringSubstr(Symbol(), 6, str_len_36));
else str_concat_28 = StringConcatenate("USD", StringSubstr(Symbol(), 3, 3));
iopen_20 = iOpen(str_concat_28, PERIOD_H1, 0);
Ld_12 = AccountFreeMargin() * AccountLeverage() / iopen_20 / MarketInfo(Symbol(), MODE_LOTSIZE);
} else Ld_12 = MathMin(MarketInfo(Symbol(), MODE_MAXLOT), AccountFreeMargin() * AccountLeverage() / iopen_20 / MarketInfo(Symbol(), MODE_LOTSIZE));
}
Ld_12 = 0.75 * Ld_12;
if (MoneyManagement) {
Ld_0 = NormalizeDouble(AccountEquity(), Li_8) * Risk / 102.0 / 100.0;
if (Ld_0 > Ld_12) Ld_0 = Ld_12;
if (Ld_0 < Ld_60) Ld_0 = Ld_60;
if (Ld_0 > Ld_52) Ld_0 = Ld_52;
} else Ld_0 = ManualLotsize;
return (NormalizeDouble(Ld_0, Li_8));
}
// 3AB2799732588E34138D987B460B8019
void f0_0() {
double bid_0;
double ask_8;
double order_open_price_16;
double Ld_24;
double Ld_32;
int magic_40;
double point_44 = MarketInfo(Symbol(), MODE_POINT);
int Li_52 = 1;
if (trailing * Gi_240 <= Gd_224) Li_52 = -1;
for (int pos_56 = OrdersTotal() - 1; pos_56 >= 0; pos_56--) {
if (OrderSelect(pos_56, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
if (OrderSymbol() == Symbol()) {
magic_40 = OrderMagicNumber();
if (magic_40 == Magic) {
if (OrderType() == OP_BUY) {
if (StopLoss * Gi_240 <= Gd_224 || Gi_168 == TRUE) {
if (OrderStopLoss() == 0.0)
if (Gd_244 == 0.0) Gd_244 = OrderOpenPrice() - StopLoss * Gi_240 * point_44;
if (OrderOpenPrice() - Ask >= StopLoss * Gi_240 * point_44) OrderClose(OrderTicket(), OrderLots(), Bid, 5 * Gi_240, Blue);
}
if (Li_52 == -1) {
order_open_price_16 = OrderOpenPrice();
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
bid_0 = Bid;
if (Gd_244 == 0.0)
if (bid_0 - trailing * Gi_240 * point_44 > order_open_price_16) Gd_244 = bid_0 - trailing * Gi_240 * point_44;
if (Gd_244 > 0.0) {
if (bid_0 < Gd_244)
if (OrderClose(OrderTicket(), OrderLots(), Bid, 5 * Gi_240, Blue)) break;
if (bid_0 - trailing * Gi_240 * point_44 > order_open_price_16 && bid_0 - trailing * Gi_240 * point_44 > Gd_244) Gd_244 = bid_0 - trailing * Gi_240 * point_44;
}
}
if (Li_52 == 1) {
order_open_price_16 = OrderOpenPrice();
Ld_24 = OrderStopLoss();
Ld_32 = Ld_24;
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
bid_0 = Bid;
if (bid_0 - trailing * Gi_240 * point_44 > order_open_price_16) Ld_32 = bid_0 - trailing * Gi_240 * point_44;
if (Ld_32 > Ld_24 && Ld_32 > order_open_price_16 && bid_0 - Ld_32 > Gd_224 * point_44) {
if (!OrderModify(OrderTicket(), order_open_price_16, NormalizeDouble(Ld_32, Digits), OrderTakeProfit(), 0)) Print("Error Occured : ", GetLastError());
else {
Gd_244 = 0;
Gd_252 = 0;
}
}
}
}
if (OrderType() == OP_SELL) {
if (StopLoss * Gi_240 <= Gd_224 || Gi_168 == TRUE) {
if (OrderStopLoss() == 0.0)
if (Gd_252 == 0.0) Gd_252 = OrderOpenPrice() + StopLoss * Gi_240 * point_44;
if (Bid - OrderOpenPrice() >= StopLoss * Gi_240 * point_44) OrderClose(OrderTicket(), OrderLots(), Ask, 5 * Gi_240, Red);
}
if (Li_52 == -1) {
order_open_price_16 = OrderOpenPrice();
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
ask_8 = Ask;
if (Gd_252 == 0.0)
if (order_open_price_16 - ask_8 > trailing * Gi_240 * point_44) Gd_252 = order_open_price_16 + trailing * Gi_240 * point_44;
if (Gd_252 > 0.0) {
if (ask_8 > Gd_252)
if (OrderClose(OrderTicket(), OrderLots(), Ask, 5 * Gi_240, Blue)) break;
if (order_open_price_16 - ask_8 > trailing * Gi_240 * point_44 && ask_8 + trailing * Gi_240 * point_44 < Gd_252) Gd_252 = ask_8 + trailing * Gi_240 * point_44;
}
}
if (Li_52 == 1) {
order_open_price_16 = OrderOpenPrice();
Ld_24 = OrderStopLoss();
Ld_32 = Ld_24;
while (!IsTradeAllowed()) Sleep(500);
RefreshRates();
ask_8 = Ask;
if (order_open_price_16 - ask_8 > trailing * Gi_240 * point_44 && Ld_24 > ask_8 + trailing * Gi_240 * point_44 || Ld_24 == 0.0) Ld_32 = ask_8 + trailing * Gi_240 * point_44;
if (Ld_32 < Ld_24 || Ld_24 == 0.0 && Ld_32 < order_open_price_16 && Ld_32 - ask_8 > Gd_224 * point_44) {
if (!OrderModify(OrderTicket(), order_open_price_16, NormalizeDouble(Ld_32, Digits), OrderTakeProfit(), 0)) {
Print("Error Occured : ", GetLastError());
continue;
}
Gd_244 = 0;
Gd_252 = 0;
}
}
}
}
}
}
}
// 4866D675DEC7EFFB3662F35D83AEC3C4
int f0_1(string A_name_0, int A_x_8, int A_y_12, string A_text_16, int A_fontsize_24, string A_fontname_28, color A_color_36, int A_window_40) {
ObjectCreate(A_name_0, OBJ_LABEL, A_window_40, 0, 0);
ObjectSet(A_name_0, OBJPROP_CORNER, 0);
ObjectSet(A_name_0, OBJPROP_COLOR, A_color_36);
ObjectSet(A_name_0, OBJPROP_XDISTANCE, A_x_8);
ObjectSet(A_name_0, OBJPROP_YDISTANCE, A_y_12);
ObjectSet(A_name_0, OBJPROP_BACK, FALSE);
ObjectSetText(A_name_0, A_text_16, A_fontsize_24, A_fontname_28, A_color_36);
return (0);
}
Replies
virtuesoft
17 Oct 2013, 10:56
What a mess! MQ4 is garbage. It looks like a hefty task at first glance. As cogs said, your best bet is probably to contact Scyware or post in the jobs section.
@virtuesoft

cogs
17 Oct 2013, 07:30
RE:
If you know what you want the bot to do, the guys over at scyware are currently making a robot up for based on my original MQL4 robot.
They have been offering a great interactive service as we go along.
I understand the codes cannot successfully be 'just converted across'.
gb1980be said:
@cogs