#property copyright "Forex MegaDroid Team" #property link "http://www.forex-megadroid.com" #include #include #import "MegaDroid.dll" int GetGmtOffset(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, double& a8[]); void Activate(string a0, int a1, int a2, string a3, int a4); int GetState(); int GetStatus(); bool IsTradeTime(string a0, int a1, int a2, int a3, int a4); bool s1_Buy(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, int a8, int a9); bool s1_Sell(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, int a8, int a9); bool s2_Buy(double a0, double a1, double a2, double a3, double a4, double a5, int a6, int a7); bool s2_Sell(double a0, double a1, double a2, double a3, double a4, double a5, int a6, int a7); bool s1_Init(string a0, int& a1[], int& a2[], int& a3[], int& a4[], int& a5[], int& a6[], int& a7[], int& a8[], int& a9[], int& a10[], int& a11[], double& a12[], double& a13[], double& a14[], double& a15[], int& a16[], int& a17[], int& a18[], int& a19[], int& a20[], int& a21[]); bool s2_Init(string a0, int& a1[], int& a2[], int& a3[], double& a4[], int& a5[], int& a6[], int& a7[], int& a8[], double& a9[], double& a10[], double& a11[], int& a12[], int& a13[], int& a14[], int& a15[], int& a16[], int& a17[]); #import extern string Version_1.21 = ""; extern string _1 = "System Parameters"; extern bool Stealth = TRUE; extern bool Aggressive = TRUE; extern bool NFA = FALSE; extern double GmtOffset = 0.0; extern bool AutoLocalGmtOffset = TRUE; extern bool AutoServerGmtOffset = TRUE; extern int S1_Reference = 77777773; extern int S2_Reference = 33333337; extern string ReceiptCode = ""; extern string _2 = "Comment Position"; extern int TopPadding = 30; extern int LeftPadding = 20; extern color TextColor1 = WhiteSmoke; extern color TextColor2 = LightGray; extern string _3 = "Strategy Parameters"; extern int Slippage = 3; extern bool SendEmails = FALSE; extern string OrderComments = ""; extern string _4 = "Order Management"; extern double LotSize = 0.1; extern string _5 = "Ratio Order Management"; extern double RiskLevel = 0.1; extern bool RecoveryMode = TRUE; bool gi_220 = FALSE; double gd_224 = 1000.0; double gd_232 = 0.2; bool gi_240 = FALSE; bool gi_244 = TRUE; bool gi_248 = TRUE; int gi_252 = 3; bool gi_256 = TRUE; int gi_260; int g_datetime_264; int gi_268; double g_hour_272; int gi_280; int g_spread_284; int g_spread_288; int g_stoplevel_292; double gd_296; double gd_304; double gd_312; bool gi_320 = FALSE; int gi_324 = 0; int gi_328 = 0; string gs_332; string gs_340; string gs_348; int g_timeframe_356 = PERIOD_M15; int gi_360 = 10; int gi_364 = 50; int gi_368 = 200; int gi_372 = 20; int gi_376 = 0; int gi_380 = 16711680; int gi_384 = 255; int g_period_388 = 6; int g_period_392 = 20; int g_period_396 = 8; double gd_400 = 70.0; double gd_408 = 30.0; double gd_416 = 64.0; double gd_424 = 36.0; bool gi_432 = TRUE; bool gi_436 = TRUE; bool gi_440 = TRUE; int gi_444 = 12; bool gi_448 = TRUE; int gi_452 = 20; bool gi_456 = TRUE; bool gi_460 = FALSE; double gd_464 = 1.0; double gd_472 = 24.0; bool gi_480 = TRUE; double gd_484 = 1.0; double gd_492 = 1.0; bool gi_500 = FALSE; int gi_504 = 0; bool gi_508 = TRUE; bool gi_512 = TRUE; int gi_516 = 21; int gi_520 = 1; int gi_524 = 21; int gi_528 = 0; int g_timeframe_532 = PERIOD_M5; int gi_536 = 35; int gi_540 = 60; int gi_544 = 200; int gi_548 = 20; double gd_552 = 1.0; int gi_560 = 0; int gi_564 = 16748574; int gi_568 = 9639167; int gi_572 = 36; int g_period_576 = 168; int g_period_580 = 275; bool gi_584 = TRUE; bool gi_588 = FALSE; bool gi_592 = TRUE; double gd_596 = 1.0; double gd_604 = 12.0; double gd_612 = 24.0; bool gi_620 = FALSE; bool gi_624 = FALSE; int gi_628 = 0; bool gi_632 = TRUE; bool gi_636 = TRUE; int gi_640 = 21; int gi_644 = 4; int gi_648 = 21; int gi_652 = 0; int gi_656 = 0; int gi_660 = 0; int gi_664 = 0; int gi_668; int gi_672; int gi_676; int gi_680; double gd_684 = 0.0; double gd_692 = 0.0; bool gi_700 = FALSE; bool gi_704; bool gi_708; int gi_712; int g_count_716 = 0; int g_ticket_720 = -2; int g_ticket_724 = -2; double g_ord_profit_728 = 0.0; double g_ord_profit_736 = 0.0; int g_ticket_744 = -2; int g_ticket_748 = -2; double g_ord_profit_752 = 0.0; double g_ord_profit_760 = 0.0; int gi_768 = 0; int gi_772 = 0; int gi_776 = 0; int gi_780 = 0; double g_irsi_784; double g_irsi_792; double g_irsi_800; double g_irsi_808; double g_icci_816; double g_icci_824; double g_icci_832; double g_ima_856; bool gi_864 = TRUE; bool gi_868 = TRUE; double g_ihigh_872 = 0.0; double g_ilow_880 = 0.0; bool gi_888 = FALSE; int gi_892 = 0; int gi_896 = 0; int gi_900 = 0; int gi_904 = 0; int gi_908; int gi_912; int gi_916 = 0; int gi_920 = 0; int gi_924; int g_datetime_928 = 0; int g_datetime_932 = 0; int g_ticket_936 = 0; int g_datetime_940 = 0; int g_ticket_944 = 0; int g_datetime_948 = 0; bool gi_952 = TRUE; int g_datetime_956 = 0; int g_datetime_960 = 0; int gi_964 = 0; double g_icci_968; double g_icci_976; double g_ihigh_984; double g_ilow_992; double g_ihigh_1000; double g_ilow_1008; bool gi_1016 = FALSE; int gi_1020 = 0; int gi_1024 = 0; int gi_1028 = 0; int gi_1032 = 0; int gi_1036; int gi_1040; int g_ticket_1044 = -1; int gi_1048; int gi_1052; int g_datetime_1056; int g_datetime_1060; double g_ord_open_price_1064; int g_ticket_1072 = -1; int gi_1076; int gi_1080; int g_datetime_1084; int g_datetime_1088; double g_ord_open_price_1092; bool gi_1100 = TRUE; int g_datetime_1104 = 0; int g_datetime_1108 = 0; string gsa_1112[] = {".", "..", "...", "....", "....."}; int gi_unused_1116 = 0; int gi_unused_1120 = 0; string gs_1124 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; bool gi_1132 = FALSE; int S1_CheckSymbol() { int lia_0[1]; int lia_4[1]; int lia_8[1]; int lia_12[1]; int lia_16[1]; int lia_20[1]; int lia_24[1]; int lia_28[1]; int lia_32[1]; int lia_36[1]; int lia_40[1]; double lda_44[1]; double lda_48[1]; double lda_52[1]; double lda_56[1]; int lia_60[1]; int lia_64[1]; int lia_68[1]; int lia_72[1]; int lia_76[1]; int lia_80[1]; if (s1_Init(Symbol(), lia_0, lia_4, lia_8, lia_12, lia_16, lia_20, lia_24, lia_28, lia_32, lia_36, lia_40, lda_44, lda_48, lda_52, lda_56, lia_60, lia_64, lia_68, lia_72, lia_76, lia_80)) { gi_360 = lia_0[0]; gi_368 = lia_4[0]; gi_372 = lia_8[0]; gi_376 = lia_12[0]; g_period_388 = lia_16[0]; g_period_392 = lia_20[0]; g_period_396 = lia_24[0]; gd_400 = lia_28[0]; gd_408 = lia_32[0]; gd_416 = lia_36[0]; gd_424 = lia_40[0]; gd_464 = lda_44[0]; gd_472 = lda_48[0]; gd_484 = lda_52[0]; gd_492 = lda_56[0]; gi_504 = lia_60[0]; gi_516 = lia_64[0]; gi_520 = lia_68[0]; gi_524 = lia_72[0]; gi_528 = lia_76[0]; g_timeframe_356 = lia_80[0]; return (1); } return (0); } int S2_CheckSymbol() { int lia_0[1]; int lia_4[1]; int lia_8[1]; int lia_12[1]; double lda_16[1]; int lia_20[1]; int lia_24[1]; int lia_28[1]; double lda_32[1]; double lda_36[1]; double lda_40[1]; int lia_44[1]; int lia_48[1]; int lia_52[1]; int lia_56[1]; int lia_60[1]; int lia_64[1]; if (s2_Init(Symbol(), lia_0, lia_4, lia_8, lda_16, lia_12, lia_20, lia_24, lia_28, lda_32, lda_36, lda_40, lia_44, lia_48, lia_52, lia_56, lia_60, lia_64)) { gi_536 = lia_0[0]; gi_544 = lia_4[0]; gi_548 = lia_8[0]; gd_552 = lda_16[0]; gi_560 = lia_12[0]; gi_572 = lia_20[0]; g_period_576 = lia_24[0]; g_period_580 = lia_28[0]; gd_596 = lda_32[0]; gd_604 = lda_36[0]; gd_612 = lda_40[0]; gi_628 = lia_44[0]; gi_640 = lia_48[0]; gi_644 = lia_52[0]; gi_648 = lia_56[0]; gi_652 = lia_60[0]; g_timeframe_532 = lia_64[0]; return (1); } return (0); } int init() { double l_global_var_8; double ld_16; if (gi_256) gi_260 = 0; else gi_260 = 1; gi_672 = LeftPadding; gi_668 = TopPadding; if (gi_676 != LeftPadding || gi_680 != TopPadding) { gi_676 = LeftPadding; gi_680 = TopPadding; } else GetPos(0, gi_672, gi_668); gi_660 = 0; gi_656 = 0; gs_332 = "MegaDroid" + " ver: " + "1.21" + " Symbol: " + Symbol(); PrintLN(gs_332, TextColor2); PrintSep(); ObjectsRedraw(); for (int l_count_0 = 0; !IsStopped() && !IsConnected() || StringLen(AccountName()) <= 0; l_count_0++) { PrintLN("Waiting for connection" + PPrint(l_count_0), TextColor1, 2, 2); ObjectsRedraw(); Sleep(150); } PrintLN("Authentication...", TextColor1, 2, 2); ObjectsRedraw(); int li_4 = 0; ReceiptCode = StringTrimLeft(StringTrimRight(ReceiptCode)); if (StringLen(ReceiptCode) <= 0) { if (GlobalVariableCheck("GV_MegaDroid_REC")) { l_global_var_8 = GlobalVariableGet("GV_MegaDroid_REC"); ReceiptCode = Base36Encode(l_global_var_8); } else li_4 |= 32; } else { ld_16 = Base36Decode(ReceiptCode); if (GlobalVariableSet("GV_MegaDroid_REC", ld_16) == 0) li_4 |= 64; } Activate("1.21", AccountNumber(), IsDemo(), StringTrimLeft(StringTrimRight(ReceiptCode)), 1); gi_324 = GetState(); gi_324 |= li_4; PrintResponse(gi_324, 2, 2); PrintSep(); ObjectsRedraw(); bool li_24 = FALSE; bool li_28 = FALSE; li_24 = S1_CheckSymbol(); li_28 = S2_CheckSymbol(); if (li_24) { gi_244 = TRUE; if (Aggressive) gi_248 = li_28; else gi_248 = FALSE; } else { if (li_28) { gi_244 = FALSE; gi_248 = TRUE; } else { gi_248 = FALSE; gi_244 = FALSE; } } if (!gi_244 && !gi_248) { gs_340 = "Error:"; gs_348 = "This currency is not supported!"; } else { gs_340 = "Aggressive:"; gs_348 = BPrint(gi_244 && gi_248); if (Aggressive && !(gi_244 && gi_248)) gs_348 = gs_348 + " (not supported)"; } PrintLN(gs_340); PrintLN(gs_348, TextColor2, gi_660, gi_656 - 1, 5 * (StringLen(gs_340) + 1)); PrintSep(); ObjectsRedraw(); if (!gi_244 && !gi_248) MessageBox("You have selected the wrong currency pair!", gs_332 + ": Warning", MB_ICONEXCLAMATION); gd_312 = gd_224; gi_328 = 0; if (!IsTesting()) gi_320 = TRUE; return (0); } int deinit() { if (IsTesting()) { if (!IsVisualMode()) { PrintLN("GmtOffset:"); PrintLN(DoubleToStr(GmtOffset, 1), TextColor2, gi_660, gi_656 - 1, 55); PrintSep(); PrintLN("Digits:"); PrintLN(Digits, TextColor2, gi_660, gi_656 - 1, 35); PrintLN("Spread:"); PrintLN(StringConcatenate(DoubleToStr(g_spread_284 / gd_296, 1), " (", g_spread_284, " pips)"), TextColor2, gi_660, gi_656 - 1, 40); PrintSep(); } return (0); } switch (UninitializeReason()) { case REASON_CHARTCLOSE: case REASON_REMOVE: Deleteobjects(0, gi_664); gi_664 = 0; break; case REASON_RECOMPILE: case REASON_CHARTCHANGE: case REASON_PARAMETERS: case REASON_ACCOUNT: Deleteobjects(1, gi_664); gi_664 = 1; } return (0); } int waitForContext() { for (int l_count_0 = 0; IsTradeContextBusy() && l_count_0 < 20; l_count_0++) Sleep(15); if (l_count_0 >= 20) Print("Trade context is buisy more than ", DoubleToStr(15 * l_count_0 / 1000, 2), " seconds"); else if (l_count_0 > 0) Print("Trade context was buisy ", DoubleToStr(15 * l_count_0 / 1000, 2), " seconds"); return (l_count_0); } int openOrder(int a_cmd_0, double a_lots_4, double a_price_12, double a_price_20, double a_price_28, int a_magic_36, color a_color_40, bool ai_44) { int l_error_68; double l_price_48 = 0; double l_price_56 = 0; if (!ai_44) { l_price_48 = a_price_20; l_price_56 = a_price_28; } waitForContext(); int l_ticket_64 = OrderSend(Symbol(), a_cmd_0, a_lots_4, a_price_12, Slippage * gd_296, l_price_56, l_price_48, OrderComments, a_magic_36, 0, a_color_40); if (l_ticket_64 > 0) { if (ai_44) { if (OrderSelect(l_ticket_64, SELECT_BY_TICKET)) { waitForContext(); OrderModify(l_ticket_64, OrderOpenPrice(), a_price_28, a_price_20, 0, a_color_40); } } if (SendEmails) SendMail(gs_332, "Open " + OpPrint(a_cmd_0) + ": [" + Symbol() + "] " + NormalizeDouble(a_price_12, Digits)); } else { l_error_68 = GetLastError(); if (!ai_44) return (openOrder(a_cmd_0, a_lots_4, a_price_12, a_price_20, a_price_28, a_magic_36, a_color_40, 1)); Print(OpPrint(a_cmd_0) + " operation failed - error(", l_error_68, "): ", ErrorDescription(l_error_68)); } return (l_ticket_64); } int closeOrder(int ai_0, color a_color_4) { double l_price_8; int l_error_20; for (int l_count_16 = 0; l_count_16 < 20; l_count_16++) { if (waitForContext() > 5) RefreshRates(); if (ai_0 == 0) l_price_8 = Bid; else l_price_8 = Ask; if (OrderClose(OrderTicket(), OrderLots(), l_price_8, Slippage * gd_296, a_color_4)) return (-1); l_error_20 = GetLastError(); Print("Order close operation failed - error(", l_error_20, "): ", ErrorDescription(l_error_20)); RefreshRates(); } Print("Order close operation failed"); return (OrderTicket()); } double MMLots(double ad_0, double ad_8, int &ai_16) { return (NormalizeLots(ad_0 * ad_8 / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / (AccountLeverage() / 100.0), ai_16)); } double NormalizeLots(double ad_0, int &ai_8) { double l_lotstep_20 = MarketInfo(Symbol(), MODE_LOTSTEP); double l_minlot_28 = MarketInfo(Symbol(), MODE_MINLOT); double l_maxlot_36 = MarketInfo(Symbol(), MODE_MAXLOT); double ld_ret_12 = MathCeil(ad_0 / l_lotstep_20) * l_lotstep_20; ai_8 = 0; if (ld_ret_12 < l_minlot_28) { ld_ret_12 = l_minlot_28; ai_8 = -1; } if (ld_ret_12 > l_maxlot_36) { ld_ret_12 = l_maxlot_36; ai_8 = 1; } return (ld_ret_12); } void CountBalance(double ad_0) { gd_684 += ad_0; if (gd_692 < gd_684) gd_692 = gd_684; } double RecoveryLot(double ad_0) { int li_8; if (gd_692 > gd_684 && gi_768 > gi_776) return (NormalizeLots(2.0 * ad_0, li_8)); gi_776 = gi_768; return (ad_0); } int RecoverTrades() { int l_count_0 = 0; for (int l_pos_4 = OrdersHistoryTotal() - 1; l_pos_4 >= 0; l_pos_4--) { if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_HISTORY)) { if (OrderMagicNumber() != S1_Reference && OrderMagicNumber() != S2_Reference) continue; CountBalance(OrderProfit()); l_count_0++; } } return (l_count_0); } int Recover(int a_magic_0, int a_cmd_4) { for (int l_pos_8 = OrdersTotal() - 1; l_pos_8 >= 0; l_pos_8--) { if (OrderSelect(l_pos_8, SELECT_BY_POS)) { if (OrderMagicNumber() == a_magic_0) { if (OrderSymbol() == Symbol()) if (OrderType() == a_cmd_4) return (OrderTicket()); } } } return (-1); } void RefreshOrders() { g_count_716 = 0; for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { if (OrderSelect(l_pos_0, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) if (OrderMagicNumber() != S1_Reference && OrderMagicNumber() != S2_Reference) g_count_716++; } } } int FIFOrule() { return (g_count_716 <= 0 && g_ticket_720 < 0 && g_ticket_724 < 0 && g_ticket_744 < 0 && g_ticket_748 < 0); } int s1_direction() { if (g_icci_816 >= 0.0 || g_irsi_784 >= 50.0) g_datetime_932 = g_datetime_264; if (g_icci_816 <= 0.0 || g_irsi_784 <= 50.0) g_datetime_928 = g_datetime_264; if (g_datetime_932 > 0 && g_datetime_264 - g_datetime_932 > 3600.0 * gd_484) return (2); if (g_datetime_928 > 0 && g_datetime_264 - g_datetime_928 > 3600.0 * gd_484) return (3); if (g_datetime_932 == 0 || g_datetime_928 == 0) return (0); return (1); } void s1_dayRange() { int l_shift_0; if (g_datetime_264 - gi_280 < 3600.0 * gi_444) l_shift_0 = iBarShift(NULL, g_timeframe_356, gi_280 - 86400); else l_shift_0 = iBarShift(NULL, g_timeframe_356, gi_280); g_ihigh_872 = iHigh(NULL, g_timeframe_356, iHighest(NULL, g_timeframe_356, MODE_HIGH, l_shift_0 - gi_260, gi_260)); g_ilow_880 = iLow(NULL, g_timeframe_356, iLowest(NULL, g_timeframe_356, MODE_LOW, l_shift_0 - gi_260, gi_260)); } void s1_setRules() { int li_0; HideTestIndicators(TRUE); g_irsi_784 = iRSI(NULL, g_timeframe_356, g_period_388, PRICE_CLOSE, gi_260); g_irsi_792 = iRSI(NULL, g_timeframe_356, g_period_388, PRICE_CLOSE, gi_260 + 1); g_irsi_800 = iRSI(NULL, g_timeframe_356, g_period_388, PRICE_CLOSE, gi_260 + 2); if (gi_432) g_irsi_808 = iRSI(NULL, PERIOD_M1, g_period_392, PRICE_CLOSE, gi_260); g_icci_816 = iCCI(NULL, g_timeframe_356, g_period_396, PRICE_TYPICAL, gi_260); g_icci_824 = iCCI(NULL, g_timeframe_356, g_period_396, PRICE_TYPICAL, gi_260 + 1); g_icci_832 = iCCI(NULL, g_timeframe_356, g_period_396, PRICE_TYPICAL, gi_260 + 2); g_ima_856 = iMA(NULL, g_timeframe_356, g_period_396, 0, MODE_SMA, PRICE_MEDIAN, gi_260); if (gi_448) { if (g_irsi_784 >= 50 - gi_452 / 2 && g_irsi_784 <= gi_452 / 2 + 50) { gi_864 = TRUE; gi_868 = TRUE; } } if (gi_440) s1_dayRange(); if (gi_480) { li_0 = gi_916; gi_916 = s1_direction(); if (li_0 != gi_916) { gi_920 = li_0; if (gi_916 == 1) gi_924 = g_datetime_264 + 3600.0 * gd_492; } } if (gi_504 > 0) { if (g_spread_284 > gi_504 * gd_296) { if (g_spread_288 < g_spread_284) { Print("Strategy1: Safe spread limit exceeded: spread = ", g_spread_284); if (gi_508) Print("Strategy1: Using DayDirection filter"); } gi_888 = TRUE; } else gi_888 = FALSE; } HideTestIndicators(FALSE); if (gi_888) { gi_908 = gi_524; gi_912 = gi_528; return; } gi_908 = gi_516; gi_912 = gi_520; } int s1_openBuyRule() { double l_iclose_0; double l_iclose_8; int l_shift_16; int l_shift_20; if (!gi_864) return (0); if (gi_888 && !gi_508) return (0); if (gi_480) { if (gi_916 == 2) return (0); if (g_datetime_264 <= gi_924) if (gi_920 == 2) return (0); } if (gi_500 || gi_888) { if (g_datetime_264 - gi_280 < 43200.0) { l_shift_16 = iBarShift(NULL, g_timeframe_356, gi_280 - 86400); l_shift_20 = iBarShift(NULL, g_timeframe_356, gi_280); } else { l_shift_16 = iBarShift(NULL, g_timeframe_356, gi_280); l_shift_20 = gi_260; } l_iclose_8 = iClose(NULL, g_timeframe_356, l_shift_16); l_iclose_0 = iClose(NULL, g_timeframe_356, l_shift_20); if (l_iclose_0 < l_iclose_8) return (0); } return (s1_Buy(Ask, g_icci_816, g_irsi_784, g_irsi_808, g_ima_856, gd_408, gd_424, gi_360 * gd_296 * Point, gi_436, gi_432)); } int s1_openSellRule() { double l_iclose_0; double l_iclose_8; int l_shift_16; int l_shift_20; if (!gi_868) return (0); if (gi_888 && !gi_508) return (0); if (gi_480) { if (gi_916 == 3) return (0); if (g_datetime_264 <= gi_924) if (gi_920 == 3) return (0); } if (gi_500 || gi_888) { if (g_datetime_264 - gi_280 < 43200.0) { l_shift_16 = iBarShift(NULL, g_timeframe_356, gi_280 - 86400); l_shift_20 = iBarShift(NULL, g_timeframe_356, gi_280); } else { l_shift_16 = iBarShift(NULL, g_timeframe_356, gi_280); l_shift_20 = gi_260; } l_iclose_8 = iClose(NULL, g_timeframe_356, l_shift_16); l_iclose_0 = iClose(NULL, g_timeframe_356, l_shift_20); if (l_iclose_0 > l_iclose_8) return (0); } return (s1_Sell(Bid, g_icci_816, g_irsi_784, g_irsi_808, g_ima_856, gd_400, gd_416, gi_360 * gd_296 * Point, gi_436, gi_432)); } bool s1_closeBuyRule() { if (Stealth || OrderTakeProfit() == 0.0) { if (gi_360 > 0) if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_360 * Point * gd_296, Digits)) return (TRUE); } if (OrderStopLoss() == 0.0) { if (gi_896 > 0) if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_896 * Point * gd_296, Digits)) return (TRUE); } if (gi_460) { if (g_ticket_936 != OrderTicket()) { g_datetime_940 = OrderOpenTime(); g_ticket_936 = OrderTicket(); } if (g_icci_816 >= 0.0 || g_irsi_784 >= 50.0) g_datetime_940 = g_datetime_264; if (g_icci_832 < g_icci_824 && g_irsi_800 < g_irsi_792) g_datetime_940 = iTime(NULL, g_timeframe_356, gi_260); if (g_datetime_264 - g_datetime_940 > 3600.0 * gd_464 && OrderProfit() < 0.0) return (TRUE); } if (gi_456) { if (g_datetime_264 - OrderOpenTime() > 3600.0 * gd_464) { if (g_icci_816 > 0.0 && g_irsi_784 > 50.0 && OrderProfit() > 0.0) return (TRUE); if (g_datetime_264 - OrderOpenTime() > 3600.0 * gd_472) return (TRUE); } } return (FALSE); } bool s1_closeSellRule() { if (Stealth || OrderTakeProfit() == 0.0) { if (gi_360 > 0) if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_360 * Point * gd_296, Digits)) return (TRUE); } if (OrderStopLoss() == 0.0) { if (gi_904 > 0) if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_904 * Point * gd_296, Digits)) return (TRUE); } if (gi_460) { if (g_ticket_944 != OrderTicket()) { g_datetime_948 = OrderOpenTime(); g_ticket_944 = OrderTicket(); } if (g_icci_816 <= 0.0 || g_irsi_784 <= 50.0) g_datetime_948 = g_datetime_264; if (g_icci_832 > g_icci_824 && g_irsi_800 > g_irsi_792) g_datetime_948 = iTime(NULL, g_timeframe_356, gi_260); if (g_datetime_264 - g_datetime_948 > 3600.0 * gd_464 && OrderProfit() < 0.0) return (TRUE); } if (gi_456) { if (g_datetime_264 - OrderOpenTime() > 3600.0 * gd_464) { if (g_icci_816 < 0.0 && g_irsi_784 < 50.0 && OrderProfit() > 0.0) return (TRUE); if (g_datetime_264 - OrderOpenTime() > 3600.0 * gd_472) return (TRUE); } } return (FALSE); } int s1_openBuy() { double ld_0 = 0; double ld_8 = 0; if (g_ilow_880 > 0.0) { gi_896 = (Bid - g_ilow_880 + Point * gd_296) / Point; if (gi_368 > 0 && gi_896 > gi_368 * gd_296) gi_896 = gi_368 * gd_296; if (gi_896 < gi_372 * gd_296) gi_896 = gi_372 * gd_296; } else gi_896 = gi_372 * gd_296; if (gi_896 < g_stoplevel_292) gi_896 = g_stoplevel_292; if (Stealth) gi_892 = gi_364 * gd_296; else gi_892 = gi_360 * gd_296; if (gi_892 < g_stoplevel_292) gi_892 = g_stoplevel_292; ld_8 = NormalizeDouble(Bid - gi_896 * Point, Digits); ld_0 = NormalizeDouble(Ask + gi_892 * Point, Digits); return (openOrder(OP_BUY, gd_304, Ask, ld_0, ld_8, S1_Reference, gi_380, 0)); } int s1_openSell() { double ld_0 = 0; double ld_8 = 0; if (g_ihigh_872 > 0.0) { gi_904 = (g_ihigh_872 - Ask + Point * gd_296) / Point; if (gi_368 > 0 && gi_904 > gi_368 * gd_296) gi_904 = gi_368 * gd_296; if (gi_904 < gi_372 * gd_296) gi_904 = gi_372 * gd_296; } else gi_904 = gi_372 * gd_296; if (gi_904 < g_stoplevel_292) gi_904 = g_stoplevel_292; if (Stealth) gi_900 = gi_364 * gd_296; else gi_900 = gi_360 * gd_296; if (gi_900 < g_stoplevel_292) gi_900 = g_stoplevel_292; ld_8 = NormalizeDouble(Ask + gi_904 * Point, Digits); ld_0 = NormalizeDouble(Bid - gi_900 * Point, Digits); return (openOrder(OP_SELL, gd_304, Bid, ld_0, ld_8, S1_Reference, gi_384, 0)); } int s1_buyControl() { int li_ret_16; double l_ord_takeprofit_0 = OrderTakeProfit(); double l_ord_stoploss_8 = OrderStopLoss(); if (l_ord_takeprofit_0 == 0.0 || l_ord_stoploss_8 == 0.0) { if (l_ord_takeprofit_0 == 0.0) { if (gi_892 < g_stoplevel_292) gi_892 = g_stoplevel_292; l_ord_takeprofit_0 = NormalizeDouble(Ask + gi_892 * Point, Digits); } if (l_ord_stoploss_8 == 0.0) { if (gi_896 < g_stoplevel_292) gi_896 = g_stoplevel_292; l_ord_stoploss_8 = NormalizeDouble(Bid - gi_896 * Point, Digits); } waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), l_ord_stoploss_8, l_ord_takeprofit_0, 0, Green); } if (s1_closeBuyRule()) { li_ret_16 = closeOrder(0, Violet); if (li_ret_16 < 0) return (li_ret_16); } if (gi_376 > 0) { if (Bid - OrderOpenPrice() > Point * gd_296 * gi_376) { if (OrderStopLoss() < Bid - Point * gd_296 * gi_376 || OrderStopLoss() == 0.0) { waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gd_296 * gi_376, Digits), OrderTakeProfit(), 0, Green); } } } return (OrderTicket()); } int s1_sellControl() { int li_ret_16; double l_ord_takeprofit_0 = OrderTakeProfit(); double l_ord_stoploss_8 = OrderStopLoss(); if (l_ord_takeprofit_0 == 0.0 || l_ord_stoploss_8 == 0.0) { if (l_ord_takeprofit_0 == 0.0) { if (gi_900 < g_stoplevel_292) gi_900 = g_stoplevel_292; l_ord_takeprofit_0 = NormalizeDouble(Bid - gi_900 * Point, Digits); } if (l_ord_stoploss_8 == 0.0) { if (gi_904 < g_stoplevel_292) gi_904 = g_stoplevel_292; l_ord_stoploss_8 = NormalizeDouble(Ask + gi_904 * Point, Digits); } waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), l_ord_stoploss_8, l_ord_takeprofit_0, 0, Red); } if (s1_closeSellRule()) { li_ret_16 = closeOrder(1, Violet); if (li_ret_16 < 0) return (li_ret_16); } if (gi_376 > 0) { if (OrderOpenPrice() - Ask > Point * gd_296 * gi_376) { if (OrderStopLoss() > Ask + Point * gd_296 * gi_376 || OrderStopLoss() == 0.0) { waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gd_296 * gi_376, Digits), OrderTakeProfit(), 0, Red); } } } return (OrderTicket()); } void run_Strategy1() { int l_day_of_week_8; gi_704 = TRUE; if (g_ticket_720 == -2) { g_ticket_720 = Recover(S1_Reference, OP_BUY); if (g_ticket_720 >= 0) { OrderSelect(g_ticket_720, SELECT_BY_TICKET); OrderPrint(); Print("Strategy1: Order found:"); } } if (g_ticket_724 == -2) { g_ticket_724 = Recover(S1_Reference, OP_SELL); if (g_ticket_724 >= 0) { OrderSelect(g_ticket_724, SELECT_BY_TICKET); OrderPrint(); Print("Strategy1: Order found:"); } } s1_setRules(); if ((gi_908 < gi_912 && (g_hour_272 >= gi_908 && g_hour_272 <= gi_912 - 1)) || (gi_908 >= gi_912 && g_hour_272 >= gi_908 || g_hour_272 <= gi_912 - 1)) gi_704 = TRUE; else gi_704 = FALSE; if (gi_704 && gi_512) { l_day_of_week_8 = TimeDayOfWeek(gi_268); if ((l_day_of_week_8 == 5 && g_hour_272 >= gi_908) || (l_day_of_week_8 == 1 && gi_908 >= gi_912 && g_hour_272 <= gi_912 - 1)) gi_704 = FALSE; else if (l_day_of_week_8 > 5 || l_day_of_week_8 < 1) gi_704 = FALSE; } if (gi_952 != gi_704) { if (gi_704) gi_768++; gi_952 = gi_704; } if (g_ticket_720 >= 0) { if (OrderSelect(g_ticket_720, SELECT_BY_TICKET)) { if (OrderCloseTime() == 0) g_ticket_720 = s1_buyControl(); else g_ticket_720 = -1; g_ord_profit_728 = OrderProfit(); if (g_ticket_720 < 0) CountBalance(g_ord_profit_728); } else { g_ticket_720 = -2; g_ord_profit_728 = 0; } } if (g_ticket_724 >= 0) { if (OrderSelect(g_ticket_724, SELECT_BY_TICKET)) { if (OrderCloseTime() == 0) g_ticket_724 = s1_sellControl(); else g_ticket_724 = -1; g_ord_profit_736 = OrderProfit(); if (g_ticket_724 < 0) CountBalance(g_ord_profit_736); } else { g_ticket_724 = -2; g_ord_profit_736 = 0; } } int li_0 = s1_openBuyRule(); int li_4 = s1_openSellRule(); if (!gi_704 || !gi_712 || gi_700) return; if (NFA && !FIFOrule()) return; if (g_datetime_956 != iTime(NULL, g_timeframe_356, gi_260) && li_0 && g_ticket_720 < 0) { g_ticket_720 = s1_openBuy(); if (g_ticket_720 < 0) return; g_datetime_956 = iTime(NULL, g_timeframe_356, gi_260); if (gi_448) { gi_864 = FALSE; gi_868 = TRUE; } gi_780++; return; } if (g_datetime_960 != iTime(NULL, g_timeframe_356, gi_260) && li_4 && g_ticket_724 < 0) { g_ticket_724 = s1_openSell(); if (g_ticket_724 >= 0) { g_datetime_960 = iTime(NULL, g_timeframe_356, gi_260); if (gi_448) { gi_864 = TRUE; gi_868 = FALSE; } gi_780++; } } } void s2_setRules() { HideTestIndicators(TRUE); if (gi_584 || gi_592) g_icci_968 = iCCI(NULL, g_timeframe_532, g_period_576, PRICE_TYPICAL, gi_260); if (gi_588) g_icci_976 = iCCI(NULL, g_timeframe_532, g_period_580, PRICE_TYPICAL, gi_260); g_ihigh_984 = iHigh(NULL, g_timeframe_532, iHighest(NULL, g_timeframe_532, MODE_HIGH, gi_572, 1)); g_ilow_992 = iLow(NULL, g_timeframe_532, iLowest(NULL, g_timeframe_532, MODE_LOW, gi_572, 1)); if (gi_628 > 0) { if (g_spread_284 > gi_628 * gd_296) { if (g_spread_288 < g_spread_284) { Print("Strategy2: Safe spread limit exceeded: spread = ", g_spread_284); if (gi_632) Print("Strategy2: Using DayDirection filter"); } gi_1016 = TRUE; } else gi_1016 = FALSE; } HideTestIndicators(TRUE); if (gi_1016) { gi_1036 = gi_648; gi_1040 = gi_652; return; } gi_1036 = gi_640; gi_1040 = gi_644; } int s2_openBuyRule() { double l_iclose_0; double l_iclose_8; int l_shift_16; int l_shift_20; if (gi_1016 && !gi_632) return (0); if (gi_624 || gi_1016) { if (g_datetime_264 - gi_280 < 43200.0) { l_shift_16 = iBarShift(NULL, g_timeframe_532, gi_280 - 86400); l_shift_20 = iBarShift(NULL, g_timeframe_532, gi_280); } else { l_shift_16 = iBarShift(NULL, g_timeframe_532, gi_280); l_shift_20 = gi_260; } l_iclose_8 = iClose(NULL, g_timeframe_532, l_shift_16); l_iclose_0 = iClose(NULL, g_timeframe_532, l_shift_20); if (l_iclose_0 < l_iclose_8) return (0); } return (s2_Buy(Ask, Bid, g_icci_968, g_icci_976, g_ilow_992, g_ihigh_984, gi_584, gi_588)); } int s2_openSellRule() { double l_iclose_0; double l_iclose_8; int l_shift_16; int l_shift_20; if (gi_1016 && !gi_632) return (0); if (gi_624 || gi_1016) { if (g_datetime_264 - gi_280 < 43200.0) { l_shift_16 = iBarShift(NULL, g_timeframe_532, gi_280 - 86400); l_shift_20 = iBarShift(NULL, g_timeframe_532, gi_280); } else { l_shift_16 = iBarShift(NULL, g_timeframe_532, gi_280); l_shift_20 = gi_260; } l_iclose_8 = iClose(NULL, g_timeframe_532, l_shift_16); l_iclose_0 = iClose(NULL, g_timeframe_532, l_shift_20); if (l_iclose_0 > l_iclose_8) return (0); } return (s2_Sell(Ask, Bid, g_icci_968, g_icci_976, g_ilow_992, g_ihigh_984, gi_584, gi_588)); } bool s2_closeBuyRule() { double l_ord_profit_0; if (Stealth || OrderTakeProfit() == 0.0) { if (gi_536 > 0) if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_536 * Point * gd_296, Digits)) return (TRUE); } if (OrderStopLoss() == 0.0) { if (gi_1024 > 0) if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_1024 * Point * gd_296, Digits)) return (TRUE); } if (gi_592) { if (g_ticket_1044 != OrderTicket()) { gi_1048 = 0; gi_1052 = 0; g_datetime_1060 = OrderOpenTime(); g_datetime_1056 = g_datetime_1060; g_ticket_1044 = OrderTicket(); g_ord_open_price_1064 = OrderOpenPrice(); } l_ord_profit_0 = OrderProfit(); if (Ask > g_ord_open_price_1064) { gi_1048 += g_datetime_264 - g_datetime_1056; g_datetime_1056 = g_datetime_264; } else { gi_1052 += g_datetime_264 - g_datetime_1056; g_datetime_1056 = g_datetime_264; } if (g_datetime_264 - g_datetime_1060 > 3600.0 * gd_596) { if (g_icci_968 > 0.0 && l_ord_profit_0 > 0.0 && gi_1048 < gi_1052) return (TRUE); if (g_icci_968 > 100.0 && l_ord_profit_0 > 0.0) return (TRUE); if (g_datetime_264 - g_datetime_1060 > 3600.0 * gd_604 && l_ord_profit_0 > 0.0) return (TRUE); if (g_datetime_264 - g_datetime_1060 > 3600.0 * gd_612) return (TRUE); } } if (gi_620) return (Bid >= g_ihigh_984); return (Bid >= g_ihigh_1000); } bool s2_closeSellRule() { double l_ord_profit_0; if (Stealth || OrderTakeProfit() == 0.0) { if (gi_536 > 0) if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_536 * Point * gd_296, Digits)) return (TRUE); } if (OrderStopLoss() == 0.0) { if (gi_1032 > 0) if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_1032 * Point * gd_296, Digits)) return (TRUE); } if (gi_592) { if (g_ticket_1072 != OrderTicket()) { gi_1076 = 0; gi_1080 = 0; g_datetime_1088 = OrderOpenTime(); g_datetime_1084 = g_datetime_1088; g_ticket_1072 = OrderTicket(); g_ord_open_price_1092 = OrderOpenPrice(); } l_ord_profit_0 = OrderProfit(); if (Bid < g_ord_open_price_1092) { gi_1076 += g_datetime_264 - g_datetime_1084; g_datetime_1084 = g_datetime_264; } else { gi_1080 += g_datetime_264 - g_datetime_1084; g_datetime_1084 = g_datetime_264; } if (g_datetime_264 - g_datetime_1088 > 3600.0 * gd_596) { if (g_icci_968 < 0.0 && l_ord_profit_0 > 0.0 && gi_1076 < gi_1080) return (TRUE); if (g_icci_968 < -100.0 && l_ord_profit_0 > 0.0) return (TRUE); if (g_datetime_264 - g_datetime_1088 > 3600.0 * gd_604 && l_ord_profit_0 > 0.0) return (TRUE); if (g_datetime_264 - g_datetime_1088 > 3600.0 * gd_612) return (TRUE); } } if (gi_620) return (Ask <= g_ilow_992); return (Ask <= g_ilow_1008); } int s2_openBuy() { double ld_0 = 0; double ld_8 = 0; if (gd_552 > 0.0) { gi_1024 = gd_552 * (g_ihigh_984 - g_ilow_992) / Point; if (gi_544 > 0 && gi_1024 > gi_544 * gd_296) gi_1024 = gi_544 * gd_296; if (gi_1024 < gi_548 * gd_296) gi_1024 = gi_548 * gd_296; } else gi_1024 = gi_548 * gd_296; if (gi_1024 < g_stoplevel_292) gi_1024 = g_stoplevel_292; if (Stealth) gi_1020 = gi_540 * gd_296; else gi_1020 = gi_536 * gd_296; if (gi_1020 < g_stoplevel_292) gi_1020 = g_stoplevel_292; ld_8 = NormalizeDouble(Bid - gi_1024 * Point, Digits); ld_0 = NormalizeDouble(Ask + gi_1020 * Point, Digits); return (openOrder(OP_BUY, gd_304, Ask, ld_0, ld_8, S2_Reference, gi_564, 0)); } int s2_openSell() { double ld_0 = 0; double ld_8 = 0; if (gd_552 > 0.0) { gi_1032 = gd_552 * (g_ihigh_984 - g_ilow_992) / Point; if (gi_544 > 0 && gi_1032 > gi_544 * gd_296) gi_1032 = gi_544 * gd_296; if (gi_1032 < gi_548 * gd_296) gi_1032 = gi_548 * gd_296; } else gi_1032 = gi_548 * gd_296; if (gi_1032 < g_stoplevel_292) gi_1032 = g_stoplevel_292; if (Stealth) gi_1028 = gi_540 * gd_296; else gi_1028 = gi_536 * gd_296; if (gi_1028 < g_stoplevel_292) gi_1028 = g_stoplevel_292; ld_8 = NormalizeDouble(Ask + gi_1032 * Point, Digits); ld_0 = NormalizeDouble(Bid - gi_1028 * Point, Digits); return (openOrder(OP_SELL, gd_304, Bid, ld_0, ld_8, S2_Reference, gi_568, 0)); } int s2_buyControl() { int li_ret_16; double l_ord_takeprofit_0 = OrderTakeProfit(); double l_ord_stoploss_8 = OrderStopLoss(); if (l_ord_takeprofit_0 == 0.0 || l_ord_stoploss_8 == 0.0) { if (l_ord_takeprofit_0 == 0.0) { if (gi_1020 < g_stoplevel_292) gi_1020 = g_stoplevel_292; l_ord_takeprofit_0 = NormalizeDouble(Ask + gi_1020 * Point, Digits); } if (l_ord_stoploss_8 == 0.0) { if (gi_1024 < g_stoplevel_292) gi_1024 = g_stoplevel_292; l_ord_stoploss_8 = NormalizeDouble(Bid - gi_1024 * Point, Digits); } waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), l_ord_stoploss_8, l_ord_takeprofit_0, 0, Green); } if (s2_closeBuyRule()) { li_ret_16 = closeOrder(0, Violet); if (li_ret_16 < 0) return (li_ret_16); } if (gi_560 > 0) { if (Bid - OrderOpenPrice() > Point * gd_296 * gi_560) { if (OrderStopLoss() < Bid - Point * gd_296 * gi_560 || OrderStopLoss() == 0.0) { waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gd_296 * gi_560, Digits), OrderTakeProfit(), 0, Green); } } } return (OrderTicket()); } int s2_sellControl() { int li_ret_16; double l_ord_takeprofit_0 = OrderTakeProfit(); double l_ord_stoploss_8 = OrderStopLoss(); if (l_ord_takeprofit_0 == 0.0 || l_ord_stoploss_8 == 0.0) { if (l_ord_takeprofit_0 == 0.0) { if (gi_1028 < g_stoplevel_292) gi_1028 = g_stoplevel_292; l_ord_takeprofit_0 = NormalizeDouble(Bid - gi_1028 * Point, Digits); } if (l_ord_stoploss_8 == 0.0) { if (gi_1032 < g_stoplevel_292) gi_1032 = g_stoplevel_292; l_ord_stoploss_8 = NormalizeDouble(Ask + gi_1032 * Point, Digits); } waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), l_ord_stoploss_8, l_ord_takeprofit_0, 0, Red); } if (s2_closeSellRule()) { li_ret_16 = closeOrder(1, Violet); if (li_ret_16 < 0) return (li_ret_16); } if (gi_560 > 0) { if (OrderOpenPrice() - Ask > Point * gd_296 * gi_560) { if (OrderStopLoss() > Ask + Point * gd_296 * gi_560 || OrderStopLoss() == 0.0) { waitForContext(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gd_296 * gi_560, Digits), OrderTakeProfit(), 0, Red); } } } return (OrderTicket()); } void run_Strategy2() { int l_day_of_week_8; gi_708 = TRUE; if (g_ticket_744 == -2) { g_ticket_744 = Recover(S2_Reference, OP_BUY); if (g_ticket_744 >= 0) { OrderSelect(g_ticket_744, SELECT_BY_TICKET); OrderPrint(); Print("Strategy2: Order found:"); } } if (g_ticket_748 == -2) { g_ticket_748 = Recover(S2_Reference, OP_SELL); if (g_ticket_748 >= 0) { OrderSelect(g_ticket_748, SELECT_BY_TICKET); OrderPrint(); Print("Strategy2: Order found:"); } } s2_setRules(); if ((gi_1036 < gi_1040 && (g_hour_272 >= gi_1036 && g_hour_272 <= gi_1040 - 1)) || (gi_1036 >= gi_1040 && g_hour_272 >= gi_1036 || g_hour_272 <= gi_1040 - 1)) gi_708 = TRUE; else gi_708 = FALSE; if (gi_708 && gi_636) { l_day_of_week_8 = TimeDayOfWeek(gi_268); if ((l_day_of_week_8 == 5 && g_hour_272 >= gi_1036) || (l_day_of_week_8 == 1 && gi_1036 >= gi_1040 && g_hour_272 <= gi_1040 - 1)) gi_708 = FALSE; else if (l_day_of_week_8 > 5 || l_day_of_week_8 < 1) gi_708 = FALSE; } if (gi_1100 != gi_708) { if (gi_708) { g_ord_profit_752 = 0; g_ord_profit_760 = 0; gi_772++; } gi_1100 = gi_708; } if (g_ticket_744 >= 0) { if (OrderSelect(g_ticket_744, SELECT_BY_TICKET)) { if (OrderCloseTime() == 0) g_ticket_744 = s2_buyControl(); else g_ticket_744 = -1; g_ord_profit_752 = OrderProfit(); if (g_ticket_744 < 0) CountBalance(g_ord_profit_752); } else { g_ticket_744 = -2; g_ord_profit_752 = 0; } } if (g_ticket_748 >= 0) { if (OrderSelect(g_ticket_748, SELECT_BY_TICKET)) { if (OrderCloseTime() == 0) g_ticket_748 = s2_sellControl(); else g_ticket_748 = -1; g_ord_profit_760 = OrderProfit(); if (g_ticket_748 < 0) CountBalance(g_ord_profit_760); } else { g_ticket_748 = -2; g_ord_profit_760 = 0; } } int li_0 = s2_openBuyRule(); int li_4 = s2_openSellRule(); if (!gi_708 || !gi_712 || gi_700) return; if (NFA && !FIFOrule()) return; if (g_datetime_1104 != iTime(NULL, g_timeframe_532, gi_260) && li_0 && g_ticket_744 < 0 && g_ord_profit_752 >= 0.0) { g_ticket_744 = s2_openBuy(); if (g_ticket_744 < 0) return; g_datetime_1104 = iTime(NULL, g_timeframe_532, gi_260); g_ihigh_1000 = g_ihigh_984; g_ilow_1008 = g_ilow_992; g_ord_profit_760 = 0; gi_964++; return; } if (g_datetime_1108 != iTime(NULL, g_timeframe_532, gi_260) && li_4 && g_ticket_748 < 0 && g_ord_profit_760 >= 0.0) { g_ticket_748 = s2_openSell(); if (g_ticket_748 >= 0) { g_datetime_1108 = iTime(NULL, g_timeframe_532, gi_260); g_ihigh_1000 = g_ihigh_984; g_ilow_1008 = g_ilow_992; g_ord_profit_752 = 0; gi_964++; } } } void Refresh(bool ai_0) { double lda_4[1]; if (ai_0) RefreshRates(); g_datetime_264 = TimeCurrent(); if (!IsTesting() && AutoServerGmtOffset || AutoLocalGmtOffset) { gi_328 = GetGmtOffset(TimeYear(g_datetime_264), TimeMonth(g_datetime_264), TimeDay(g_datetime_264), TimeHour(g_datetime_264), TimeMinute(g_datetime_264), TimeSeconds(g_datetime_264), 0, AutoServerGmtOffset, lda_4); if (gi_328 == 4 && !AutoLocalGmtOffset) gi_328 = 0; else GmtOffset = lda_4[0]; } gi_268 = g_datetime_264 - 3600.0 * GmtOffset; g_hour_272 = TimeHour(gi_268); gi_280 = g_datetime_264 - 3600.0 * g_hour_272 - 60 * TimeMinute(gi_268) - TimeSeconds(gi_268); g_spread_284 = MarketInfo(Symbol(), MODE_SPREAD); g_stoplevel_292 = MarketInfo(Symbol(), MODE_STOPLEVEL); gd_296 = 0.0001 / Point; if (Digits < 4) gd_296 = 100.0 * gd_296; } string BPrint(bool ai_0) { if (ai_0) return ("True"); return ("False"); } string CPrint(bool ai_0, string as_4, string as_12 = "") { if (ai_0) return (as_4); return (as_12); } string OpPrint(int ai_0) { switch (ai_0) { case 0: return ("Buy"); case 1: return ("Sell"); } return ("Order"); } string GMPrint(int ai_0) { switch (ai_0) { case 1: return ("automatic: server"); case 2: return ("automatic: server"); case 4: return ("automatic: local"); } return ("manual"); } string DPrint(int ai_0) { switch (ai_0) { case 1: return ("Correction"); case 3: return ("Upward Impulse"); case 2: return ("Downward Impulse"); } return (""); } string PPrint(int ai_0) { int li_4 = MathMod(ai_0, 5); return (gsa_1112[li_4]); } string PrintStatus(int ai_0) { switch (ai_0) { case 1: return ("Assessing market volume"); case 2: return ("Checking volatility"); case 3: return ("Monitoring spread"); case 4: return ("Determining direction"); case 5: return ("Reviewing price range"); case 6: return ("Calculating probability"); } return (""); } void PrintResponse(int ai_0, int ai_4 = -1, int ai_8 = -1) { if (ai_4 == -1) ai_4 = gi_660; if (ai_8 == -1) ai_8 = gi_656; gi_660 = ai_4; gi_656 = ai_8; if (ai_0 & 16384 > 0) PrintLN("Authenticated", TextColor1); else PrintLN("Authentication failed - error(" + ai_0 + ")", TextColor1); if (ai_0 & 512 > 0) PrintLN("Attention: Upgrade available", TextColor1); if (ai_0 & 1024 > 0) PrintLN("Error: Upgrade required", TextColor1); if (ai_0 & 1 > 0) PrintLN("Error: WinINet initialisation failed", TextColor1); if (ai_0 & 2 > 0) PrintLN("Error: WinINet connection failed", TextColor1); if (ai_0 & 4 > 0) PrintLN("Error: Invalid account number", TextColor1); if (ai_0 & 8 > 0) PrintLN("Error: Invalid account status", TextColor1); if (ai_0 & 16 > 0) PrintLN("Error: Dll and Expert versions mismatch", TextColor1); if (ai_0 & 128 > 0) PrintLN("Error: Unable to retrieve authentication code", TextColor1); if (ai_0 & 256 > 0) PrintLN("Error: Server response failure", TextColor1); if (ai_0 & 2048 > 0) PrintLN("Error: Invalid authorisation details", TextColor1); if (ai_0 & 4096 > 0) PrintLN("Error: Authorisation declined", TextColor1); } string GetObjName(int ai_0) { return (StringConcatenate("MegaDroid", " lb: ", ai_0)); } void GetPos(int ai_0, int &ai_4, int &ai_8) { string l_name_12 = GetObjName(ai_0); if (ObjectFind(l_name_12) == 0) { ai_4 = ObjectGet(l_name_12, OBJPROP_XDISTANCE); ai_8 = ObjectGet(l_name_12, OBJPROP_YDISTANCE); } } void PrintLN(string a_text_0, color a_color_8 = -1, int ai_12 = -1, double ad_16 = -1.0, int ai_24 = 0) { if (a_color_8 == CLR_NONE) a_color_8 = TextColor1; if (ai_12 == -1) ai_12 = gi_660; if (ad_16 == -1.0) ad_16 = gi_656; string l_name_28 = GetObjName(ai_12); if (ObjectFind(l_name_28) != 0) { ObjectCreate(l_name_28, OBJ_LABEL, 0, 0, 0); ObjectSet(l_name_28, OBJPROP_CORNER, 0); } ObjectSetText(l_name_28, a_text_0, 8, "Tahoma", a_color_8); ObjectSet(l_name_28, OBJPROP_XDISTANCE, gi_672 + ai_24); ObjectSet(l_name_28, OBJPROP_YDISTANCE, gi_668 + 14.0 * ad_16); if (gi_656 < ad_16 + 1.0) gi_656 = ad_16 + 1.0; if (gi_660 < ai_12 + 1) gi_660 = ai_12 + 1; if (gi_664 < ai_12) gi_664 = ai_12; } void PrintSep(int ai_0 = -1, double ad_4 = -1.0, int ai_12 = 0) { if (ai_0 == -1) ai_0 = gi_660; if (ad_4 == -1.0) ad_4 = gi_656; PrintLN("_______", TextColor2, ai_0, ad_4 - 0.3, ai_12); if (gi_656 < ad_4 + 1.0) gi_656 = ad_4 + 1.0; } void Deleteobjects(int ai_0, int ai_4) { for (int li_8 = ai_0; li_8 <= ai_4; li_8++) ObjectDelete(GetObjName(li_8)); } double Base36Decode(string as_0) { int li_24; as_0 = StringUpper(as_0); int l_str_len_8 = StringLen(as_0); double ld_ret_12 = 0; for (int li_20 = 0; li_20 < l_str_len_8; li_20++) { li_24 = StringFind(gs_1124, StringSubstr(as_0, l_str_len_8 - li_20 - 1, 1)); ld_ret_12 += li_24 * MathPow(36, li_20); } return (ld_ret_12); } string Base36Encode(double ad_0) { string l_str_concat_8 = ""; for (ad_0 = MathAbs(ad_0); ad_0 >= 1.0; ad_0 = MathFloor(ad_0 / 36.0)) l_str_concat_8 = StringConcatenate(StringSubstr(gs_1124, MathMod(ad_0, 36), 1), l_str_concat_8); return (l_str_concat_8); } string StringUpper(string as_0) { int li_8; int li_20; int l_str_len_16 = StringLen(as_0); for (int li_12 = 0; li_12 < l_str_len_16; li_12++) { li_20 = 0; li_8 = StringGetChar(as_0, li_12); if (li_8 > '`' && li_8 < '{') li_20 = li_8 - 32; if (li_8 > 'ß' && li_8 < 256) li_20 = li_8 - 32; if (li_8 == '¸') li_20 = 168; if (li_20 > 0) as_0 = StringSetChar(as_0, li_12, li_20); } return (as_0); } int start() { int li_4; int li_8; if (!gi_244 && !gi_248) return (0); int li_0 = GetState(); if (Bars < 100) { Print("Bars less than 100"); return (0); } if (gi_320) { gi_320 = FALSE; li_4 = RecoverTrades(); Print("Orders in history: ", li_4, " profit made: ", DoubleToStr(gd_684, 2)); } if (gi_220 && RiskLevel > 0.0) { if (gi_240) while (AccountBalance() < gd_312 / (gd_232 + 1.0)) gd_312 /= (gd_232 + 1.0); while (AccountBalance() > gd_312) gd_312 *= (gd_232 + 1.0); gd_304 = MMLots(RiskLevel, gd_312, li_8); } else { if (RiskLevel > 0.0) { gd_304 = MMLots(RiskLevel, AccountFreeMargin(), li_8); if (RecoveryMode) gd_304 = RecoveryLot(gd_304); } else gd_304 = NormalizeLots(LotSize, li_8); } double ld_12 = NormalizeDouble(MarketInfo(Symbol(), MODE_MARGINREQUIRED) * gd_304, 8); g_spread_288 = g_spread_284; Refresh(0); gi_700 = NormalizeDouble(AccountFreeMargin(), 8) < ld_12; gi_712 = IsTradeTime(Symbol(), TimeYear(gi_268), TimeMonth(gi_268), TimeDay(gi_268), gi_252); if (NFA) RefreshOrders(); if (gi_244) run_Strategy1(); Refresh(1); gi_700 = NormalizeDouble(AccountFreeMargin(), 8) < ld_12; if (gi_248) run_Strategy2(); if (IsTesting() && !IsVisualMode()) return (0); GetPos(0, gi_672, gi_668); gi_660 = 0; gi_656 = 0; PrintLN(gs_332, TextColor2); PrintSep(); PrintResponse(gi_324); PrintSep(); PrintLN(gs_340); PrintLN(gs_348, TextColor2, gi_660, gi_656 - 1, 5 * (StringLen(gs_340) + 1)); PrintSep(); string ls_20 = DoubleToStr(GmtOffset, 1); if (!IsTesting()) ls_20 = StringConcatenate(ls_20, " (", GMPrint(gi_328), ")"); PrintLN("ServerTime:"); PrintLN(TimeToStr(g_datetime_264), TextColor2, gi_660, gi_656 - 1, 60); PrintLN("UtcTime:"); PrintLN(TimeToStr(gi_268), TextColor2, gi_660, gi_656 - 1, 45); PrintLN("GmtOffset:"); PrintLN(ls_20, TextColor2, gi_660, gi_656 - 1, 55); PrintSep(); PrintLN("Digits:"); PrintLN(Digits, TextColor2, gi_660, gi_656 - 1, 35); PrintLN("Spread:"); PrintLN(StringConcatenate(DoubleToStr(g_spread_284 / gd_296, 1), " (", g_spread_284, " pips)"), TextColor2, gi_660, gi_656 - 1, 40); PrintSep(); PrintLN("Lot:"); PrintLN(DoubleToStr(gd_304, 2), TextColor2, gi_660, gi_656 - 1, 25); switch (li_8) { case 1: PrintLN("Maximum Lot size exeeded!"); break; case -1: PrintLN("Minimum Lot size exeeded!"); } if (gi_1132 != gi_700) { if (gi_700) Print("Not enough money! Available margin = ", DoubleToStr(AccountFreeMargin(), 2), ", Required margin = ", DoubleToStr(ld_12, 2)); gi_1132 = gi_700; } if (gi_700) { PrintSep(); PrintLN("Not enough money!"); PrintLN("Available margin ="); PrintLN(DoubleToStr(AccountFreeMargin(), 2), TextColor2, gi_660, gi_656 - 1, 90); PrintLN("Required margin ="); PrintLN(DoubleToStr(ld_12, 2), TextColor2, gi_660, gi_656 - 1, 90); } PrintSep(); if (IsTesting()) PrintLN("Backtesting"); else PrintLN(PrintStatus(GetStatus())); PrintSep(); if (gi_244 && gi_480) { if (gi_916 == 0) PrintLN("Analyzing market"); else PrintLN(DPrint(gi_916) + " detected"); if (g_datetime_264 <= gi_924 && gi_916 != gi_920 && gi_920 != 0) PrintLN(DPrint(gi_920) + " fading: " + TimeToStr(gi_924 - g_datetime_264, TIME_SECONDS)); } else PrintLN(CPrint(gi_704 || gi_708, "Running", "Collecting Data")); if (NFA && g_count_716 > 0) { PrintSep(); PrintLN("Waiting for trades to close: "); PrintLN(g_count_716, TextColor2, gi_660, gi_656 - 1, 125); } if (g_ticket_720 >= 0 || g_ticket_724 >= 0 || g_ticket_744 >= 0 || g_ticket_724 >= 0) { PrintSep(); if (g_ticket_720 >= 0) PrintLN("Strategy1: Long position open"); if (g_ticket_724 >= 0) PrintLN("Strategy1: Short position open"); if (g_ticket_744 >= 0) PrintLN("Strategy2: Long position open"); if (g_ticket_748 >= 0) PrintLN("Strategy2: Short position open"); } Deleteobjects(gi_660, gi_664); gi_664 = gi_660 - 1; ObjectsRedraw(); return (0); }