#property copyright "FXiGoR" #property link "http://www.forex-tsd.com/commercial-trading-systems-indicators/22016-fxigor-trading-group-powered-ea.html" #property show_inputs #import "Cash_DNA_v2.dll" void GetLimits(double a0, double& a1[], int a2, double& a3[], int a4, int a5, int a6, int a7, string a8, int a9, double& a10[]); #import extern string Key = "Enter your key here"; extern double EntropyFactor = 0.2; extern double SpreadMaxToOpen = 4.1; double gd_100 = 15.0; extern string info = "!!! All the times are CET times !!!"; extern int CETOffset = 0; int gi_120 = 23; int gi_124 = 0; extern int PrimarySessionStopHour = 0; extern int OrdersMax = 2; extern double OrdersStepFactor = 1.0; int gi_144 = 23; int gi_148 = 8; extern double StopLoss = 60.0; extern double TakeProfit = 10.0; extern double HiddenTakeProfit = 20.0; int gi_176 = 8; bool gi_180 = TRUE; double gd_184 = 0.1; extern double LotsBase = 0.1; extern int LotsDigits = 1; extern int Magic = 280; double gda_208[][6]; double gda_212[][6]; double gd_216; double gda_224[2]; double gd_228; double gd_236; double gd_244; double gd_252; double gd_260; double gd_268; double gd_276; double g_ord_open_price_284; double g_ord_open_price_292; double g_lots_300; double gd_308; double gd_316; string g_comment_324; string g_str_concat_332; string gs_340; int g_pos_348; int g_count_352; int g_count_356; int g_ticket_360; int gi_364; int gi_368; int g_error_372; datetime g_time_376; int g_datetime_384; int g_datetime_388; int gi_392; bool g_bool_396; bool g_bool_400; bool g_bool_404; int gi_unused_408; bool gi_412; bool gi_416; bool g_bool_420; bool g_bool_424; int g_acc_number_428; int g_bool_432; int gi_436; int g_str_len_440; int gi_444; int g_hour_448; int g_day_of_week_452; void init() { if (IsTesting() == 0) { g_comment_324 = WindowExpertName() + " "; gd_276 = MarketInfo(Symbol(), MODE_TICKVALUE); gd_228 = Point; if (Digits == 5 || Digits == 3) { gd_228 = 10.0 * gd_228; gd_276 = 10.0 * gd_276; } gd_244 = TakeProfit * gd_228; gd_236 = StopLoss * gd_228; gd_252 = HiddenTakeProfit * gd_228; gd_260 = SpreadMaxToOpen * gd_228; gd_268 = gd_100 * gd_228; gi_412 = PrimarySessionStopHour > gi_120; gi_416 = gi_148 > gi_144; g_time_376 = 0; gs_340 = gi_124; if (gi_124 < 10) gs_340 = "0" + gs_340; g_acc_number_428 = AccountNumber(); g_bool_432 = IsDemo(); gi_436 = WindowHandle(Symbol(), 0); g_str_len_440 = StringLen(Key); gda_224[0] = 100000; gda_224[1] = 0; gi_444 = 3600 * CETOffset; ObjectCreate("Limits", OBJ_RECTANGLE, 0, 0, 0, 0, 0); ObjectSet("Limits", OBJPROP_COLOR, Yellow); } } void deinit() { ObjectDelete("Limits"); Comment(""); } void start() { if (IsTesting() == 0) { gi_392 = TimeCurrent() - gi_444; g_hour_448 = TimeHour(gi_392); g_day_of_week_452 = TimeDayOfWeek(gi_392); CheckPositions(); CheckNewBar(); gd_316 = Ask - Bid; if (Bid <= gda_224[1]) { if (g_count_356 > 0 && gd_316 <= gd_268) CloseAll(OP_SELL); if (g_count_352 < OrdersMax && gd_316 <= gd_260) { if (g_bool_396 && g_count_352 == 0) OpenLong(); if (g_bool_400 && g_count_352 > 0 && Ask < g_ord_open_price_284 - gd_308) OpenLong(); } } if (Bid >= gda_224[0]) { if (g_count_352 > 0 && gd_316 <= gd_268) CloseAll(OP_BUY); if (g_count_356 < OrdersMax && gd_316 <= gd_260) { if (g_bool_396 && g_count_356 == 0) OpenShort(); if (g_bool_400 && g_count_356 > 0 && Bid > g_ord_open_price_292 + gd_308) OpenShort(); } } if (g_bool_420) { if (HiddenTakeProfit < TakeProfit) { for (g_pos_348 = OrdersTotal() - 1; g_pos_348 >= 0; g_pos_348--) { if (OrderSelect(g_pos_348, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) { if (OrderMagicNumber() == Magic) { RefreshRates(); if (OrderType() == OP_BUY && Bid >= OrderOpenPrice() + gd_252) OrderClose(OrderTicket(), OrderLots(), Bid, 2, Pink); if (OrderType() == OP_SELL && Ask <= OrderOpenPrice() - gd_252) OrderClose(OrderTicket(), OrderLots(), Ask, 2, Pink); } } } } } if (g_bool_404 && g_bool_424) { g_bool_424 = FALSE; for (g_pos_348 = OrdersTotal() - 1; g_pos_348 >= 0; g_pos_348--) { if (OrderSelect(g_pos_348, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) { if (OrderMagicNumber() == Magic) { if (OrderProfit() >= 0.0) { g_bool_424 = TRUE; OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, White); } else { if (MathAbs(OrderTakeProfit() - OrderOpenPrice()) > gd_228) { g_bool_424 = TRUE; OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice(), 0, Pink); } } } } } } } } WriteComment(); } } void CheckNewBar() { if (Time[0] != g_time_376) { GetLastError(); gi_364 = ArrayCopyRates(gda_208, Symbol(), 0); g_error_372 = GetLastError(); if (g_error_372 > 0/* NO_ERROR */ || gi_364 < 501) { if (g_error_372 == 4066/* HISTORY_WILL_UPDATED */) Print("Updating the History..."); else Print("Error passing datas to the Dll: ", g_error_372, " Records: ", gi_364); } else { gi_368 = ArrayCopyRates(gda_212, Symbol(), PERIOD_D1); g_error_372 = GetLastError(); if (g_error_372 > 0/* NO_ERROR */ || gi_368 < 7) { if (g_error_372 == 4066/* HISTORY_WILL_UPDATED */) Print("Updating the Daily History..."); else Print("Error passing Daily datas to the Dll: ", g_error_372, " Records: ", gi_368); } else { GetLimits(EntropyFactor, gda_208, gi_364, gda_212, gi_368, g_acc_number_428, g_bool_432, gi_436, Key, g_str_len_440, gda_224); gd_216 = gda_224[0] - gda_224[1]; gd_308 = gd_216 * OrdersStepFactor; if (gi_412) g_bool_396 = g_hour_448 > gi_120 || (g_hour_448 == gi_120 && Minute() >= gi_124) && g_hour_448 < PrimarySessionStopHour; else g_bool_396 = g_hour_448 > gi_120 || (g_hour_448 == gi_120 && Minute() >= gi_124) || g_hour_448 < PrimarySessionStopHour; if (gi_416) g_bool_400 = g_hour_448 >= gi_144 && g_hour_448 < gi_148; else g_bool_400 = g_hour_448 >= gi_144 || g_hour_448 < gi_148; g_bool_404 = g_hour_448 == gi_176; if (!g_bool_404) g_bool_424 = g_bool_420; if (gi_180) { if ((g_day_of_week_452 == 5 && g_hour_448 >= 12) || g_day_of_week_452 == 6 || g_day_of_week_452 == 0 || (g_day_of_week_452 == 1 && g_hour_448 < 12)) { g_bool_396 = FALSE; g_bool_400 = FALSE; gi_unused_408 = 1; } } g_time_376 = Time[0]; ObjectMove("Limits", 0, g_time_376 + 300 * Period(), gda_224[0]); ObjectMove("Limits", 1, g_time_376 + 360 * Period(), gda_224[1]); ObjectSetText("Limits", "Limits Size: " + DoubleToStr(gd_216 / gd_228, 1)); RefreshRates(); } } } } void WriteComment() { if (IsTesting() && !IsVisualMode()) return; if (gda_224[0] > 99999.0) { Comment("\n" + g_comment_324 + "has EXPIRED, please contact iGoR for a new key"); return; } g_str_concat_332 = StringConcatenate("\nLast Tick Time: ", TimeToStr(gi_392, TIME_MINUTES|TIME_SECONDS), " CET", "\nEntropy: ", DoubleToStr(gd_216 / gd_228, 1), " Spread: ", DoubleToStr((Ask - Bid) / gd_228, 1)); if (g_bool_396) { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nPrimary Session is OPEN until ", GetSessionStop(PrimarySessionStopHour), ":00 CET"); } else { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nPrimary Session is CLOSE until ", GetSessionStart(gi_120), ":", gs_340, " CET"); } if (g_bool_420) { if (g_count_352 < OrdersMax && g_count_356 < OrdersMax) { if (g_bool_400) { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nAveraging Session is OPEN until ", GetSessionStop(gi_148), ":00 CET"); } else { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nAveraging Session is CLOSE until ", GetSessionStart(gi_144), ":00 CET"); } } if (g_bool_404) { if (g_bool_424) { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nTrying to move TakeProfits to Breakeven"); } else { g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nAll TakeProfits are moved to Breakeven"); } } g_str_concat_332 = StringConcatenate(g_str_concat_332, "\nWaiting to close the position..."); } Comment(g_str_concat_332); } string GetSessionStop(int ai_0) { if (g_hour_448 < ai_0) { if (gi_180 && g_day_of_week_452 == 5) return (StringConcatenate("Today ", MathMin(ai_0, 12))); return (StringConcatenate("Today ", ai_0)); } if (gi_180 && g_day_of_week_452 == 4) return (StringConcatenate("Tomorrow ", MathMin(ai_0, 12))); return (StringConcatenate("Tomorrow ", ai_0)); } string GetSessionStart(int ai_0) { if (gi_180) { if (g_day_of_week_452 == 6 || g_day_of_week_452 == 0 || (g_day_of_week_452 == 5 && g_hour_448 >= 12 || ai_0 >= 12) || (g_day_of_week_452 == 4 && g_hour_448 >= ai_0 && ai_0 >= 12)) return (StringConcatenate("Monday ", MathMax(12, ai_0))); } if (g_day_of_week_452 < 6 && g_hour_448 < ai_0) return (StringConcatenate("Today ", ai_0)); if (g_day_of_week_452 < 5) return (StringConcatenate("Tomorrow ", ai_0)); return (StringConcatenate("Monday ", ai_0)); } void OpenLong() { GetLots(gd_236); g_ticket_360 = OrderSend(Symbol(), OP_BUY, g_lots_300, Ask, 2, 0, 0, g_comment_324, Magic, 0, DeepSkyBlue); if (g_ticket_360 > 0) if (OrderSelect(g_ticket_360, SELECT_BY_TICKET)) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - gd_236, OrderOpenPrice() + gd_244, 0); } void OpenShort() { GetLots(gd_236); g_ticket_360 = OrderSend(Symbol(), OP_SELL, g_lots_300, Bid, 2, 0, 0, g_comment_324, Magic, 0, DarkOrange); if (g_ticket_360 > 0) if (OrderSelect(g_ticket_360, SELECT_BY_TICKET)) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + gd_236, OrderOpenPrice() - gd_244, 0); } void CheckPositions() { g_datetime_384 = 0; g_datetime_388 = 0; g_count_352 = 0; g_count_356 = 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() == Magic) { if (OrderType() == OP_BUY) { g_count_352++; if (OrderOpenTime() > g_datetime_384) { g_datetime_384 = OrderOpenTime(); g_ord_open_price_284 = OrderOpenPrice(); } } if (OrderType() == OP_SELL) { g_count_356++; if (OrderOpenTime() > g_datetime_388) { g_datetime_388 = OrderOpenTime(); g_ord_open_price_292 = OrderOpenPrice(); } } } } } } g_bool_420 = g_count_352 > 0 || g_count_356 > 0; } void CloseAll(int a_cmd_0) { for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { if (OrderSelect(l_pos_4, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) { if (OrderMagicNumber() == Magic) if (OrderType() == a_cmd_0) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Yellow); } } } } void GetLots(double ad_0) { g_lots_300 = NormalizeDouble(AccountBalance() * gd_184 / (gd_276 * ad_0 / gd_228), LotsDigits); g_lots_300 = MathMax(LotsBase, g_lots_300); }