#property copyright "FXiGoR" #property link "CashDNA@gmail.com" #property show_inputs #include #import "Cash_DNA_v3.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[], string a11); #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; double gd_192 = 0.5; extern int Magic = 280; double gda_204[][6]; double gda_208[][6]; double gd_212; double gda_220[2]; double gd_224; double gd_232; double gd_240; double gd_248; double gd_256; double gd_264; double gd_272; double g_ord_open_price_280; double g_ord_open_price_288; double gd_296; double gd_304; double g_minlot_312; double g_lotstep_320; string g_comment_328; string g_str_concat_336; string gs_344; string gs_352; int g_pos_360; int g_count_364; int g_count_368; int gi_372; int gi_376; datetime g_time_380; int g_datetime_388; int g_datetime_392; int gi_396; int g_datetime_400; bool g_bool_404; bool g_bool_408; bool g_bool_412; int gi_unused_416; bool gi_420; bool gi_424; bool g_bool_428; bool g_bool_432; bool gi_436 = FALSE; int g_acc_number_440; int g_bool_444; int gi_448; int g_str_len_452; int gi_456; int g_hour_460; int g_day_of_week_464; void init() { if (IsTesting() == 0) { gs_352 = StringSubstr(Symbol(), 0, 6); if (gs_352 != "USDCAD" && gs_352 != "USDJPY" && gs_352 != "USDCHF" && gs_352 != "GBPUSD" && gs_352 != "EURUSD") return; g_comment_328 = WindowExpertName() + " "; gd_272 = MarketInfo(Symbol(), MODE_TICKVALUE); gd_224 = Point; if (Digits == 5 || Digits == 3) { gd_224 = 10.0 * gd_224; gd_272 = 10.0 * gd_272; } g_minlot_312 = MarketInfo(Symbol(), MODE_MINLOT); g_lotstep_320 = MarketInfo(Symbol(), MODE_LOTSTEP); if (CompareDoubles(g_lotstep_320, 1.0)) gi_376 = 0; if (CompareDoubles(g_lotstep_320, 0.1)) gi_376 = 1; if (CompareDoubles(g_lotstep_320, 0.01)) gi_376 = 2; if (CompareDoubles(g_lotstep_320, 0.001)) gi_376 = 3; gd_240 = TakeProfit * gd_224; gd_232 = StopLoss * gd_224; gd_248 = HiddenTakeProfit * gd_224; gd_256 = SpreadMaxToOpen * gd_224; gd_264 = gd_100 * gd_224; gi_420 = PrimarySessionStopHour > gi_120; gi_424 = gi_148 > gi_144; gs_344 = gi_124; if (gi_124 < 10) gs_344 = "0" + gs_344; g_acc_number_440 = AccountNumber(); g_bool_444 = IsDemo(); gi_448 = WindowHandle(Symbol(), 0); g_str_len_452 = StringLen(Key); gda_220[0] = StrToDouble(Key); gda_220[1] = 0; g_time_380 = 0; gi_372 = Bars - 1; gi_456 = 3600 * CETOffset; ObjectCreate("Limits", OBJ_RECTANGLE, 0, 0, 0, 0, 0); ObjectSet("Limits", OBJPROP_COLOR, Yellow); gi_436 = TRUE; start(); } } void deinit() { ObjectDelete("Limits"); Comment(""); } void start() { if (gi_436) { if (AccountEquity() <= AccountBalance() * gd_192) g_datetime_400 = TimeCurrent(); if (g_datetime_400 > 0) { CloseAll(); if (TimeCurrent() > g_datetime_400 + 43200) g_datetime_400 = 0; } gi_396 = TimeCurrent() - gi_456; g_hour_460 = TimeHour(gi_396); g_day_of_week_464 = TimeDayOfWeek(gi_396); CheckPositions(); CheckNewBar(); gd_304 = Ask - Bid; if (Bid <= gda_220[1]) { if (g_count_368 > 0 && gd_304 <= gd_264) CloseAllByType(OP_SELL); if (g_count_364 < OrdersMax && gd_304 <= gd_256) { if (g_bool_404 && g_count_364 == 0) OpenLong(); if (g_bool_408 && g_count_364 > 0 && Ask < g_ord_open_price_280 - gd_296) OpenLong(); } } if (Bid >= gda_220[0]) { if (g_count_364 > 0 && gd_304 <= gd_264) CloseAllByType(OP_BUY); if (g_count_368 < OrdersMax && gd_304 <= gd_256) { if (g_bool_404 && g_count_368 == 0) OpenShort(); if (g_bool_408 && g_count_368 > 0 && Bid > g_ord_open_price_288 + gd_296) OpenShort(); } } if (g_bool_428) { if (HiddenTakeProfit < TakeProfit) { for (g_pos_360 = OrdersTotal() - 1; g_pos_360 >= 0; g_pos_360--) { if (OrderSelect(g_pos_360, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) { if (OrderMagicNumber() == Magic) { RefreshRates(); if (OrderType() == OP_BUY && Bid >= OrderOpenPrice() + gd_248) OrderClose(OrderTicket(), OrderLots(), Bid, 2, Pink); if (OrderType() == OP_SELL && Ask <= OrderOpenPrice() - gd_248) OrderClose(OrderTicket(), OrderLots(), Ask, 2, Pink); } } } } } if (g_bool_412 && g_bool_432) { g_bool_432 = FALSE; for (g_pos_360 = OrdersTotal() - 1; g_pos_360 >= 0; g_pos_360--) { if (OrderSelect(g_pos_360, SELECT_BY_POS)) { if (OrderSymbol() == Symbol()) { if (OrderMagicNumber() == Magic) { if (OrderProfit() >= 0.0) { g_bool_432 = TRUE; OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, White); } else { if (MathAbs(OrderTakeProfit() - OrderOpenPrice()) > gd_224) { g_bool_432 = TRUE; OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice(), 0, Pink); } } } } } } } } WriteComment(); } } void CheckNewBar() { int li_0; int l_error_4; int li_8; if (Time[0] != g_time_380) { gi_372++; if (gi_372 != Bars) { gda_220[0] = StrToDouble(Key); gda_220[1] = 0; Sleep(2000); } GetLastError(); li_0 = ArrayCopyRates(gda_204, Symbol(), 0); l_error_4 = GetLastError(); if (l_error_4 > 0/* NO_ERROR */ || li_0 < 501) { if (l_error_4 == 4066/* HISTORY_WILL_UPDATED */) Print("Updating the History..."); else Print("Error passing datas to the Dll: ", l_error_4, " Records: ", li_0); } else { li_8 = ArrayCopyRates(gda_208, Symbol(), PERIOD_D1); l_error_4 = GetLastError(); if (l_error_4 > 0/* NO_ERROR */ || li_8 < 7) { if (l_error_4 == 4066/* HISTORY_WILL_UPDATED */) Print("Updating the Daily History..."); else Print("Error passing Daily datas to the Dll: ", l_error_4, " Records: ", li_8); } else { GetLimits(EntropyFactor, gda_204, li_0, gda_208, li_8, g_acc_number_440, g_bool_444, gi_448, Key, g_str_len_452, gda_220, gs_352); gd_212 = gda_220[0] - gda_220[1]; gd_296 = gd_212 * OrdersStepFactor; if (gi_420) g_bool_404 = g_hour_460 > gi_120 || (g_hour_460 == gi_120 && Minute() >= gi_124) && g_hour_460 < PrimarySessionStopHour; else g_bool_404 = g_hour_460 > gi_120 || (g_hour_460 == gi_120 && Minute() >= gi_124) || g_hour_460 < PrimarySessionStopHour; if (gi_424) g_bool_408 = g_hour_460 >= gi_144 && g_hour_460 < gi_148; else g_bool_408 = g_hour_460 >= gi_144 || g_hour_460 < gi_148; g_bool_412 = g_hour_460 == gi_176; if (!g_bool_412) g_bool_432 = g_bool_428; if (gi_180) { if ((g_day_of_week_464 == 5 && g_hour_460 >= 12) || g_day_of_week_464 == 6 || g_day_of_week_464 == 0 || (g_day_of_week_464 == 1 && g_hour_460 < 12)) { g_bool_404 = FALSE; g_bool_408 = FALSE; gi_unused_416 = 1; } } if (g_datetime_400 > 0) { g_bool_404 = FALSE; g_bool_408 = FALSE; } g_time_380 = Time[0]; gi_372 = Bars; ObjectMove("Limits", 0, g_time_380 + 300 * Period(), gda_220[0]); ObjectMove("Limits", 1, g_time_380 + 360 * Period(), gda_220[1]); ObjectSetText("Limits", "Limits Size: " + DoubleToStr(gd_212 / gd_224, 1)); RefreshRates(); } } } } void WriteComment() { if (gda_220[0] > 99999.0) { Comment("\n" + g_comment_328 + "has EXPIRED, please contact iGoR for a new key"); return; } g_str_concat_336 = StringConcatenate("\nLast Tick Time: ", TimeToStr(gi_396, TIME_MINUTES|TIME_SECONDS), " CET", "\nEntropy: ", DoubleToStr(gd_212 / gd_224, 1), " Spread: ", DoubleToStr((Ask - Bid) / gd_224, 1)); if (g_bool_404) { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nPrimary Session is OPEN until ", GetSessionStop(PrimarySessionStopHour), ":00 CET"); } else { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nPrimary Session is CLOSE until ", GetSessionStart(gi_120), ":", gs_344, " CET"); } if (g_bool_428) { if (g_count_364 < OrdersMax && g_count_368 < OrdersMax) { if (g_bool_408) { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nAveraging Session is OPEN until ", GetSessionStop(gi_148), ":00 CET"); } else { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nAveraging Session is CLOSE until ", GetSessionStart(gi_144), ":00 CET"); } } if (g_bool_412) { if (g_bool_432) { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nTrying to move TakeProfits to Breakeven"); } else { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nAll TakeProfits are moved to Breakeven"); } } g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nWaiting to close the position..."); } if (g_datetime_400 > 0) { g_str_concat_336 = StringConcatenate(g_str_concat_336, "\nALL POSITIONS ARE CLOSED TO PROTECT THE ACCOUNT."); } Comment(g_str_concat_336); } string GetSessionStop(int ai_0) { if (g_hour_460 < ai_0) { if (gi_180 && g_day_of_week_464 == 5) return (StringConcatenate("Today ", MathMin(ai_0, 12))); return (StringConcatenate("Today ", ai_0)); } if (gi_180 && g_day_of_week_464 == 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_464 == 6 || g_day_of_week_464 == 0 || (g_day_of_week_464 == 5 && g_hour_460 >= 12 || ai_0 >= 12) || (g_day_of_week_464 == 4 && g_hour_460 >= ai_0 && ai_0 >= 12)) return (StringConcatenate("Monday ", MathMax(12, ai_0))); } if (g_day_of_week_464 < 6 && g_hour_460 < ai_0) return (StringConcatenate("Today ", ai_0)); if (g_day_of_week_464 < 5) return (StringConcatenate("Tomorrow ", ai_0)); return (StringConcatenate("Monday ", ai_0)); } void OpenLong() { double l_ask_0 = Ask; int l_ticket_8 = OrderSend(Symbol(), OP_BUY, GetLots(gd_232), l_ask_0, 2, 0, 0, g_comment_328, Magic, 0, DeepSkyBlue); if (l_ticket_8 < 0) { PrintError("ERROR OPENING A LONG POSITION : "); return; } if (!OrderSelect(l_ticket_8, SELECT_BY_TICKET)) { PrintError("ERROR SELECTING ORDER # " + l_ticket_8 + " : "); return; } Print("SLIPPAGE OPENNING ORDER # ", l_ticket_8, " : ", DoubleToStr((OrderOpenPrice() - l_ask_0) / gd_224, 1)); if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - gd_232, OrderOpenPrice() + gd_240, 0)) PrintError("ERROR MODIFYING ORDER # " + l_ticket_8 + " : "); } void OpenShort() { double l_bid_0 = Bid; int l_ticket_8 = OrderSend(Symbol(), OP_SELL, GetLots(gd_232), l_bid_0, 2, 0, 0, g_comment_328, Magic, 0, DarkOrange); if (l_ticket_8 < 0) { PrintError("ERROR OPENING A SHORT POSITION : "); return; } if (!OrderSelect(l_ticket_8, SELECT_BY_TICKET)) { PrintError("ERROR SELECTING ORDER # " + l_ticket_8 + " : "); return; } Print("SLIPPAGE OPENNING ORDER # ", l_ticket_8, " : ", DoubleToStr((l_bid_0 - OrderOpenPrice()) / gd_224, 1)); if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + gd_232, OrderOpenPrice() - gd_240, 0)) PrintError("ERROR MODIFYING ORDER # " + l_ticket_8 + " : "); } void PrintError(string as_0) { int l_error_8 = GetLastError(); Print(as_0, l_error_8, " ", ErrorDescription(l_error_8)); } void CheckPositions() { g_datetime_388 = 0; g_datetime_392 = 0; g_count_364 = 0; g_count_368 = 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_364++; if (OrderOpenTime() > g_datetime_388) { g_datetime_388 = OrderOpenTime(); g_ord_open_price_280 = OrderOpenPrice(); } } if (OrderType() == OP_SELL) { g_count_368++; if (OrderOpenTime() > g_datetime_392) { g_datetime_392 = OrderOpenTime(); g_ord_open_price_288 = OrderOpenPrice(); } } } } } } g_bool_428 = g_count_364 > 0 || g_count_368 > 0; } void CloseAllByType(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 CloseAll() { for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { if (OrderSelect(l_pos_0, SELECT_BY_POS)) if (OrderMagicNumber() == Magic) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Yellow); } } double GetLots(double ad_0) { double ld_8 = NormalizeDouble(AccountBalance() * gd_184 / (gd_272 * ad_0 / gd_224), gi_376); ld_8 = MathMax(g_minlot_312, ld_8); return (ld_8); }