extern string note0 = "- Hedge trade settings";
extern double X_Pips = 25.0;
extern double TakeProfitPips = 0.0;
extern double StopLossPips = 0.0;
extern string note1 = "- Other settings";
extern int MagicNumber = 110812;
extern int Slippage = 5;
extern int DashboardDisplay = 2;
extern color DashboardColor = C'0x46,0x91,0xEC';
bool gi_132 = TRUE;
int gi_136 = 5;
double gd_unused_156 = 0.0;
double gd_unused_164 = 0.0;
double g_lotstep_172;
double gd_180;
double gd_188;
double gd_196;
double gd_204;
int gi_212;
int gia_216[11];
double gda_220[][11];
double gda_224[][11];
string gsa_228[][11];
string gsa_232[][11];
void f0_6()
{
double point_0;
double ld_unused_8;
int li_unused_16;
ArrayInitialize(gia_216, 0);
int index_20 = 0;
if (ArraySize(gda_220) > 0)
ArrayCopy(gda_224, gda_220);
else
ArrayResize(gda_224, 0);
ArrayResize(gda_220, 0);
if (ArraySize(gda_220) > 0)
ArrayInitialize(gda_220, 0);
if (ArraySize(gsa_228) > 0)
ArrayCopy(gsa_232, gsa_228);
else
ArrayResize(gsa_232, 0);
ArrayResize(gsa_228, 0);
if (ArraySize(gsa_228) > 0)
//ArrayInitialize(gsa_228, 0);
for (int pos_24 = 0; pos_24 < OrdersTotal(); pos_24++)
{
if (OrderSelect(pos_24, SELECT_BY_POS) == TRUE && OrderSymbol() == Symbol())
{
index_20++;
ArrayResize(gsa_228, 11 * index_20);
gsa_228[index_20][1] = OrderSymbol();
ArrayResize(gda_220, 11 * index_20);
gda_220[index_20][1] = OrderOpenPrice();
gda_220[index_20][2] = OrderStopLoss();
gda_220[index_20][3] = OrderTakeProfit();
gda_220[index_20][4] = OrderTicket();
gda_220[index_20][5] = OrderLots();
gda_220[index_20][6] = OrderType();
gda_220[index_20][7] = OrderMagicNumber();
if (StringSubstr(OrderComment(), 0, 6) == "from #")
gda_220[index_20][8] = 1;
else
gda_220[index_20][8] = 0;
gda_220[index_20][9] = OrderClosePrice();
gda_220[index_20][10] = OrderProfit();
gia_216[OrderType()]++;
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
gia_216[6]++;
if (OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT)
{
gia_216[7]++;
gia_216[9]++;
}
if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
{
gia_216[8]++;
gia_216[9]++;
}
gia_216[10]++;
point_0 = MarketInfo(OrderSymbol(), MODE_POINT);
li_unused_16 = MarketInfo(OrderSymbol(), MODE_DIGITS);
if (point_0 == 0.00001)
{
ld_unused_8 = 0.0001;
continue;
}
if (point_0 == 0.001)
{
ld_unused_8 = 0.01;
continue;
}
ld_unused_8 = point_0;
}
}
gda_220[0][0] = index_20;
gsa_228[0][0] = index_20;
}
void f0_14()
{
bool li_0;
for (int li_4 = 1; li_4 <= gda_224[0][0]; li_4++)
{
li_0 = FALSE;
for (int li_8 = 1; li_8 <= gda_220[0][0]; li_8++)
{
if (gda_224[li_4][4] == gda_220[li_8][4])
{
if (gda_220[li_8][2] != gda_224[li_4][2] || gda_220[li_8][3] != gda_224[li_4][3])
f0_8(li_8);
if (gda_220[li_8][6] <= 1.0 && gda_224[li_4][6] > 1.0)
f0_22(li_8);
li_0 = TRUE;
break;
}
}
if (li_0 == FALSE)
f0_23(li_4);
}
for (li_8 = 1; li_8 <= gda_220[0][0]; li_8++)
{
if (gda_220[li_8][8] <= 0.0)
{
li_0 = FALSE;
for (li_4 = 1; li_4 <= gda_224[0][0]; li_4++)
{
if (gda_220[li_8][4] == gda_224[li_4][4])
{
li_0 = TRUE;
break;
}
}
if (li_0 == FALSE)
f0_22(li_8);
}
}
}
void f0_23(int ai_0)
{
int count_4;
int error_8;
double point_12;
double point_20;
int li_unused_28;
bool is_deleted_32 = FALSE;
if (gda_224[ai_0][7] != MagicNumber)
{
if (OrderSymbol() == Symbol())
{
if (ObjectFind("buy_" + DoubleToStr(gda_224[ai_0][4], 0)) > -1)
ObjectDelete("buy_" + DoubleToStr(gda_224[ai_0][4], 0));
if (ObjectFind("sell_" + DoubleToStr(gda_224[ai_0][4], 0)) > -1)
ObjectDelete("sell_" + DoubleToStr(gda_224[ai_0][4], 0));
}
for (int pos_44 = OrdersTotal() - 1; pos_44 >= 0; pos_44--)
{
if (OrderSelect(pos_44, SELECT_BY_POS) == TRUE && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderComment() == DoubleToStr(gda_224[ai_0][4], 0))
{
if (OrderType() > OP_SELL)
{
count_4 = 0;
for (is_deleted_32 = OrderDelete(OrderTicket()); !is_deleted_32 && count_4 <= gi_136; is_deleted_32 = OrderDelete(OrderTicket()))
{
error_8 = GetLastError();
Print("OrderDelete error (" + error_8 + "): " + f0_20(error_8) + "; OrderTicket: " + OrderTicket() + ";");
if (error_8 != 0 /* NO_ERROR */ && error_8 != 4 /* SERVER_BUSY */ && error_8 != 6 /* NO_CONNECTION */ && error_8 != 128 /* TRADE_TIMEOUT */ && error_8 != 129 /* INVALID_PRICE */ &&
error_8 != 130 /* INVALID_STOPS */ && error_8 != 135 /* PRICE_CHANGED */ && error_8 != 136 /* OFF_QUOTES */ && error_8 != 137 /* BROKER_BUSY */ && error_8 != 138 /* REQUOTE */ &&
error_8 != 145 /* TRADE_MODIFY_DENIED */ && error_8 != 146 /* TRADE_CONTEXT_BUSY */)
break;
if (count_4 >= gi_136)
break;
Sleep(1000);
if (error_8 == 128 /* TRADE_TIMEOUT */ || error_8 == 129 /* INVALID_PRICE */ || error_8 == 130 /* INVALID_STOPS */ || error_8 == 136 /* OFF_QUOTES */ || error_8 == 145 /* TRADE_MODIFY_DENIED */ ||
error_8 == 146 /* TRADE_CONTEXT_BUSY */)
{
Print("EA must wait a few seconds before attempting to repeat the last trading action to obey MQL rules");
Sleep(5000);
}
count_4++;
Print("OrderDelete retry #" + count_4);
RefreshRates();
}
}
if (OrderSymbol() == Symbol())
{
if (error_8 > 1 /* NO_RESULT */)
{
point_12 = MarketInfo(OrderSymbol(), MODE_POINT);
li_unused_28 = MarketInfo(OrderSymbol(), MODE_DIGITS);
if (point_12 == 0.00001)
point_20 = 0.0001;
else
{
if (point_12 == 0.001)
point_20 = 0.01;
else
point_20 = point_12;
}
f0_9("Hedge EA Demo" + "_error_close_trade_" + Time[0], "ce" + error_8, Yellow, Time[0], Low[0] - 2.0 * point_20);
}
}
}
}
}
}
void f0_22(int ai_0)
{
int li_4;
double ld_8;
double ld_16;
double ld_24;
double ld_32;
double point_40;
double point_48;
int digits_56;
if (gda_220[ai_0][7] != MagicNumber)
{
ld_24 = 0;
ld_32 = 0;
if (gda_220[ai_0][6] <= 1.0)
{
point_40 = MarketInfo(gsa_228[ai_0][1], MODE_POINT);
digits_56 = MarketInfo(gsa_228[ai_0][1], MODE_DIGITS);
if (point_40 == 0.00001)
point_48 = 0.0001;
else
{
if (point_40 == 0.001)
point_48 = 0.01;
else
point_48 = point_40;
}
li_4 = MathAbs(gda_220[ai_0][6] - 1.0);
if (li_4 == 0)
ld_8 = NormalizeDouble(gda_220[ai_0][1] + X_Pips * point_48, digits_56);
else
ld_8 = NormalizeDouble(gda_220[ai_0][1] - X_Pips * point_48, digits_56);
li_4 += 4;
ld_16 = f0_18(gda_220[ai_0][5]);
if (gda_220[ai_0][6] == 0.0)
{
if (StopLossPips > 0.0)
ld_24 = StopLossPips;
else
if (gda_220[ai_0][2] > 0.0)
ld_24 = NormalizeDouble((gda_220[ai_0][1] - gda_220[ai_0][2]) / point_48, 1);
if (TakeProfitPips > 0.0)
ld_32 = TakeProfitPips;
else
if (gda_220[ai_0][3] > 0.0)
ld_32 = NormalizeDouble((gda_220[ai_0][3] - gda_220[ai_0][1]) / point_48, 1);
}
else
{
if (gda_220[ai_0][6] == 1.0)
{
if (StopLossPips > 0.0)
ld_24 = StopLossPips;
else
if (gda_220[ai_0][2] > 0.0)
ld_24 = NormalizeDouble((gda_220[ai_0][2] - gda_220[ai_0][1]) / point_48, 1);
if (TakeProfitPips > 0.0)
ld_32 = TakeProfitPips;
else
if (gda_220[ai_0][3] > 0.0)
ld_32 = NormalizeDouble((gda_220[ai_0][1] - gda_220[ai_0][3]) / point_48, 1);
}
}
f0_16(gsa_228[ai_0][1], li_4, ld_8, ld_16, Slippage, ld_24, ld_32, DoubleToStr(gda_220[ai_0][4], 0), 0, MagicNumber, 1, f0_17(li_4));
}
}
}
void f0_8(int ai_0)
{
int count_4;
int error_8;
double order_stoploss_12;
double order_takeprofit_20;
double point_28;
double point_36;
int digits_44;
if (gda_220[ai_0][7] != MagicNumber)
{
order_stoploss_12 = 0;
order_takeprofit_20 = 0;
for (int pos_48 = 0; pos_48 < OrdersTotal(); pos_48++)
{
if (OrderSelect(pos_48, SELECT_BY_POS) == TRUE && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderComment() == DoubleToStr(gda_220[ai_0][4], 0) && OrderStopLoss() == 0.0 || OrderTakeProfit() == 0.0)
{
point_28 = MarketInfo(OrderSymbol(), MODE_POINT);
digits_44 = MarketInfo(OrderSymbol(), MODE_DIGITS);
if (point_28 == 0.00001)
point_36 = 0.0001;
else
{
if (point_28 == 0.001)
point_36 = 0.01;
else
point_36 = point_28;
}
if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
{
if (StopLossPips > 0.0)
order_stoploss_12 = NormalizeDouble(OrderOpenPrice() - StopLossPips * point_36, digits_44);
else
{
if (gda_220[ai_0][2] > 0.0)
order_stoploss_12 = NormalizeDouble(OrderOpenPrice() - MathAbs(gda_220[ai_0][1] - gda_220[ai_0][2]), digits_44);
else
order_stoploss_12 = OrderStopLoss();
}
if (TakeProfitPips > 0.0)
order_takeprofit_20 = NormalizeDouble(OrderOpenPrice() + TakeProfitPips * point_36, digits_44);
else
{
if (gda_220[ai_0][3] > 0.0)
order_takeprofit_20 = NormalizeDouble(OrderOpenPrice() + MathAbs(gda_220[ai_0][3] - gda_220[ai_0][1]), digits_44);
else
order_takeprofit_20 = OrderTakeProfit();
}
}
else
{
if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
{
if (StopLossPips > 0.0)
order_stoploss_12 = NormalizeDouble(OrderOpenPrice() + StopLossPips * point_36, digits_44);
else
{
if (gda_220[ai_0][2] > 0.0)
order_stoploss_12 = NormalizeDouble(OrderOpenPrice() + MathAbs(gda_220[ai_0][2] - gda_220[ai_0][1]), digits_44);
else
order_stoploss_12 = OrderStopLoss();
}
if (TakeProfitPips > 0.0)
order_takeprofit_20 = NormalizeDouble(OrderOpenPrice() - TakeProfitPips * point_36, digits_44);
else
{
if (gda_220[ai_0][3] > 0.0)
order_takeprofit_20 = NormalizeDouble(OrderOpenPrice() - MathAbs(gda_220[ai_0][1] - gda_220[ai_0][3]), digits_44);
else
order_takeprofit_20 = OrderTakeProfit();
}
}
}
if (NormalizeDouble(order_stoploss_12, digits_44) == NormalizeDouble(OrderStopLoss(), digits_44) && NormalizeDouble(order_takeprofit_20, digits_44) == NormalizeDouble(OrderTakeProfit(), digits_44) || order_stoploss_12 == 0.0 && order_takeprofit_20 == 0.0)
continue;
count_4 = 0;
while (!OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_12, order_takeprofit_20, OrderExpiration()) && count_4 <= gi_136)
{
error_8 = GetLastError();
Print("OrderModify error (" + error_8 + "): " + f0_20(error_8) + "; OrderTicket: " + OrderTicket() + "; OrderOpenPrice: " + DoubleToStr(OrderOpenPrice(), Digits) +
"; StopLoss: " + DoubleToStr(order_stoploss_12, Digits) + "; TakeProfit: " + DoubleToStr(order_takeprofit_20, Digits));
if (error_8 != 0 /* NO_ERROR */ && error_8 != 4 /* SERVER_BUSY */ && error_8 != 6 /* NO_CONNECTION */ && error_8 != 128 /* TRADE_TIMEOUT */ && error_8 != 129 /* INVALID_PRICE */ &&
error_8 != 130 /* INVALID_STOPS */ && error_8 != 135 /* PRICE_CHANGED */ && error_8 != 136 /* OFF_QUOTES */ && error_8 != 137 /* BROKER_BUSY */ && error_8 != 138 /* REQUOTE */ &&
error_8 != 145 /* TRADE_MODIFY_DENIED */ && error_8 != 146 /* TRADE_CONTEXT_BUSY */)
break;
Sleep(1000);
if (error_8 == 128 /* TRADE_TIMEOUT */ || error_8 == 129 /* INVALID_PRICE */ || error_8 == 130 /* INVALID_STOPS */ || error_8 == 136 /* OFF_QUOTES */ || error_8 == 145 /* TRADE_MODIFY_DENIED */ ||
error_8 == 146 /* TRADE_CONTEXT_BUSY */)
{
Print("EA must wait a few seconds before attempting to repeat the last trading action to obey MQL rules");
Sleep(5000);
}
count_4++;
Print("OrderModify retry #" + count_4);
RefreshRates();
}
if (OrderSymbol() == Symbol())
if (error_8 > 1 /* NO_RESULT */)
f0_9("Hedge EA Demo" + "_error_modify_trade_" + Time[0], "me" + error_8, Red, Time[0], Low[0] - 2.0 * point_36);
}
}
}
}
int init()
{
gi_132 = TRUE;
/*if (!f0_3()) {
f0_7("Hedge EA Demo" + " is allowed to be used only on MT4 demo account", 1, 1, 1);
return (0);
}*/
if (!IsConnected())
Alert("Hedge EA Demo" + " v" + "1.0" + ": No connection with broker server! EA will start running once connection established");
if (!IsExpertEnabled())
Alert("Hedge EA Demo" + " v" + "1.0" + ": Please enable \"Expert Advisors\" in the top toolbar of Metatrader to run this EA");
if (!IsTradeAllowed())
{
Alert("Hedge EA Demo" + " v" + "1.0" + ": Trade is not allowed. EA cannot run. Please check \"Allow live trading\" in the \"Common\" tab of the EA properties window", 1, 1, 1);
}
g_lotstep_172 = MarketInfo(Symbol(), MODE_LOTSTEP);
gd_180 = MarketInfo(Symbol(), MODE_MINLOT);
gd_188 = MarketInfo(Symbol(), MODE_MAXLOT);
gi_212 = f0_21(g_lotstep_172);
if (Digits == 5 || Digits == 3)
Slippage = 10 * Slippage;
f0_6();
//if (IsTesting() && AccountNumber() == 2847085) OrderSend(Symbol(), OP_SELL, 0.1, Bid, 0, Bid + 1000.0 * Point, Bid - 400.0 * Point);
return(0);
}
int deinit()
{
Comment("");
f0_19();
return(0);
}
void f0_19()
{
for (int li_0 = ObjectsTotal() - 1; li_0 >= 0; li_0--)
if (StringSubstr(ObjectName(li_0), 0, StringLen("Hedge EA Demo")) == "Hedge EA Demo")
ObjectDelete(ObjectName(li_0));
}
int f0_21(double ad_0)
{
if (ad_0 <= 0.0)
return(0);
double ld_ret_8 = 0;
while (ad_0 < 1.0)
{
ld_ret_8++;
ad_0 = 10.0 * ad_0;
}
return(ld_ret_8);
}
string f0_15(int ai_0)
{
switch (ai_0)
{
case 0:
return("BUY");
case 1:
return("SELL");
case 2:
return("BUY LIMIT");
case 3:
return("SELL LIMIT");
case 4:
return("BUY STOP");
case 5:
return("SELL STOP");
}
return("N/A");
}
int f0_17(int ai_0)
{
if (ai_0 == 0 || ai_0 == 2 || ai_0 == 4)
return(16711680);
return(255);
}
void f0_9(string a_name_0, string a_text_8, color a_color_16, int a_datetime_20, double a_price_24)
{
if (ObjectFind(a_name_0) == -1)
ObjectCreate(a_name_0, OBJ_TEXT, 0, a_datetime_20, a_price_24);
ObjectSetText(a_name_0, a_text_8, 8, "Arial Bold", a_color_16);
}
int f0_12(int ai_0, int ai_4, string a_symbol_8, double ad_16, double &ad_24, double ad_32, double ad_40, int &a_stoplevel_48)
{
int li_64;
double point_80;
if (ad_24 <= 0.0)
return(0);
string ls_52 = "market";
int li_60 = 0;
int digits_68 = MarketInfo(a_symbol_8, MODE_DIGITS);
double point_72 = MarketInfo(a_symbol_8, MODE_POINT);
if (point_72 == 0.00001)
point_80 = 0.0001;
else
{
if (point_72 == 0.001)
point_80 = 0.01;
else
point_80 = point_72;
}
double ld_88 = ad_24;
a_stoplevel_48 = MarketInfo(a_symbol_8, MODE_STOPLEVEL);
if (ai_0 == 0)
li_60 = (ad_40 - ad_24) / point_72;
if (ai_0 == 1)
li_60 = (ad_24 - ad_32) / point_72;
if (ai_0 == 4)
li_60 = (ad_16 - ad_24) / point_72;
if (ai_0 == 2)
li_60 = (ad_16 - ad_24) / point_72;
if (ai_0 == 5)
li_60 = (ad_24 - ad_16) / point_72;
if (ai_0 == 3)
li_60 = (ad_24 - ad_16) / point_72;
if (li_60 < a_stoplevel_48)
{
li_64 = a_stoplevel_48 - li_60;
if (li_64 > 0)
{
if (ai_0 == 0)
ad_24 = NormalizeDouble(ad_40 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 1)
ad_24 = NormalizeDouble(ad_32 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 4)
ad_24 = NormalizeDouble(ad_16 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 2)
ad_24 = NormalizeDouble(ad_16 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 5)
ad_24 = NormalizeDouble(ad_16 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 3)
ad_24 = NormalizeDouble(ad_16 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 2 || ai_0 == 4 || ai_0 == 3 || ai_0 == 5)
ls_52 = "open";
if (ai_0 == 0)
ls_52 = "market BID";
if (ai_0 == 1)
ls_52 = "market ASK";
Print(f0_15(ai_0) + " #" + ai_4 + " stop loss adjusted by " + DoubleToStr(li_64 * point_72 / point_80, 1) + " pips because it was too close to " + ls_52 + " price (Ask: " + DoubleToStr(ad_32, digits_68) + "; Bid: " + DoubleToStr(ad_40, digits_68) + "; Distance: " + DoubleToStr(li_60 * point_72 / point_80, 1) + " pips)");
Print(f0_15(ai_0) + " #" + ai_4 + " New stop loss " + DoubleToStr(ad_24, digits_68) + "; Old stop loss " + DoubleToStr(ld_88, digits_68) + "; Minimum distance between stop loss and " + ls_52 + " price (StopLevel) must be at least " + DoubleToStr(a_stoplevel_48 * point_72 / point_80, 1) + " pips or the size of the spread");
return(1);
}
}
else
return(0);
return(0);
}
int f0_1(int ai_0, int ai_4, string a_symbol_8, double ad_16, double &ad_24, double ad_32, double ad_40, int &a_stoplevel_48)
{
int li_64;
double point_80;
if (ad_24 <= 0.0)
return(0);
string ls_52 = "market";
int li_60 = 0;
int digits_68 = MarketInfo(a_symbol_8, MODE_DIGITS);
double point_72 = MarketInfo(a_symbol_8, MODE_POINT);
if (point_72 == 0.00001)
point_80 = 0.0001;
else
{
if (point_72 == 0.001)
point_80 = 0.01;
else
point_80 = point_72;
}
double ld_88 = ad_24;
a_stoplevel_48 = MarketInfo(a_symbol_8, MODE_STOPLEVEL);
if (ai_0 == 0)
li_60 = (ad_24 - ad_40) / point_72;
if (ai_0 == 1)
li_60 = (ad_32 - ad_24) / point_72;
if (ai_0 == 4)
li_60 = (ad_24 - ad_16) / point_72;
if (ai_0 == 2)
li_60 = (ad_24 - ad_16) / point_72;
if (ai_0 == 5)
li_60 = (ad_16 - ad_24) / point_72;
if (ai_0 == 3)
li_60 = (ad_16 - ad_24) / point_72;
if (li_60 < a_stoplevel_48)
{
li_64 = a_stoplevel_48 - li_60;
if (li_64 > 0)
{
if (ai_0 == 0)
ad_24 = NormalizeDouble(ad_40 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 1)
ad_24 = NormalizeDouble(ad_32 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 4)
ad_24 = NormalizeDouble(ad_16 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 2)
ad_24 = NormalizeDouble(ad_16 + a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 5)
ad_24 = NormalizeDouble(ad_16 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 3)
ad_24 = NormalizeDouble(ad_16 - a_stoplevel_48 * point_72, digits_68);
if (ai_0 == 2 || ai_0 == 4 || ai_0 == 3 || ai_0 == 5)
ls_52 = "open";
if (ai_0 == 0)
ls_52 = "market BID";
if (ai_0 == 1)
ls_52 = "market ASK";
Print(f0_15(ai_0) + " #" + ai_4 + " take profit adjusted by " + DoubleToStr(li_64 * point_72 / point_80, 1) + " pips because it was too close to " + ls_52 + " price (Ask: " + DoubleToStr(ad_32, digits_68) + "; Bid: " + DoubleToStr(ad_40, digits_68) + "; Distance: " + DoubleToStr(li_60 * point_72 / point_80, 1) + " pips)");
Print(f0_15(ai_0) + " #" + ai_4 + " New take profit " + DoubleToStr(ad_24, digits_68) + "; Old take profit " + DoubleToStr(ld_88, digits_68) + "; Minimum distance between take profit and " + ls_52 + " price (StopLevel) must be at least " + DoubleToStr(a_stoplevel_48 * point_72 / point_80, 1) + " pips or the size of the spread");
return(1);
}
}
else
return(0);
return(0);
}
int f0_10(int ai_0, string a_symbol_4, double &ad_12, double &a_ask_20, double &a_bid_28, int &a_stoplevel_36, bool ai_40)
{
int li_48;
double point_64;
int li_44 = 0;
int digits_52 = MarketInfo(a_symbol_4, MODE_DIGITS);
double point_56 = MarketInfo(a_symbol_4, MODE_POINT);
if (point_56 == 0.00001)
point_64 = 0.0001;
else
{
if (point_56 == 0.001)
point_64 = 0.01;
else
point_64 = point_56;
}
int count_72 = 0;
while (count_72 < gi_136)
{
count_72++;
a_stoplevel_36 = MarketInfo(a_symbol_4, MODE_STOPLEVEL);
if (ai_0 == 2 || ai_0 == 4 || ai_0 == 3 || ai_0 == 5)
{
if (ai_0 == 4)
li_44 = (ad_12 - a_ask_20) / point_56;
if (ai_0 == 2)
li_44 = (a_ask_20 - ad_12) / point_56;
if (ai_0 == 5)
li_44 = (a_bid_28 - ad_12) / point_56;
if (ai_0 == 3)
li_44 = (ad_12 - a_bid_28) / point_56;
if (li_44 >= a_stoplevel_36)
return(1);
if (!ai_40)
{
Print(f0_15(ai_0) + " entry price " + DoubleToStr(ad_12, digits_52) + " is too close to market price (Ask: " + DoubleToStr(a_ask_20, digits_52) + "; Bid: " + DoubleToStr(a_bid_28, digits_52) + "; Distance: " + DoubleToStr(li_44 * point_56 / point_64, 1) + " pips)");
Print("Can not place " + f0_15(ai_0) + " order because StopLevel (" + DoubleToStr(a_stoplevel_36 * point_56 / point_64, 1) + " pips) rules disrupted");
return(0);
}
li_48 = a_stoplevel_36 - li_44;
if (li_48 <= Slippage)
{
if (ai_0 == 4)
ad_12 = NormalizeDouble(ad_12 + li_48 * point_56, digits_52);
if (ai_0 == 2)
ad_12 = NormalizeDouble(ad_12 - li_48 * point_56, digits_52);
if (ai_0 == 5)
ad_12 = NormalizeDouble(ad_12 - li_48 * point_56, digits_52);
if (ai_0 == 3)
ad_12 = NormalizeDouble(ad_12 + li_48 * point_56, digits_52);
Print(f0_15(ai_0) + " entry price adjusted by " + DoubleToStr(li_48 * point_56 / point_64, 1) + " pips because it was too close to market price (Ask: " + DoubleToStr(a_ask_20, digits_52) + "; Bid: " + DoubleToStr(a_bid_28, digits_52) + "; Distance: " + DoubleToStr(li_44 * point_56 / point_64, 1) + " pips)");
Print("New " + f0_15(ai_0) + " entry price " + DoubleToStr(ad_12, digits_52) + "; StopLevel " + DoubleToStr(a_stoplevel_36 * point_56 / point_64, 1) + " pips; Slippage: " + DoubleToStr(Slippage * point_56 / point_64, 1) + " pips;");
return(1);
}
Print(f0_15(ai_0) + " entry price " + DoubleToStr(ad_12, digits_52) + " is too close to market price (Ask: " + DoubleToStr(a_ask_20, digits_52) + "; Bid: " + DoubleToStr(a_bid_28, digits_52) + "; Distance: " + DoubleToStr(li_44 * point_56 / point_64, 1) + " pips)");
Print("Can not place " + f0_15(ai_0) + " order because StopLevel (" + DoubleToStr(a_stoplevel_36 * point_56 / point_64, 1) + " pips) rules disrupted and Slippage (" + DoubleToStr(Slippage * point_56 / point_64, 1) + " pips) does not allow to adjust the entry price by " + DoubleToStr(li_48 * point_56 / point_64, 1) + " pips");
if (count_72 >= gi_136)
return(0);
Sleep(5000);
RefreshRates();
a_bid_28 = MarketInfo(a_symbol_4, MODE_BID);
a_ask_20 = MarketInfo(a_symbol_4, MODE_ASK);
continue;
return(1);
}
}
return(0);
}
int f0_16(string a_symbol_0, int a_cmd_8, double a_price_12, double a_lots_20, int a_slippage_28, double ad_32, double ad_40, string a_comment_48, int a_datetime_56, int a_magic_60, int ai_64 = 1, color a_color_68 = -2)
{
int stoplevel_108;
double point_144;
if (f0_5() < 0)
return(-1);
bool li_72 = FALSE;
bool li_76 = FALSE;
int count_100 = 0;
int error_104 = 0;
if (a_symbol_0 == "")
a_symbol_0 = Symbol();
RefreshRates();
double bid_116 = MarketInfo(a_symbol_0, MODE_BID);
double ask_124 = MarketInfo(a_symbol_0, MODE_ASK);
int digits_132 = MarketInfo(a_symbol_0, MODE_DIGITS);
double point_136 = MarketInfo(a_symbol_0, MODE_POINT);
if (point_136 == 0.00001)
point_144 = 0.0001;
else
{
if (point_136 == 0.001)
point_144 = 0.01;
else
point_144 = point_136;
}
a_price_12 = NormalizeDouble(a_price_12, digits_132);
double price_88 = NormalizeDouble(a_price_12, digits_132);
int cmd_112 = a_cmd_8;
if (a_cmd_8 > OP_SELL)
{
if (a_cmd_8 == OP_SELLSTOP)
if (a_price_12 >= bid_116)
li_72 = TRUE;
if (a_cmd_8 == OP_BUYSTOP)
if (a_price_12 <= ask_124)
li_72 = TRUE;
if (a_cmd_8 == OP_SELLLIMIT)
if (a_price_12 <= bid_116)
li_72 = TRUE;
if (a_cmd_8 == OP_BUYLIMIT)
if (a_price_12 >= ask_124)
li_72 = TRUE;
if (li_72)
{
Print("Incorrect " + f0_15(a_cmd_8) + " entry price " + DoubleToStr(a_price_12, digits_132) + " (Ask: " + DoubleToStr(ask_124, digits_132) + "; Bid: " + DoubleToStr(bid_116, digits_132) + ")");
return(0);
}
}
else
{
if (a_cmd_8 < OP_BUY)
return(0);
if (a_cmd_8 == OP_BUY || a_cmd_8 == OP_SELL)
li_76 = TRUE;
if (a_cmd_8 == OP_BUY)
{
if (a_price_12 > ask_124)
a_cmd_8 = 4;
else
a_cmd_8 = 2;
}
else
{
if (a_cmd_8 == OP_SELL)
{
if (a_price_12 > bid_116)
a_cmd_8 = 3;
else
{
a_cmd_8 = 5;
if (false)
return(0);
}
}
}
}
if (a_color_68 == -2)
a_color_68 = f0_17(a_cmd_8);
if (!f0_10(a_cmd_8, a_symbol_0, a_price_12, ask_124, bid_116, stoplevel_108, 0))
return(0);
int ticket_96 = OrderSend(a_symbol_0, a_cmd_8, a_lots_20, a_price_12, a_slippage_28, 0, 0, a_comment_48, a_magic_60, a_datetime_56, a_color_68);
if (ticket_96 <= 0)
{
error_104 = GetLastError();
Print("OrderSend error (" + error_104 + "): " + f0_20(error_104) + "; OrderType: " + a_cmd_8 + "; LotSize: " + DoubleToStr(a_lots_20, gi_212) + "; Entry Price: " +
DoubleToStr(a_price_12, digits_132) + "; Ask: " + DoubleToStr(ask_124, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_ASK), digits_132) + "; Bid: " + DoubleToStr(bid_116, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_BID), digits_132) + "; STOPLEVEL: " + DoubleToStr(stoplevel_108 * point_136 / point_144, 1) + ";");
if (error_104 > 1 /* NO_RESULT */)
if (a_symbol_0 == Symbol())
f0_9("error_open_trade_" + Time[0], "oe" + error_104, a_color_68, Time[0], Low[0] - 2.0 * point_144);
if (error_104 == 5 /* OLD_VERSION */ || error_104 == 7 /* NOT_ENOUGH_RIGHTS */ || error_104 == 64 /* ACCOUNT_DISABLED */ || error_104 == 65 /* INVALID_ACCOUNT */)
{
gi_132 = FALSE;
return(0);
}
if (error_104 != 0 /* NO_ERROR */ && error_104 != 4 /* SERVER_BUSY */ && error_104 != 6 /* NO_CONNECTION */ && error_104 != 128 /* TRADE_TIMEOUT */ && error_104 != 129 /* INVALID_PRICE */ &&
error_104 != 130 /* INVALID_STOPS */ && error_104 != 135 /* PRICE_CHANGED */ && error_104 != 136 /* OFF_QUOTES */ && error_104 != 137 /* BROKER_BUSY */ && error_104 != 138 /* REQUOTE */ &&
error_104 != 145 /* TRADE_MODIFY_DENIED */ && error_104 != 146 /* TRADE_CONTEXT_BUSY */)
return(0);
if (error_104 == 128 /* TRADE_TIMEOUT */ || error_104 == 129 /* INVALID_PRICE */ || error_104 == 130 /* INVALID_STOPS */ || error_104 == 136 /* OFF_QUOTES */ || error_104 == 145 /* TRADE_MODIFY_DENIED */ ||
error_104 == 146 /* TRADE_CONTEXT_BUSY */)
{
Print("EA must wait a few seconds before attempting to repeat the last trading action to obey MQL rules");
Sleep(5000);
}
}
count_100 = 1;
while (ticket_96 <= 0 && count_100 <= gi_136)
{
Sleep(1000);
count_100++;
Print("OrderSend retry #" + count_100);
if (error_104 == 147 /* TRADE_EXPIRATION_DENIED */)
{
a_datetime_56 = 0;
Print("Expiration for trade #" + OrderTicket() + " was removed because broker does not allow it");
}
RefreshRates();
bid_116 = MarketInfo(a_symbol_0, MODE_BID);
ask_124 = MarketInfo(a_symbol_0, MODE_ASK);
if (error_104 == 130 /* INVALID_STOPS */)
{
if (li_76)
{
a_price_12 = price_88;
a_cmd_8 = cmd_112;
if (a_cmd_8 == OP_BUY)
{
if (a_price_12 > bid_116)
a_cmd_8 = 4;
else
a_cmd_8 = 2;
}
else
{
if (cmd_112 == OP_SELL)
{
if (a_price_12 > bid_116)
a_cmd_8 = 3;
else
a_cmd_8 = 5;
}
}
}
}
if (!f0_10(a_cmd_8, a_symbol_0, a_price_12, ask_124, bid_116, stoplevel_108, 0))
return(0);
ticket_96 = OrderSend(a_symbol_0, a_cmd_8, a_lots_20, a_price_12, a_slippage_28, 0, 0, a_comment_48, a_magic_60, a_datetime_56, a_color_68);
if (ticket_96 <= 0)
{
error_104 = GetLastError();
Print("OrderSend error (" + error_104 + "): " + f0_20(error_104) + "; OrderType: " + a_cmd_8 + "; LotSize: " + DoubleToStr(a_lots_20, gi_212) + "; Entry Price: " +
DoubleToStr(a_price_12, digits_132) + "; Ask: " + DoubleToStr(ask_124, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_ASK), digits_132) + "; Bid: " + DoubleToStr(bid_116, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_BID), digits_132) + "; STOPLEVEL: " + DoubleToStr(stoplevel_108 * point_136 / point_144, 1) + ";");
if (error_104 != 0 /* NO_ERROR */ && error_104 != 4 /* SERVER_BUSY */ && error_104 != 6 /* NO_CONNECTION */ && error_104 != 128 /* TRADE_TIMEOUT */ && error_104 != 129 /* INVALID_PRICE */ &&
error_104 != 130 /* INVALID_STOPS */ && error_104 != 135 /* PRICE_CHANGED */ && error_104 != 136 /* OFF_QUOTES */ && error_104 != 137 /* BROKER_BUSY */ && error_104 != 138 /* REQUOTE */ &&
error_104 != 145 /* TRADE_MODIFY_DENIED */ && error_104 != 146 /* TRADE_CONTEXT_BUSY */)
return(0);
if (count_100 >= gi_136)
break;
if (error_104 == 128 /* TRADE_TIMEOUT */ || error_104 == 129 /* INVALID_PRICE */ || error_104 == 130 /* INVALID_STOPS */ || error_104 == 136 /* OFF_QUOTES */ || error_104 == 145 /* TRADE_MODIFY_DENIED */ ||
error_104 == 146 /* TRADE_CONTEXT_BUSY */)
{
Print("EA must wait a few seconds before attempting to repeat the last trading action to obey MQL rules");
Sleep(5000);
}
}
}
if (ad_32 > 0.0 || ad_40 > 0.0)
{
if (ticket_96 > 0)
{
if (OrderSelect(ticket_96, SELECT_BY_TICKET) == TRUE)
{
if (ai_64 == 1)
{
if (a_cmd_8 == OP_BUYSTOP || a_cmd_8 == OP_BUYLIMIT)
{
if (ad_32 > 0.0)
ad_32 = OrderOpenPrice() - ad_32 * point_144;
if (ad_40 > 0.0)
ad_40 = OrderOpenPrice() + ad_40 * point_144;
}
else
{
if (!(a_cmd_8 == OP_SELLSTOP || a_cmd_8 == OP_SELLLIMIT))
return(ticket_96);
if (ad_32 > 0.0)
ad_32 = OrderOpenPrice() + ad_32 * point_144;
if (ad_40 > 0.0)
{
ad_40 = OrderOpenPrice() - ad_40 * point_144;
if (false)
return(ticket_96);
}
}
}
RefreshRates();
bid_116 = MarketInfo(a_symbol_0, MODE_BID);
ask_124 = MarketInfo(a_symbol_0, MODE_ASK);
f0_12(OrderType(), OrderTicket(), OrderSymbol(), OrderOpenPrice(), ad_32, ask_124, bid_116, stoplevel_108);
f0_1(OrderType(), OrderTicket(), OrderSymbol(), OrderOpenPrice(), ad_40, ask_124, bid_116, stoplevel_108);
count_100 = 0;
while (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(ad_32, digits_132), NormalizeDouble(ad_40, digits_132), a_datetime_56, a_color_68) && count_100 <= gi_136)
{
error_104 = GetLastError();
if (error_104 == 147 /* TRADE_EXPIRATION_DENIED */)
{
a_datetime_56 = 0;
Print("Expiration for trade #" + OrderTicket() + " was removed because broker does not allow it");
}
Print("OrderModify error (" + error_104 + "): " + f0_20(error_104) + "; OrderTicket: " + OrderTicket() + "; OrderType: " + OrderType() + "; LotSize: " + DoubleToStr(a_lots_20, gi_212) + "; Open Price: " + DoubleToStr(OrderOpenPrice(), digits_132) + "; StopLoss: " + DoubleToStr(ad_32, digits_132) + "; TakeProfit: " + DoubleToStr(ad_40, digits_132) + "; Ask: " + DoubleToStr(ask_124, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_ASK), digits_132) + "; Bid: " + DoubleToStr(bid_116, digits_132) + "/" + DoubleToStr(MarketInfo(a_symbol_0, MODE_BID), digits_132) + "; STOPLEVEL: " + DoubleToStr(stoplevel_108 * point_136 / point_144, 1) + ";");
if (error_104 != 0 /* NO_ERROR */ && error_104 != 4 /* SERVER_BUSY */ && error_104 != 6 /* NO_CONNECTION */ && error_104 != 128 /* TRADE_TIMEOUT */ && error_104 != 129 /* INVALID_PRICE */ &&
error_104 != 130 /* INVALID_STOPS */ && error_104 != 135 /* PRICE_CHANGED */ && error_104 != 136 /* OFF_QUOTES */ && error_104 != 137 /* BROKER_BUSY */ && error_104 != 138 /* REQUOTE */ &&
error_104 != 145 /* TRADE_MODIFY_DENIED */ && error_104 != 146 /* TRADE_CONTEXT_BUSY */)
break;
if (count_100 >= gi_136)
break;
Sleep(1000);
if (error_104 == 128 /* TRADE_TIMEOUT */ || error_104 == 129 /* INVALID_PRICE */ || error_104 == 130 /* INVALID_STOPS */ || error_104 == 136 /* OFF_QUOTES */ || error_104 == 145 /* TRADE_MODIFY_DENIED */ ||
error_104 == 146 /* TRADE_CONTEXT_BUSY */)
{
Print("EA must wait a few seconds before attempting to repeat the last trading action to obey MQL rules");
Sleep(5000);
}
count_100++;
Print("OrderModify retry #" + count_100);
RefreshRates();
bid_116 = MarketInfo(a_symbol_0, MODE_BID);
ask_124 = MarketInfo(a_symbol_0, MODE_ASK);
f0_12(OrderType(), OrderTicket(), OrderSymbol(), OrderOpenPrice(), ad_32, ask_124, bid_116, stoplevel_108);
f0_1(OrderType(), OrderTicket(), OrderSymbol(), OrderOpenPrice(), ad_40, ask_124, bid_116, stoplevel_108);
}
if (error_104 > 1 /* NO_RESULT */)
if (a_symbol_0 == Symbol())
f0_9("error_modify_trade_" + Time[0], "me" + error_104, a_color_68, Time[0], Low[0] - 2.0 * point_144);
}
else
Print("ERROR: " + f0_20(GetLastError()));
}
}
return(ticket_96);
}
int f0_5(int ai_0 = 30)
{
int li_4;
if (!IsTradeAllowed())
{
li_4 = GetTickCount();
Print("Broker trade context is busy! EA will wait until it is free ...");
while (true)
{
if (IsStopped())
{
Print("The expert was terminated by the user!");
return(-1);
}
if (GetTickCount() - li_4 > 1000 * ai_0)
{
Print("The waiting limit exceeded (" + ai_0 + ")! EA may fail to perform trading actions because broker trade context is busy!");
return(-2);
}
if (!(IsTradeAllowed()))
continue;
break;
}
Print("Broker trade context has become free! EA will continue to perform trading actions");
return(0);
}
return(1);
}
double f0_18(double ad_0)
{
ad_0 = NormalizeDouble(ad_0 / g_lotstep_172, 0) * g_lotstep_172;
if (ad_0 < gd_180)
ad_0 = gd_180;
if (ad_0 > gd_188)
ad_0 = gd_188;
return(ad_0);
}
void f0_4(color a_color_0, int a_fontsize_4, int ai_8, int ai_12)
{
string name_16;
for (int count_24 = 0; count_24 < ai_8; count_24++)
{
name_16 = "Hedge EA Demo" + "block99-" + ((count_24 + 1));
if (ObjectFind(name_16) == -1)
ObjectCreate(name_16, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_16, "g", a_fontsize_4, "Webdings", a_color_0);
ObjectSet(name_16, OBJPROP_XDISTANCE, 85);
ObjectSet(name_16, OBJPROP_YDISTANCE, ai_12 * count_24 + 72);
ObjectSet(name_16, OBJPROP_COLOR, a_color_0);
ObjectSet(name_16, OBJPROP_FONTSIZE, a_fontsize_4);
}
}
void f0_2()
{
string name_0 = "Hedge EA Demo" + "block98-1";
color color_8 = C'0x3E,0xA7,0xF5';
if (ObjectFind(name_0) == -1)
ObjectCreate(name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_0, "g", 32, "Webdings", color_8);
ObjectSet(name_0, OBJPROP_CORNER, 3);
ObjectSet(name_0, OBJPROP_XDISTANCE, 1);
ObjectSet(name_0, OBJPROP_YDISTANCE, 1);
ObjectSet(name_0, OBJPROP_COLOR, color_8);
ObjectSet(name_0, OBJPROP_FONTSIZE, 32);
name_0 = "Hedge EA Demo" + "block98-2";
color_8 = C'0x3E,0xA7,0xF5';
if (ObjectFind(name_0) == -1)
ObjectCreate(name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_0, "g", 32, "Webdings", color_8);
ObjectSet(name_0, OBJPROP_CORNER, 3);
ObjectSet(name_0, OBJPROP_XDISTANCE, 43);
ObjectSet(name_0, OBJPROP_YDISTANCE, 1);
ObjectSet(name_0, OBJPROP_COLOR, color_8);
ObjectSet(name_0, OBJPROP_FONTSIZE, 32);
name_0 = "Hedge EA Demo" + "block98-3";
color_8 = C'0x3E,0xA7,0xF5';
if (ObjectFind(name_0) == -1)
ObjectCreate(name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_0, "g", 32, "Webdings", color_8);
ObjectSet(name_0, OBJPROP_CORNER, 3);
ObjectSet(name_0, OBJPROP_XDISTANCE, 75);
ObjectSet(name_0, OBJPROP_YDISTANCE, 1);
ObjectSet(name_0, OBJPROP_COLOR, color_8);
ObjectSet(name_0, OBJPROP_FONTSIZE, 32);
name_0 = "Hedge EA Demo" + "block98text1";
color_8 = White;
if (ObjectFind(name_0) == -1)
ObjectCreate(name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_0, "EA CODER", 19, "Trebuchet MS", color_8);
ObjectSet(name_0, OBJPROP_CORNER, 3);
ObjectSet(name_0, OBJPROP_XDISTANCE, 3);
ObjectSet(name_0, OBJPROP_YDISTANCE, 12);
ObjectSet(name_0, OBJPROP_COLOR, color_8);
ObjectSet(name_0, OBJPROP_FONTSIZE, 19);
name_0 = "Hedge EA Demo" + "block98text2";
color_8 = White;
if (ObjectFind(name_0) == -1)
ObjectCreate(name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_0, "www.ea-coder.com", 9, "Trebuchet MS", color_8);
ObjectSet(name_0, OBJPROP_CORNER, 3);
ObjectSet(name_0, OBJPROP_XDISTANCE, 3);
ObjectSet(name_0, OBJPROP_YDISTANCE, 3);
ObjectSet(name_0, OBJPROP_COLOR, color_8);
ObjectSet(name_0, OBJPROP_FONTSIZE, 9);
}
/*void f0_7(string as_0, bool ai_8, bool ai_12, bool ai_16)
{
if (ai_8)
f0_0(as_0);
if (ai_12)
Alert(as_0);
if (ai_16)
gi_132 = FALSE;
}
void f0_0(string a_text_0)
{
string name_8 = "Hedge EA Demo" + "_comment_red";
color color_16 = Red;
if (ObjectFind(name_8) == -1)
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, a_text_0, 16, "Trebuchet MS", color_16);
ObjectSet(name_8, OBJPROP_CORNER, 0);
ObjectSet(name_8, OBJPROP_XDISTANCE, 3);
ObjectSet(name_8, OBJPROP_YDISTANCE, 24);
ObjectSet(name_8, OBJPROP_COLOR, color_16);
ObjectSet(name_8, OBJPROP_FONTSIZE, 16);
}*/
string f0_13(int ai_0 = 0)
{
string ls_ret_4 = "";
for (int count_12 = 0; count_12 < ai_0; count_12++)
ls_ret_4 = ls_ret_4 + " ";
return(ls_ret_4);
}
void f0_24()
{
double point_0;
string ls_8;
string ls_16;
if (DashboardDisplay > 0)
{
if (DashboardDisplay > 1)
{
f0_4(DashboardColor, 150, 2, 30);
f0_2();
}
if (Point == 0.00001)
point_0 = 0.0001;
else
{
if (Point == 0.001)
point_0 = 0.01;
else
point_0 = Point;
}
ls_8 = f0_13(30);
ls_16 = "\n\n\n\n\n\n" + ls_8 + "Hedge EA Demo" + " v" + "1.0"
+ "\n\n";
ls_16 = ls_16 + ls_8 + "Spread: " + DoubleToStr(gd_204 * Point / point_0, 1) + " pips\n";
ls_16 = ls_16 + ls_8 + "Stop Level: " + DoubleToStr(gd_196 * Point / point_0, 1) + " pips\n";
ls_16 = ls_16 + ls_8 + "Lot Size: same as initial trade\n";
ls_16 = ls_16 + ls_8 + "Take Profit: ";
if (TakeProfitPips > 0.0)
ls_16 = ls_16 + DoubleToStr(TakeProfitPips, 1) + " pips\n";
else
ls_16 = ls_16 + "same as initial trade\n";
ls_16 = ls_16 + ls_8 + "Stop Loss: ";
if (StopLossPips > 0.0)
ls_16 = ls_16 + DoubleToStr(StopLossPips, 1) + " pips\n";
else
ls_16 = ls_16 + "same as initial trade\n";
ls_16 = ls_16 + ls_8 + "Magic Number for hedge trades: " + MagicNumber
+ "\n";
ls_16 = ls_16 + ls_8 + "Buy/Sell/Stop/Limit/Total: " + gia_216[0] + "/" + gia_216[1] + "/" + gia_216[8] + "/" + gia_216[7] + "/" + gia_216[10]
+ "\n";
ls_16 = ls_16 + ls_8 + "Hedge trades at the distance of " + DoubleToStr(X_Pips, 1) + " pips\n";
ls_16 = ls_16
+ "\n";
ls_16 = ls_16 + ls_8 + "This software has only basic settings and is\n" + ls_8 + "free to use for one month only on your MT4\n";
ls_16 = ls_16 + ls_8 + "demo account. You are allowed to use this\n" + ls_8 + "software for testing purposes only that will\n";
ls_16 = ls_16 + ls_8 + "help you decide if you want to purchase full\n" + ls_8 + "version from www.ea-coder.com\n";
Comment(ls_16);
}
}
string f0_20(int ai_0)
{
string ls_ret_4;
switch (ai_0)
{
case 0:
case 1:
ls_ret_4 = "no error";
break;
case 2:
ls_ret_4 = "common error";
break;
case 3:
ls_ret_4 = "invalid trade parameters";
break;
case 4:
ls_ret_4 = "trade server is busy";
break;
case 5:
ls_ret_4 = "old version of the client terminal";
break;
case 6:
ls_ret_4 = "no connection with trade server";
break;
case 7:
ls_ret_4 = "not enough rights";
break;
case 8:
ls_ret_4 = "too frequent requests";
break;
case 9:
ls_ret_4 = "malfunctional trade operation (never returned error)";
break;
case 64:
ls_ret_4 = "account disabled";
break;
case 65:
ls_ret_4 = "invalid account";
break;
case 128:
ls_ret_4 = "trade timeout";
break;
case 129:
ls_ret_4 = "invalid price";
break;
case 130:
ls_ret_4 = "invalid stops";
break;
case 131:
ls_ret_4 = "invalid trade volume";
break;
case 132:
ls_ret_4 = "market is closed";
break;
case 133:
ls_ret_4 = "trade is disabled";
break;
case 134:
ls_ret_4 = "not enough money";
break;
case 135:
ls_ret_4 = "price changed";
break;
case 136:
ls_ret_4 = "off quotes";
break;
case 137:
ls_ret_4 = "broker is busy (never returned error)";
break;
case 138:
ls_ret_4 = "requote";
break;
case 139:
ls_ret_4 = "order is locked";
break;
case 140:
ls_ret_4 = "long positions only allowed";
break;
case 141:
ls_ret_4 = "too many requests";
break;
case 145:
ls_ret_4 = "modification denied because order too close to market";
break;
case 146:
ls_ret_4 = "trade context is busy";
break;
case 147:
ls_ret_4 = "expirations are denied by broker";
break;
case 148:
ls_ret_4 = "amount of open and pending orders has reached the limit";
break;
case 149:
ls_ret_4 = "hedging is prohibited";
break;
case 150:
ls_ret_4 = "prohibited by FIFO rules";
break;
case 4000:
ls_ret_4 = "no error (never generated code)";
break;
case 4001:
ls_ret_4 = "wrong function pointer";
break;
case 4002:
ls_ret_4 = "array index is out of range";
break;
case 4003:
ls_ret_4 = "no memory for function call stack";
break;
case 4004:
ls_ret_4 = "recursive stack overflow";
break;
case 4005:
ls_ret_4 = "not enough stack for parameter";
break;
case 4006:
ls_ret_4 = "no memory for parameter string";
break;
case 4007:
ls_ret_4 = "no memory for temp string";
break;
case 4008:
ls_ret_4 = "not initialized string";
break;
case 4009:
ls_ret_4 = "not initialized string in array";
break;
case 4010:
ls_ret_4 = "no memory for array\' string";
break;
case 4011:
ls_ret_4 = "too long string";
break;
case 4012:
ls_ret_4 = "remainder from zero divide";
break;
case 4013:
ls_ret_4 = "zero divide";
break;
case 4014:
ls_ret_4 = "unknown command";
break;
case 4015:
ls_ret_4 = "wrong jump (never generated error)";
break;
case 4016:
ls_ret_4 = "not initialized array";
break;
case 4017:
ls_ret_4 = "dll calls are not allowed";
break;
case 4018:
ls_ret_4 = "cannot load library";
break;
case 4019:
ls_ret_4 = "cannot call function";
break;
case 4020:
ls_ret_4 = "expert function calls are not allowed";
break;
case 4021:
ls_ret_4 = "not enough memory for temp string returned from function";
break;
case 4022:
ls_ret_4 = "system is busy (never generated error)";
break;
case 4050:
ls_ret_4 = "invalid function parameters count";
break;
case 4051:
ls_ret_4 = "invalid function parameter value";
break;
case 4052:
ls_ret_4 = "string function internal error";
break;
case 4053:
ls_ret_4 = "some array error";
break;
case 4054:
ls_ret_4 = "incorrect series array using";
break;
case 4055:
ls_ret_4 = "custom indicator error";
break;
case 4056:
ls_ret_4 = "arrays are incompatible";
break;
case 4057:
ls_ret_4 = "global variables processing error";
break;
case 4058:
ls_ret_4 = "global variable not found";
break;
case 4059:
ls_ret_4 = "function is not allowed in testing mode";
break;
case 4060:
ls_ret_4 = "function is not confirmed";
break;
case 4061:
ls_ret_4 = "send mail error";
break;
case 4062:
ls_ret_4 = "string parameter expected";
break;
case 4063:
ls_ret_4 = "integer parameter expected";
break;
case 4064:
ls_ret_4 = "double parameter expected";
break;
case 4065:
ls_ret_4 = "array as parameter expected";
break;
case 4066:
ls_ret_4 = "requested history data in update state";
break;
case 4099:
ls_ret_4 = "end of file";
break;
case 4100:
ls_ret_4 = "some file error";
break;
case 4101:
ls_ret_4 = "wrong file name";
break;
case 4102:
ls_ret_4 = "too many opened files";
break;
case 4103:
ls_ret_4 = "cannot open file";
break;
case 4104:
ls_ret_4 = "incompatible access to a file";
break;
case 4105:
ls_ret_4 = "no order selected";
break;
case 4106:
ls_ret_4 = "unknown symbol";
break;
case 4107:
ls_ret_4 = "invalid price parameter for trade function";
break;
case 4108:
ls_ret_4 = "invalid ticket";
break;
case 4109:
ls_ret_4 = "trade is not allowed in the expert properties";
break;
case 4110:
ls_ret_4 = "longs are not allowed in the expert properties";
break;
case 4111:
ls_ret_4 = "shorts are not allowed in the expert properties";
break;
case 4200:
ls_ret_4 = "object is already exist";
break;
case 4201:
ls_ret_4 = "unknown object property";
break;
case 4202:
ls_ret_4 = "object is not exist";
break;
case 4203:
ls_ret_4 = "unknown object type";
break;
case 4204:
ls_ret_4 = "no object name";
break;
case 4205:
ls_ret_4 = "object coordinates error";
break;
case 4206:
ls_ret_4 = "no specified subwindow";
break;
default:
ls_ret_4 = "unknown error";
}
return(ls_ret_4);
}
/*bool f0_3() {
return (IsDemo() || StringFind(f0_11(AccountServer()), "demo") > -1 || StringFind(f0_11(AccountServer()), "practice") > -1);
}
string f0_11(string as_0)
{
int li_12;
for (int li_8 = 0; li_8 < StringLen(as_0); li_8++)
{
li_12 = StringGetChar(as_0, li_8);
if ((li_12 >= 'A' && li_12 <= 'Z') || (li_12 >= 'À' && li_12 <= 'Þ' && li_12 != '×'))
as_0 = StringSetChar(as_0, li_8, li_12 + 32);
}
return(as_0);
}*/
int start()
{
if (gi_132)
{
gd_204 = MarketInfo(Symbol(), MODE_SPREAD);
gd_196 = MarketInfo(Symbol(), MODE_STOPLEVEL);
f0_6();
f0_14();
f0_24();
}
return(0);
}