//+------------------------------------------------------------------+ //| Ilan-Trio V1.48T.mq4 | //| Night | //| http://alfonius@yandex.ru | //+------------------------------------------------------------------+ // 1.47Т Добавлен индикатор биржевого времени // 1.47: Введён режим "Turbo": первое колено=1/3 пипстепа,второе =2/3 пипстепа для повышения прибыльности во флете // Добавлен режим "NewCycle" отмены выставления новых ордеров. Открытые серии продолжают работать // Отключен информационный индикатор (для ускорения тестирования и оптимизации), так же при работе часто // вызывал зависание терминала // Добавлена переменная PeriodRSI, позволяющая выбирать таймфрейм // для RSI:1=M1, 2=M5, 3=M15, 4=M30, 5=H1, 6=H4, 7=D1, 8=W1, 9=MN1, 0=Period() // 1.46: добавлена нормализация цен при расчёте OrderSend, чем избавились от ошибок при расчёте ордеров // 1.45: убраны неиспользуемые ф-ции // добавлена проверка расчёта ТР, для исключения открытия ордеров с невыставленым ТР , спасибо за содействие Neame // 1.44: исправлен баг, присутствующий в версии 1.43 (не работал один из иланов при включеном ММ) #property copyright "Night" #property link "http://alfonius@yandex.ru" #property indicator_buffers 1 #property indicator_color1 Red #import "kernel32.dll" void GetLocalTime(int& a0[]); int GetTimeZoneInformation(int& a0[]); #import //=================================================================== //------------------Общие настройки--------------------------------// //=================================================================== extern string t1 = "Общие настройки"; extern double Lots = 0.01; // теперь можно и микролоты 0.01 при этом если стоит 0.1 то следующий лот в серии будет 0.16 extern double LotExponent = 1.95; // умножение лотов в серии по експоненте для вывода в безубыток. первый лот 0.1, серия: 0.15, 0.26, 0.43 ... extern int lotdecimal = 2; // 2 - микролоты 0.01, 1 - мини лоты 0.1, 0 - нормальные лоты 1.0 extern double PipStep_ = 30.0; // шаг колена extern double TakeProfit_ = 10.0; // тейк профит double PipStep; double TakeProfit; extern bool Turbo = true; // Турбо-режим :) extern bool NewCycle = true; // Режим отмены выставления новых ордеров extern int PeriodRSI = 2; // 1=M1, 2=M5, 3=M15, 4=M30, 5=H1, 6=H4, 7=D1, 8=W1, 9=MN1, 0=текущий график int PerRSI; // Период RSI double MaxLots = 10; // ограничение макс лота extern bool MM =FALSE; // ММ - манименеджмент bool UseEquityStop = FALSE; // использовать риск в процентах double TotalEquityRisk = 20.0; // риск в процентах от депозита bool UseTrailingStop = FALSE; // использовать трейлинг стоп double TrailStart_ = 13.0; // трейлингстарт double TrailStop_ = 3.0; //трейлингстоп double TrailStart; // трейлингстарт double TrailStop; //трейлингстоп double slip = 5.0; // проскальзывание extern bool UseMACD_or_OsMA = 1 ; extern int emaFast = 12; // parameters for MACD and OSMA extern int emaSlow = 26; // parameters for MACD and OSMA extern int signalPeriod = 9; // parameters for MACD and OSMA extern int timeFrame = 0; // parameters for MACD and OSMA //==================================================== //==================================================== //extern string t2 = "работа советника в пятницу- до и в понедельник- после"; //extern bool CloseFriday=true; // использовать ограничение по времени в пятницу true, не использовать false //extern int CloseFridayHour=17; // время в пятницу после которого не выставляется первый ордер //extern bool OpenMondey=true; // использовать ограничение по времени в пятницу true, не использовать false //extern int OpenMondeyHour=10; // время в пятницу после которого не выставляется первый ордер //===================================================== //===================================================== //=================================================================== //=================================================================== //-------------------Hilo_RSI--------------------------------------// //=================================================================== extern string t3 = "Настройки эксперта Ilan_Hilo"; double Lots_Hilo; // задание всех лотов через 1 переменную double LotExponent_Hilo; int lotdecimal_Hilo, ord_Hilo; double TakeProfit_Hilo; // тейк профит extern int MaxTrades_Hilo = 10; // максимально количество одновременно открытых ордеров bool UseEquityStop_Hilo; // использовать риск в процентах double TotalEquityRisk_Hilo; // риск в процентах от депозита //===================================================== bool UseTimeOut_Hilo = FALSE; // использовать анулирование ордеров по времени double MaxTradeOpenHours_Hilo = 48.0; // через колько часов анулировать висячие ордера //===================================================== bool UseTrailingStop_Hilo; // использовать трейлинг стоп double Stoploss_Hilo = 500.0; // Эти параметра работают!!! double TrailStart_Hilo; double TrailStop_Hilo; //===================================================== double PipStep_Hilo; // шаг колена- был 30 double slip_Hilo; // проскальзывание extern int MagicNumber_Hilo = 11111; // магик //===================================================== double PriceTarget_Hilo, StartEquity_Hilo, BuyTarget_Hilo, SellTarget_Hilo, Balans, Sredstva ; double AveragePrice_Hilo, SellLimit_Hilo, BuyLimit_Hilo ; double LastBuyPrice_Hilo, LastSellPrice_Hilo, Spread_Hilo; bool flag_Hilo; string EAName_Hilo = "Ilan_HiLo_RSI"; int timeprev_Hilo = 0, expiration_Hilo; int NumOfTrades_Hilo = 0; double iLots_Hilo; int cnt_Hilo = 0, total_Hilo; double Stopper_Hilo = 0.0; bool TradeNow_Hilo = FALSE, LongTrade_Hilo = FALSE, ShortTrade_Hilo = FALSE; int ticket_Hilo; bool NewOrdersPlaced_Hilo = FALSE; double AccountEquityHighAmt_Hilo, PrevEquity_Hilo; //============================== //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ILAN 1.5 // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ extern string t4 = "Настройки эксперта Ilan 1.5"; double LotExponent_15; double Lots_15; int lotdecimal_15, ord_15; double TakeProfit_15; bool UseEquityStop_15; // использовать риск в процентах double TotalEquityRisk_15; // риск в процентах от депозита extern int MaxTrades_15 = 10; int OpenNewTF_15 = 1; int gi_unused_88_15; //============================================== bool UseTrailingStop_15; // использовать трейлинг стоп double Stoploss_15 = 500.0; // Эти параметры не работают!!! double TrailStart_15; double TrailStop_15; //============================================== bool UseTimeOut_15 = FALSE; // использовать анулирование ордеров по времени double MaxTradeOpenHours_15 = 48.0; // через колько часов анулировать висячие ордера //=============================================== double PipStep_15; //30 double slip_15; extern int g_magic_176_15 = 12324; //=============================================== double g_price_180_15; double gd_188_15; double gd_unused_196_15; double gd_unused_204_15; double g_price_212_15; double g_bid_220_15; double g_ask_228_15; double gd_236_15; double gd_244_15; double gd_260_15; bool gi_268_15; string gs_ilan_272_15 = "Ilan 1.5"; int gi_280_15 = 0; int gi_284_15; int gi_288_15 = 0; double gd_292_15; int g_pos_300_15 = 0; int gi_304_15; double gd_308_15 = 0.0; bool gi_316_15 = FALSE; bool gi_320_15 = FALSE; bool gi_324_15 = FALSE; int gi_328_15; bool gi_332_15 = FALSE; double gd_336_15; double gd_344_15; datetime time_15=1; //======================================================================== // ILAN 1.6 // //======================================================================== extern string t5 = "Настройки эксперта Ilan 1.6"; double LotExponent_16; double Lots_16; int lotdecimal_16, ord_16; double TakeProfit_16; extern int MaxTrades_16 = 10; bool UseEquityStop_16; // использовать риск в процентах double TotalEquityRisk_16; // риск в процентах от депозита int OpenNewTF_16 = 1; //========================================================= bool UseTrailingStop_16; double Stoploss_16 = 500.0; // Эти три параметра не работают!!! double TrailStart_16; double TrailStop_16; //========================================================= bool UseTimeOut_16 = FALSE; double MaxTradeOpenHours_16 = 48.0; //========================================================= double PipStep_16;//30 double slip_16; extern int g_magic_176_16 = 16794; //========================================================= double g_price_180_16; double gd_188_16; double gd_unused_196_16; double gd_unused_204_16; double g_price_212_16; double g_bid_220_16; double g_ask_228_16; double gd_236_16; double gd_244_16; double gd_260_16; bool gi_268_16; string gs_ilan_272_16 = "Ilan 1.6"; int gi_280_16 = 0; int gi_284_16; int gi_288_16 = 0; double gd_292_16; int g_pos_300_16 = 0; int gi_304_16; double gd_308_16 = 0.0; bool gi_316_16 = FALSE; bool gi_320_16 = FALSE; bool gi_324_16 = FALSE; int gi_328_16; bool gi_332_16 = FALSE; double gd_336_16; double gd_344_16; datetime time_16=1; //*****************Time*************** //**** bool ShowLocal = true; int corner = 3; int topOff = 120; color labelColor = DodgerBlue; color clockColor = DodgerBlue; bool show12HourTime = FALSE; int gi_100; double g_ibuf_104[]; int gi_108 = 0; int gi_112 = 9; int gi_116 = -5; //***** //============================== //============================== string txt,txt1; string txt2=""; string txt3=""; color col = ForestGreen; //============================== int init() {int x; if (Digits==5 || Digits == 3)x=10; else x=1; TrailStart=TrailStart_*x; // трейлингстарт TrailStop=TrailStop_*x; //трейлингстоп PipStep=PipStep_*x; TakeProfit=TakeProfit_*x; //======================= Spread_Hilo = MarketInfo(Symbol(), MODE_SPREAD) * Point; gd_260_15 = MarketInfo(Symbol(), MODE_SPREAD) * Point; gd_260_16 = MarketInfo(Symbol(), MODE_SPREAD) * Point; //------------------------ /* ObjectCreate("Lable1",OBJ_LABEL,0,0,1.0); ObjectSet("Lable1", OBJPROP_CORNER, 2); ObjectSet("Lable1", OBJPROP_XDISTANCE, 23); ObjectSet("Lable1", OBJPROP_YDISTANCE, 21); txt1="Ilan-Trio 1.47T"; ObjectSetText("Lable1",txt1,16,"Times New Roman",Aqua); */ //------------------------- ObjectCreate("Lable",OBJ_LABEL,0,0,1.0); ObjectSet("Lable", OBJPROP_CORNER, 2); ObjectSet("Lable", OBJPROP_XDISTANCE, 3); ObjectSet("Lable", OBJPROP_YDISTANCE, 11); txt="Ilan-Trio 1.48T "+CharToStr(174)+" "/*" alfonius@yandex.ru"*/; ObjectSetText("Lable",txt,16,"Times New Roman",DodgerBlue); //------------------------- //++++++++время { SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, g_ibuf_104); int li_0 = topOff; int li_4 = 60; if (show12HourTime) li_4 = 102; if (ShowLocal) { ObjectMakeLabel("locl", li_4, li_0); ObjectMakeLabel("loct", 15, li_0); } ObjectMakeLabel("gmtl", li_4, li_0 - 15); ObjectMakeLabel("gmtt", 15, li_0 - 15); ObjectMakeLabel("nyl", li_4, li_0 - 30); ObjectMakeLabel("nyt", 15, li_0 - 30); ObjectMakeLabel("lonl", li_4, li_0 - 45); ObjectMakeLabel("lont", 15, li_0 - 45); ObjectMakeLabel("tokl", li_4, li_0 - 60); ObjectMakeLabel("tokt", 15, li_0 - 60); ObjectMakeLabel("brol", li_4, li_0 - 75); ObjectMakeLabel("brot", 15, li_0 - 75); ObjectMakeLabel("barl", li_4, li_0 - 90); ObjectMakeLabel("bart", 15, li_0 - 90); ObjectMakeLabel("Spread Monitor1", li_4, li_0 - 105); ObjectMakeLabel("Spread Monitor2", 40, li_0 - 105); return (0); } //++++++++++ return (0); } int deinit() { { //****время { ObjectDelete("locl"); ObjectDelete("loct"); ObjectDelete("nyl"); ObjectDelete("nyt"); ObjectDelete("gmtl"); ObjectDelete("gmtt"); ObjectDelete("lonl"); ObjectDelete("lont"); ObjectDelete("tokl"); ObjectDelete("tokt"); ObjectDelete("brol"); ObjectDelete("brot"); ObjectDelete("barl"); ObjectDelete("bart"); ObjectDelete("Spread Monitor1"); ObjectDelete("Spread Monitor2"); } //**** { //---- ObjectDelete("Lable"); ObjectDelete("Lable1"); ObjectDelete("Lable2"); ObjectDelete("Lable3"); //---- } } return (0); } //======================================================================== //======================================================================== int start() { if ( UseMACD_or_OsMA==1 ) { double Trigger0=iMACD(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,MODE_MAIN,0); double Trigger1=iMACD(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,MODE_MAIN,1); double Trigger2=iMACD(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,MODE_MAIN,2); } if ( UseMACD_or_OsMA==2 ) { Trigger0=iOsMA(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,0); Trigger1=iOsMA(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,1); Trigger2=iOsMA(NULL,timeFrame,emaFast,emaSlow,signalPeriod,PRICE_CLOSE,2); } int counted_bars=IndicatorCounted(); if (Lots > MaxLots) Lots = MaxLots; //ограничение лотов { Comment("" + "\n" + "Ilan-Trio V 1.48T" //+ "\n" //+ "________________________________" //+ "\n" //+ "Брокер: " + AccountCompany() + "\n" + "Время брокера: " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + "\n" + "________________________________" //+ "\n" //+ "Счёт: " + AccountName() //+ "\n" //+ "Номер счёт " + AccountNumber() //+ "\n" //+ "Валюта счёта: " + AccountCurrency() //+ "\n" //+ "_______________________________" + "\n" + "Открыто ордеров Ilan_Hilo:" + CountTrades_Hilo() + "\n" + "Открыто ордеров Ilan_1.5 :" + CountTrades_15() + "\n" + "Открыто ордеров Ilan_1.6 :" + CountTrades_16() + "\n" + "Всего ордеров :" + OrdersTotal() + "\n" + "_______________________________" + "\n" + "Баланс: " + DoubleToStr(AccountBalance(), 2) + "\n" + "Свободные средства: " + DoubleToStr(AccountEquity(), 2) + "\n" + "_______________________________"); } //************* //================= if (PeriodRSI == 1) PerRSI =PERIOD_M1; if (PeriodRSI == 2) PerRSI =PERIOD_M5; if (PeriodRSI == 3) PerRSI =PERIOD_M15; if (PeriodRSI == 4) PerRSI =PERIOD_M30; if (PeriodRSI == 5) PerRSI =PERIOD_H1; if (PeriodRSI == 6) PerRSI =PERIOD_H4; if (PeriodRSI == 7) PerRSI =PERIOD_D1; if (PeriodRSI == 8) PerRSI =PERIOD_W1; if (PeriodRSI == 9) PerRSI =PERIOD_MN1; if (PeriodRSI == 0) PerRSI =Period(); //================= //================= //ForestGreen' YellowGreen' Yellow' OrangeRed' Red Balans = NormalizeDouble( AccountBalance(),2); Sredstva = NormalizeDouble(AccountEquity(),2); if (Sredstva >= Balans/6*5) col = DodgerBlue; if (Sredstva >= Balans/6*4 && Sredstva < Balans/6*5)col = DeepSkyBlue; if (Sredstva >= Balans/6*3 && Sredstva < Balans/6*4)col = Gold; if (Sredstva >= Balans/6*2 && Sredstva < Balans/6*3)col = OrangeRed; if (Sredstva >= Balans/6 && Sredstva < Balans/6*2)col = Crimson; if (Sredstva < Balans/5 )col = Red; //------------------------- { ObjectDelete("Lable2"); ObjectCreate("Lable2",OBJ_LABEL,0,0,1.0); ObjectSet("Lable2", OBJPROP_CORNER, 3); ObjectSet("Lable2", OBJPROP_XDISTANCE, 153); ObjectSet("Lable2", OBJPROP_YDISTANCE, 31); txt2=(DoubleToStr(AccountBalance(), 2)); ObjectSetText("Lable2","БАЛАНС "+txt2+"",14,"Times New Roman",DodgerBlue); //------------------------- ObjectDelete("Lable3"); ObjectCreate("Lable3",OBJ_LABEL,0,0,1.0); ObjectSet("Lable3", OBJPROP_CORNER, 3); ObjectSet("Lable3", OBJPROP_XDISTANCE, 153); ObjectSet("Lable3", OBJPROP_YDISTANCE, 11); txt3=(DoubleToStr(AccountEquity(), 2)); ObjectSetText("Lable3","СРЕДСТВА "+txt3+"",14,"Times New Roman",col); //------------------------- } {//*****время int lia_16[4]; int lia_20[43]; string ls_unused_52; string ls_0 = "2115.11.01"; int l_str2time_8 = StrToTime(ls_0); /*if (TimeCurrent() >= l_str2time_8) { Alert(" Trial version has expired! Email support@forexprofitmonster.com with broker account number for rights to full version!"); return (0); }*/ /*if (!IsDllsAllowed()) { Alert("FPM Clock: DLLs are disabled. To enable tick the checkbox in the Common Tab of indicator"); return; }*/ int li_unused_12 = IndicatorCounted(); GetLocalTime(lia_16); int li_24 = lia_16[0] & 65535; int li_28 = lia_16[0] >> 16; int li_32 = lia_16[1] >> 16; int li_36 = lia_16[2] & 65535; int li_40 = lia_16[2] >> 16; int li_44 = lia_16[3] & 65535; int li_48 = lia_16[3] >> 16; string ls_60 = FormatDateTime(li_24, li_28, li_32, li_36, li_40, li_44); int l_str2time_68 = StrToTime(ls_60); gi_108 = GMT_Offset("LONDON", l_str2time_68); gi_112 = GMT_Offset("TOKYO", l_str2time_68); gi_116 = GMT_Offset("US", l_str2time_68); int li_72 = 0; int li_76 = GetTimeZoneInformation(lia_20); if (li_76 != 0) li_72 = lia_20[0]; if (li_76 == 2) li_72 += lia_20[42]; int li_unused_80 = TimeCurrent(); int li_84 = l_str2time_68 + 60 * li_72; int li_88 = li_84 + 3600 * gi_108; int li_92 = li_84 + 3600 * gi_112; int li_96 = li_84 + 3600 * gi_116; string l_text_100 = TimeToString(li_84); string l_text_108 = TimeToString(l_str2time_68); string l_text_116 = TimeToString(li_88); string l_text_124 = TimeToString(li_92); string l_text_132 = TimeToString(li_96); string l_text_140 = TimeToString(TimeCurrent()); string l_time2str_148 = TimeToStr(TimeCurrent() - Time[0], TIME_MINUTES); if (ShowLocal) { ObjectSetText("locl", "Local:", 10, "Arial", labelColor); ObjectSetText("loct", l_text_108, 10, "Arial", clockColor); } ObjectSetText("gmtl", "GMT:", 10, "Arial", labelColor); ObjectSetText("gmtt", l_text_100, 10, "Arial", clockColor); ObjectSetText("nyl", "New York:", 10, "Arial", labelColor); ObjectSetText("nyt", l_text_132, 10, "Arial", clockColor); ObjectSetText("lonl", "London:", 10, "Arial", labelColor); ObjectSetText("lont", l_text_116, 10, "Arial", clockColor); ObjectSetText("tokl", "Tokyo:", 10, "Arial", labelColor); ObjectSetText("tokt", l_text_124, 10, "Arial", clockColor); ObjectSetText("brol", "Broker:", 10, "Arial", labelColor); ObjectSetText("brot", l_text_140, 10, "Arial", clockColor); ObjectSetText("barl", "Bar:", 10, "Arial", labelColor); ObjectSetText("bart", l_time2str_148, 10, "Arial", clockColor); gi_100 = NormalizeDouble((Ask - Bid) / Point, 0); ObjectSetText("Spread Monitor1", "Spread:", 10, "Arial", labelColor); ObjectSetText("Spread Monitor2", DoubleToStr(gi_100, 0), 10, "Arial", clockColor); //return (0); }//******** //================== //================== { //=======================================================================// // Программный код Ilan_Hilo_RSI // //=======================================================================// {double PrevCl_Hilo; //переменная Hilo double CurrCl_Hilo; //переменная Hilo double l_iclose_8; //переменная Ilan_1.5 double l_iclose_16; //переменная Ilan_1.6 //======================= double LotExponent_Hilo = LotExponent; int lotdecimal_Hilo = lotdecimal; double TakeProfit_Hilo = TakeProfit; bool UseEquityStop_Hilo = UseEquityStop; double TotalEquityRisk_Hilo = TotalEquityRisk; // риск в процентах от депозита bool UseTrailingStop_Hilo = UseTrailingStop; double TrailStart_Hilo = TrailStart; double TrailStop_Hilo = TrailStop; //double PipStep_Hilo = PipStep;//30 double slip_Hilo = slip; // проскальзывание //========= ord_Hilo = CountTrades_Hilo(); if (Turbo) { if (ord_Hilo == 1) PipStep_Hilo = PipStep/3; if (ord_Hilo == 2) PipStep_Hilo = PipStep/3*2; if (ord_Hilo >= 3) PipStep_Hilo = PipStep; } else PipStep_Hilo = PipStep; //========= //======================= if(MM==true) {if (MathCeil(AccountBalance ()) < 2000) // MM = если депо меньше 2000, то лот = Lots (0.01), иначе- % от депо { double Lots_Hilo = Lots; } else {Lots_Hilo = 0.00001 * MathCeil(AccountBalance ()); } } else Lots_Hilo = Lots; if (UseTrailingStop_Hilo) TrailingAlls_Hilo(TrailStart_Hilo, TrailStop_Hilo, AveragePrice_Hilo); if (UseTimeOut_Hilo) { if (TimeCurrent() >= expiration_Hilo) { CloseThisSymbolAll_Hilo(); Print("Closed All due_Hilo to TimeOut"); } } if (timeprev_Hilo == Time[0]) return (0); timeprev_Hilo = Time[0]; double CurrentPairProfit_Hilo = CalculateProfit_Hilo(); if (UseEquityStop_Hilo) { if (CurrentPairProfit_Hilo < 0.0 && MathAbs(CurrentPairProfit_Hilo) > TotalEquityRisk_Hilo / 100.0 * AccountEquityHigh_Hilo()) { CloseThisSymbolAll_Hilo(); Print("Closed All due_Hilo to Stop Out"); NewOrdersPlaced_Hilo = FALSE; } } total_Hilo = CountTrades_Hilo(); if (total_Hilo == 0) flag_Hilo = FALSE; for (cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_BUY) { LongTrade_Hilo = TRUE; ShortTrade_Hilo = FALSE; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_SELL) { LongTrade_Hilo = FALSE; ShortTrade_Hilo = TRUE; break; } } } if (total_Hilo > 0 && total_Hilo <= MaxTrades_Hilo) { RefreshRates(); LastBuyPrice_Hilo = FindLastBuyPrice_Hilo(); LastSellPrice_Hilo = FindLastSellPrice_Hilo(); if (LongTrade_Hilo && LastBuyPrice_Hilo - Ask >= PipStep_Hilo * Point) TradeNow_Hilo = TRUE; if (ShortTrade_Hilo && Bid - LastSellPrice_Hilo >= PipStep_Hilo * Point) TradeNow_Hilo = TRUE; } if (total_Hilo < 1) { ShortTrade_Hilo = FALSE; LongTrade_Hilo = FALSE; TradeNow_Hilo = TRUE; StartEquity_Hilo = AccountEquity(); } if (TradeNow_Hilo) { LastBuyPrice_Hilo = FindLastBuyPrice_Hilo(); LastSellPrice_Hilo = FindLastSellPrice_Hilo(); if (ShortTrade_Hilo) { NumOfTrades_Hilo = total_Hilo; iLots_Hilo = NormalizeDouble(Lots_Hilo * MathPow(LotExponent_Hilo, NumOfTrades_Hilo), lotdecimal_Hilo); RefreshRates(); ticket_Hilo = OpenPendingOrder_Hilo(1, iLots_Hilo, NormalizeDouble(Bid,Digits), slip_Hilo, NormalizeDouble(Ask,Digits), 0, 0, EAName_Hilo + "-" + NumOfTrades_Hilo, MagicNumber_Hilo, 0, HotPink); if (ticket_Hilo < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice_Hilo = FindLastSellPrice_Hilo(); TradeNow_Hilo = FALSE; NewOrdersPlaced_Hilo = TRUE; } else { if (LongTrade_Hilo) { NumOfTrades_Hilo = total_Hilo; iLots_Hilo = NormalizeDouble(Lots_Hilo * MathPow(LotExponent_Hilo, NumOfTrades_Hilo), lotdecimal_Hilo); ticket_Hilo = OpenPendingOrder_Hilo(0, iLots_Hilo, NormalizeDouble(Ask,Digits), slip_Hilo, NormalizeDouble(Bid,Digits), 0, 0, EAName_Hilo + "-" + NumOfTrades_Hilo, MagicNumber_Hilo, 0, Lime); if (ticket_Hilo < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice_Hilo = FindLastBuyPrice_Hilo(); TradeNow_Hilo = FALSE; NewOrdersPlaced_Hilo = TRUE; } } } if (TradeNow_Hilo && total_Hilo < 1) { PrevCl_Hilo = iHigh(Symbol(), 0, 1); CurrCl_Hilo = iLow(Symbol(), 0, 2); SellLimit_Hilo = NormalizeDouble(Bid,Digits); BuyLimit_Hilo = NormalizeDouble(Ask,Digits); if (!ShortTrade_Hilo && !LongTrade_Hilo) { NumOfTrades_Hilo = total_Hilo; iLots_Hilo = NormalizeDouble(Lots_Hilo * MathPow(LotExponent_Hilo, NumOfTrades_Hilo), lotdecimal_Hilo); //=============ограничения на работу утром понедельника и вечер пятницы========================// //if( // (CloseFriday==true&&DayOfWeek()==5&&TimeCurrent()>=StrToTime(CloseFridayHour+":00")) // ||(OpenMondey ==true&&DayOfWeek()==1&&TimeCurrent()<=StrToTime(OpenMondeyHour +":00")) // ) return(0); //=============================================================================================// if (NewCycle) { if (PrevCl_Hilo > CurrCl_Hilo) { //HHHHHHHH~~~~~~~~~~~~~ Индюк RSI ~~~~~~~~~~HHHHHHHHH~~~~~~~~~~~~~~~// if (iRSI(NULL, PerRSI, 14, PRICE_CLOSE, 1) > 30.0 || (Trigger0<0) && (Trigger1<0) && (Trigger2>0)) { ticket_Hilo = OpenPendingOrder_Hilo(1, iLots_Hilo, SellLimit_Hilo, slip_Hilo, SellLimit_Hilo, 0, 0, EAName_Hilo + "-" + NumOfTrades_Hilo, MagicNumber_Hilo, 0, HotPink); if (ticket_Hilo < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice_Hilo = FindLastBuyPrice_Hilo(); NewOrdersPlaced_Hilo = TRUE; } } else { //HHHHHHHH~~~~~~~~~~~~~ Индюк RSI ~~~~~~~~~HHHHHHHHHH~~~~~~~~~~~~~~~~~ if (iRSI(NULL, PerRSI, 14, PRICE_CLOSE, 1) < 70.0 || (Trigger0 > 0) && (Trigger1 > 0) && (Trigger2 < 0 )) { ticket_Hilo = OpenPendingOrder_Hilo(0, iLots_Hilo, BuyLimit_Hilo, slip_Hilo, BuyLimit_Hilo, 0, 0, EAName_Hilo + "-" + NumOfTrades_Hilo, MagicNumber_Hilo, 0, Lime); if (ticket_Hilo < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice_Hilo = FindLastSellPrice_Hilo(); NewOrdersPlaced_Hilo = TRUE; } } } //===================================================== if (ticket_Hilo > 0) expiration_Hilo = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours_Hilo); TradeNow_Hilo = FALSE; } } total_Hilo = CountTrades_Hilo(); AveragePrice_Hilo = 0; double Count_Hilo = 0; for (cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { AveragePrice_Hilo += OrderOpenPrice() * OrderLots(); Count_Hilo += OrderLots(); } } } if (total_Hilo > 0) AveragePrice_Hilo = NormalizeDouble(AveragePrice_Hilo / Count_Hilo, Digits); if (NewOrdersPlaced_Hilo) { for (cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_BUY) { PriceTarget_Hilo = AveragePrice_Hilo + TakeProfit_Hilo * Point; BuyTarget_Hilo = PriceTarget_Hilo; Stopper_Hilo = AveragePrice_Hilo - Stoploss_Hilo * Point; flag_Hilo = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_SELL) { PriceTarget_Hilo = AveragePrice_Hilo - TakeProfit_Hilo * Point; SellTarget_Hilo = PriceTarget_Hilo; Stopper_Hilo = AveragePrice_Hilo + Stoploss_Hilo * Point; flag_Hilo = TRUE; } } } } if (NewOrdersPlaced_Hilo) { if (flag_Hilo == TRUE) { for (cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo)// OrderModify(OrderTicket(), AveragePrice_Hilo, OrderStopLoss(), PriceTarget_Hilo, 0, Yellow); //=== while(!OrderModify(OrderTicket(), AveragePrice_Hilo, OrderStopLoss(), PriceTarget_Hilo, 0, Yellow))// модифицируем все открытые ордера... {Sleep(1000);RefreshRates();} //..причём здесь добавлена проверка, котрая должна по идее исключить невыставление ТР //=== NewOrdersPlaced_Hilo = FALSE; } } } //========================================================================// // ПРОГРАМНЫЙ КОД Ilan 1.5 // //========================================================================// //double l_iclose_8; //double l_iclose_16; //======================= double LotExponent_15 = LotExponent; int lotdecimal_15 = lotdecimal; double TakeProfit_15 = TakeProfit; bool UseEquityStop_15 = UseEquityStop; double TotalEquityRisk_15 = TotalEquityRisk;// риск в процентах от депозита bool UseTrailingStop_15 = UseTrailingStop; double TrailStart_15 = TrailStart; double TrailStop_15 = TrailStop; //double PipStep_15 = PipStep;//30 double slip_15 = slip; // проскальзывание //========= ord_15 = CountTrades_15(); if (Turbo) { if (ord_15 == 1) PipStep_15 = PipStep/3; if (ord_15 == 2) PipStep_15 = PipStep/3*2; if (ord_15 >= 3) PipStep_15 = PipStep; } else PipStep_15 = PipStep; //========= //======================= if(MM==true) {if (MathCeil(AccountBalance ()) < 2000) // MM = если депо меньше 2000, то лот = Lots (0.01), иначе- % от депо { double Lots_15 = Lots; } else {Lots_15 = 0.00001 * MathCeil(AccountBalance ()); } } else Lots_15 = Lots; //======================= //=============ограничения на работу утром понедельника и вечер пятницы========================// //if( // (CloseFriday==true&&DayOfWeek()==5&&TimeCurrent()>=StrToTime(CloseFridayHour+":00")) // ||(OpenMondey ==true&&DayOfWeek()==1&&TimeCurrent()<=StrToTime(OpenMondeyHour +":00")) // ) return(0); //=============================================================================================// if (UseTrailingStop_15) TrailingAlls_15(TrailStart_15, TrailStop_15, g_price_212_15); if (UseTimeOut_15) { if (TimeCurrent() >= gi_284_15) { CloseThisSymbolAll_15(); Print("Closed All due to TimeOut"); } } if (gi_280_15 != Time[0]) { gi_280_15 = Time[0]; double ld_0_15 = CalculateProfit_15(); if (UseEquityStop_15) { if (ld_0_15 < 0.0 && MathAbs(ld_0_15) > TotalEquityRisk_15 / 100.0 * AccountEquityHigh_15()) { CloseThisSymbolAll_15(); Print("Closed All due to Stop Out"); gi_332_15 = FALSE; } } gi_304_15 = CountTrades_15(); if (gi_304_15 == 0) gi_268_15 = FALSE; for (g_pos_300_15 = OrdersTotal() - 1; g_pos_300_15 >= 0; g_pos_300_15--) { OrderSelect(g_pos_300_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_BUY) { gi_320_15 = TRUE; gi_324_15 = FALSE; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_SELL) { gi_320_15 = FALSE; gi_324_15 = TRUE; break; } } } if (gi_304_15 > 0 && gi_304_15 <= MaxTrades_15) { RefreshRates(); gd_236_15 = FindLastBuyPrice_15(); gd_244_15 = FindLastSellPrice_15(); if (gi_320_15 && gd_236_15 - Ask >= PipStep_15 * Point) gi_316_15 = TRUE; if (gi_324_15 && Bid - gd_244_15 >= PipStep_15 * Point) gi_316_15 = TRUE; } if (gi_304_15 < 1) { gi_324_15 = FALSE; gi_320_15 = FALSE; gi_316_15 = TRUE; gd_188_15 = AccountEquity(); } if (gi_316_15) { gd_236_15 = FindLastBuyPrice_15(); gd_244_15 = FindLastSellPrice_15(); if (gi_324_15) { gi_288_15 = gi_304_15; gd_292_15 = NormalizeDouble(Lots_15 * MathPow(LotExponent_15, gi_288_15), lotdecimal_15); RefreshRates(); gi_328_15 = OpenPendingOrder_15(1, gd_292_15, NormalizeDouble(Bid,Digits), slip_15, NormalizeDouble(Ask,Digits), 0, 0, gs_ilan_272_15 + "-" + gi_288_15, g_magic_176_15, 0, HotPink); if (gi_328_15 < 0) { Print("Error: ", GetLastError()); return (0); } gd_244_15 = FindLastSellPrice_15(); gi_316_15 = FALSE; gi_332_15 = TRUE; } else { if (gi_320_15) { gi_288_15 = gi_304_15; gd_292_15 = NormalizeDouble(Lots_15 * MathPow(LotExponent_15, gi_288_15), lotdecimal_15); gi_328_15 = OpenPendingOrder_15(0, gd_292_15, NormalizeDouble(Ask,Digits), slip_15, NormalizeDouble(Bid,Digits), 0, 0, gs_ilan_272_15 + "-" + gi_288_15, g_magic_176_15, 0, Lime); if (gi_328_15 < 0) { Print("Error: ", GetLastError()); return (0); } gd_236_15 = FindLastBuyPrice_15(); gi_316_15 = FALSE; gi_332_15 = TRUE; } } } } if(time_15!=iTime(NULL,OpenNewTF_15,0)) { int totals_15=OrdersTotal(); int orders_15=0; for(int total_15=totals_15; total_15>=1; total_15--) { OrderSelect(total_15-1,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { orders_15++; } } if (totals_15==0 || orders_15 < 1) { l_iclose_8 = iClose(Symbol(), 0, 2); l_iclose_16 = iClose(Symbol(), 0, 1); g_bid_220_15 = NormalizeDouble(Bid,Digits); g_ask_228_15 = NormalizeDouble(Ask,Digits); if (!gi_324_15 && !gi_320_15) { gi_288_15 = gi_304_15; gd_292_15 = NormalizeDouble(Lots_15 * MathPow(LotExponent, gi_288_15), lotdecimal_15); if (l_iclose_8 > l_iclose_16) { if (NewCycle || Trigger0<0 && Trigger1<0 && Trigger2>0) {//!!! gi_328_15 = OpenPendingOrder_15(1, gd_292_15, g_bid_220_15, slip_15, g_bid_220_15, 0, 0, gs_ilan_272_15 + "-" + gi_288_15, g_magic_176_15, 0, HotPink); if (gi_328_15 < 0) { Print("Error: ", GetLastError()); return (0); } gd_236_15 = FindLastBuyPrice_15(); gi_332_15 = TRUE;} } }else { if (NewCycle || Trigger0 > 0 && Trigger1 > 0 && Trigger2 < 0 ) {//!!! gi_328_15 = OpenPendingOrder_15(0, gd_292_15, g_ask_228_15, slip_15, g_ask_228_15, 0, 0, gs_ilan_272_15 + "-" + gi_288_15, g_magic_176_15, 0, Lime); if (gi_328_15 < 0) { Print("Error: ", GetLastError()); return (0); } gd_244_15 = FindLastSellPrice_15(); gi_332_15 = TRUE; } }//!!! if (gi_328_15 > 0) gi_284_15 = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours_15); gi_316_15 = FALSE; // } } time_15=iTime(NULL,OpenNewTF_15,0); } gi_304_15 = CountTrades_15(); g_price_212_15 = 0; double ld_24_15 = 0; for (g_pos_300_15 = OrdersTotal() - 1; g_pos_300_15 >= 0; g_pos_300_15--) { OrderSelect(g_pos_300_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { g_price_212_15 += OrderOpenPrice() * OrderLots(); ld_24_15 += OrderLots(); } } } if (gi_304_15 > 0) g_price_212_15 = NormalizeDouble(g_price_212_15 / ld_24_15, Digits); if (gi_332_15) { for (g_pos_300_15 = OrdersTotal() - 1; g_pos_300_15 >= 0; g_pos_300_15--) { OrderSelect(g_pos_300_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_BUY) { g_price_180_15 = g_price_212_15 + TakeProfit_15 * Point; gd_unused_196_15 = g_price_180_15; gd_308_15 = g_price_212_15 - Stoploss_15 * Point; gi_268_15 = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_SELL) { g_price_180_15 = g_price_212_15 - TakeProfit_15 * Point; gd_unused_204_15 = g_price_180_15; gd_308_15 = g_price_212_15 + Stoploss_15 * Point; gi_268_15 = TRUE; } } } } if (gi_332_15) { if (gi_268_15 == TRUE) { for (g_pos_300_15 = OrdersTotal() - 1; g_pos_300_15 >= 0; g_pos_300_15--) { OrderSelect(g_pos_300_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) //OrderModify(OrderTicket(), g_price_212_15, OrderStopLoss(), g_price_180_15, 0, Yellow); //=== while(!OrderModify(OrderTicket(), g_price_212_15, OrderStopLoss(), g_price_180_15, 0, Yellow))// модифицируем все открытые ордера... {Sleep(1000);RefreshRates();} //..причём здесь добавлена проверка, котрая должна по идее исключить.. //=== gi_332_15 = FALSE; } } } //========================================================================// // ПРОГРАМНЫЙ КОД Ilan 1.6 // //========================================================================// // double l_iclose_8; // double l_iclose_16; //======================= double LotExponent_16 = LotExponent; int lotdecimal_16 = lotdecimal; double TakeProfit_16 = TakeProfit; bool UseEquityStop_16 = UseEquityStop; double TotalEquityRisk_16 = TotalEquityRisk;// риск в процентах от депозита bool UseTrailingStop_16 = UseTrailingStop; double TrailStart_16 = TrailStart; double TrailStop_16 = TrailStop; //double PipStep_16 = PipStep;//30 double slip_16 = slip; // проскальзывание //========= ord_16 = CountTrades_16(); if (Turbo) { if (ord_16 == 1) PipStep_16 = PipStep/3; if (ord_16 == 2) PipStep_16 = PipStep/3*2; if (ord_16 >= 3) PipStep_16 = PipStep; } else PipStep_16 = PipStep; //========= //======================= // манименеджмент // //======================= if(MM==true) {if (MathCeil(AccountBalance ()) < 2000) // MM = если депо меньше 2000, то лот = Lots (0.01), иначе- % от депо { double Lots_16 = Lots; } else {Lots_16 = 0.00001 * MathCeil(AccountBalance ()); } } else Lots_16 = Lots; //======================= //=============ограничения на работу утром понедельника и вечер пятницы========================// //if( // (CloseFriday==true&&DayOfWeek()==5&&TimeCurrent()>=StrToTime(CloseFridayHour+":00")) // ||(OpenMondey ==true&&DayOfWeek()==1&&TimeCurrent()<=StrToTime(OpenMondeyHour+ ":00")) // ) return(0); //=============================================================================================// if (UseTrailingStop_16) TrailingAlls_16(TrailStart_16, TrailStop_16, g_price_212_16); if (UseTimeOut_16) { if (TimeCurrent() >= gi_284_16) { CloseThisSymbolAll_16(); Print("Closed All due to TimeOut"); } } if (gi_280_16 != Time[0]) { gi_280_16 = Time[0]; double ld_0_16 = CalculateProfit_16(); if (UseEquityStop_16) { if (ld_0_16 < 0.0 && MathAbs(ld_0_16) > TotalEquityRisk_16 / 100.0 * AccountEquityHigh_16()) { CloseThisSymbolAll_16(); Print("Closed All due to Stop Out"); gi_332_16 = FALSE; } } gi_304_16 = CountTrades_16(); if (gi_304_16 == 0) gi_268_16 = FALSE; for (g_pos_300_16 = OrdersTotal() - 1; g_pos_300_16 >= 0; g_pos_300_16--) { OrderSelect(g_pos_300_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_BUY) { gi_320_16 = TRUE; gi_324_16 = FALSE; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_SELL) { gi_320_16 = FALSE; gi_324_16 = TRUE; break; } } } if (gi_304_16 > 0 && gi_304_16 <= MaxTrades_16) { RefreshRates(); gd_236_16 = FindLastBuyPrice_16(); gd_244_16 = FindLastSellPrice_16(); if (gi_320_16 && gd_236_16 - Ask >= PipStep_16 * Point) gi_316_16 = TRUE; if (gi_324_16 && Bid - gd_244_16 >= PipStep_16 * Point) gi_316_16 = TRUE; } if (gi_304_16 < 1) { gi_324_16 = FALSE; gi_320_16 = FALSE; gi_316_16 = TRUE; gd_188_16 = AccountEquity(); } if (gi_316_16) { gd_236_16 = FindLastBuyPrice_16(); gd_244_16 = FindLastSellPrice_16(); if (gi_324_16) { gi_288_16 = gi_304_16; gd_292_16 = NormalizeDouble(Lots_16 * MathPow(LotExponent_16, gi_288_16), lotdecimal_16); RefreshRates(); gi_328_16 = OpenPendingOrder_16(1, gd_292_16, NormalizeDouble(Bid,Digits), slip_16, NormalizeDouble(Ask,Digits), 0, 0, gs_ilan_272_16 + "-" + gi_288_16, g_magic_176_16, 0, HotPink); if (gi_328_16 < 0) { Print("Error: ", GetLastError()); return (0); } gd_244_16 = FindLastSellPrice_16(); gi_316_16 = FALSE; gi_332_16 = TRUE; } else { if (gi_320_16) { gi_288_16 = gi_304_16; gd_292_16 = NormalizeDouble(Lots_16 * MathPow(LotExponent_16, gi_288_16), lotdecimal_16); gi_328_16 = OpenPendingOrder_16(0, gd_292_16, NormalizeDouble(Ask,Digits), slip_16, NormalizeDouble(Bid,Digits), 0, 0, gs_ilan_272_16 + "-" + gi_288_16, g_magic_176_16, 0, Lime); if (gi_328_16 < 0) { Print("Error: ", GetLastError()); return (0); } gd_236_16 = FindLastBuyPrice_16(); gi_316_16 = FALSE; gi_332_16 = TRUE; } } } } if(time_16!=iTime(NULL,OpenNewTF_16,0)) { int totals_16=OrdersTotal(); int orders_16=0; for(int total_16=totals_16; total_16>=1; total_16--) { OrderSelect(total_16-1,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { orders_16++; } } if (totals_16==0 || orders_16 < 1) { l_iclose_8/*_16*/ = iClose(Symbol(), 0, 2); l_iclose_16/*_16*/ = iClose(Symbol(), 0, 1); g_bid_220_16 = NormalizeDouble(Bid,Digits); g_ask_228_16 = NormalizeDouble(Ask,Digits); if (!gi_324_16 && !gi_320_16) { gi_288_16 = gi_304_16; gd_292_16 = NormalizeDouble(Lots_16 * MathPow(LotExponent_16, gi_288_16), lotdecimal_16); if (NewCycle) {//!!! if (l_iclose_8/*_16*/ > l_iclose_16/*_16*/) { if (iRSI(NULL, PerRSI, 14, PRICE_CLOSE, 1) > 30.0 || Trigger0<0 && Trigger1<0 && Trigger2>0) { gi_328_16 = OpenPendingOrder_16(1, gd_292_16, g_bid_220_16, slip_16, g_bid_220_16, 0, 0, gs_ilan_272_16 + "-" + gi_288_16, g_magic_176_16, 0, HotPink); if (gi_328_16 < 0) { Print("Error: ", GetLastError()); return (0); } gd_236_16 = FindLastBuyPrice_16(); gi_332_16 = TRUE; } } else { if (iRSI(NULL, PerRSI, 14, PRICE_CLOSE, 1) < 70.0 || (Trigger0 > 0) && (Trigger1 > 0) && (Trigger2 < 0 )) { gi_328_16 = OpenPendingOrder_16(0, gd_292_16, g_ask_228_16, slip_16, g_ask_228_16, 0, 0, gs_ilan_272_16 + "-" + gi_288_16, g_magic_176_16, 0, Lime); if (gi_328_16 < 0) { Print("Error: ", GetLastError()); return (0); } gd_244_16 = FindLastSellPrice_16(); gi_332_16 = TRUE; } } }//!!! if (gi_328_16 > 0) gi_284_16 = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours_16); gi_316_16 = FALSE; } } time_16=iTime(NULL,OpenNewTF_16,0); } gi_304_16 = CountTrades_16(); g_price_212_16 = 0; double ld_24_16 = 0; for (g_pos_300_16 = OrdersTotal() - 1; g_pos_300_16 >= 0; g_pos_300_16--) { OrderSelect(g_pos_300_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { g_price_212_16 += OrderOpenPrice() * OrderLots(); ld_24_16 += OrderLots(); } } } if (gi_304_16 > 0) g_price_212_16 = NormalizeDouble(g_price_212_16 / ld_24_16, Digits); if (gi_332_16) { for (g_pos_300_16 = OrdersTotal() - 1; g_pos_300_16 >= 0; g_pos_300_16--) { OrderSelect(g_pos_300_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_BUY) { g_price_180_16 = g_price_212_16 + TakeProfit_16 * Point; gd_unused_196_16 = g_price_180_16; gd_308_16 = g_price_212_16 - Stoploss_16 * Point; gi_268_16 = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_SELL) { g_price_180_16 = g_price_212_16 - TakeProfit_16 * Point; gd_unused_204_16 = g_price_180_16; gd_308_16 = g_price_212_16 + Stoploss_16 * Point; gi_268_16 = TRUE; } } } } if (gi_332_16) { if (gi_268_16 == TRUE) { for (g_pos_300_16 = OrdersTotal() - 1; g_pos_300_16 >= 0; g_pos_300_16--) { OrderSelect(g_pos_300_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) //OrderModify(OrderTicket(), g_price_212_16, OrderStopLoss(), g_price_180_16, 0, Yellow); //=== while(!OrderModify(OrderTicket(), g_price_212_16, OrderStopLoss(), g_price_180_16, 0, Yellow))// модифицируем все открытые ордера... {Sleep(1000);RefreshRates();} //..причём здесь добавлена проверка, котрая должна по идее исключить.. //=== gi_332_16 = FALSE; } } } } } //============================= //============================= return (0); } //============================= int CountTrades_Hilo() { int count_Hilo = 0; for (int trade_Hilo = OrdersTotal() - 1; trade_Hilo >= 0; trade_Hilo--) { OrderSelect(trade_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) if (OrderType() == OP_SELL || OrderType() == OP_BUY) count_Hilo++; } return (count_Hilo); } //============================= void CloseThisSymbolAll_Hilo() { for (int trade_Hilo = OrdersTotal() - 1; trade_Hilo >= 0; trade_Hilo--) { OrderSelect(trade_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip_Hilo, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip_Hilo, Red); } Sleep(1000); } } } //============================= int OpenPendingOrder_Hilo(int pType_Hilo, double pLots_Hilo, double pPrice_Hilo, int pSlippage_Hilo, double pr_Hilo, int sl_Hilo, int tp_Hilo, string pComment_Hilo, int pMagic_Hilo, int pDatetime_Hilo, color pColor_Hilo) { int ticket_Hilo = 0; int err_Hilo = 0; int c_Hilo = 0; int NumberOfTries_Hilo = 100; switch (pType_Hilo) { case 0: for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { RefreshRates(); ticket_Hilo = OrderSend(Symbol(), OP_BUY, pLots_Hilo, NormalizeDouble(Ask,Digits), pSlippage_Hilo, NormalizeDouble(StopLong_Hilo(Bid, sl_Hilo),Digits), NormalizeDouble(TakeLong_Hilo(Ask, tp_Hilo),Digits), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); err_Hilo = GetLastError(); if (err_Hilo == 0/* NO_ERROR */) break; if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 1: for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { ticket_Hilo = OrderSend(Symbol(), OP_SELL, pLots_Hilo, NormalizeDouble(Bid,Digits), pSlippage_Hilo, NormalizeDouble(StopShort_Hilo(Ask, sl_Hilo),Digits), NormalizeDouble(TakeShort_Hilo(Bid, tp_Hilo),Digits), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); err_Hilo = GetLastError(); if (err_Hilo == 0/* NO_ERROR */) break; if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; Sleep(5000); } } //case 2: //for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { //ticket_Hilo = OrderSend(Symbol(), OP_BUYLIMIT, pLots_Hilo, pPrice_Hilo, pSlippage_Hilo, StopLong_Hilo(pr_Hilo, sl_Hilo), TakeLong_Hilo(pPrice_Hilo, tp_Hilo), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); //err_Hilo = GetLastError(); //if (err_Hilo == 0/* NO_ERROR */) break; //if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; //Sleep(1000); //} //break; //case 4: //for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { //ticket_Hilo = OrderSend(Symbol(), OP_BUYSTOP, pLots_Hilo, pPrice_Hilo, pSlippage_Hilo, StopLong_Hilo(pr_Hilo, sl_Hilo), TakeLong_Hilo(pPrice_Hilo, tp_Hilo), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); //err_Hilo = GetLastError(); //if (err_Hilo == 0/* NO_ERROR */) break; //if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; //Sleep(5000); //} //break; //case 3: //for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { //ticket_Hilo = OrderSend(Symbol(), OP_SELLLIMIT, pLots_Hilo, pPrice_Hilo, pSlippage_Hilo, StopShort_Hilo(pr_Hilo, sl_Hilo), TakeShort_Hilo(pPrice_Hilo, tp_Hilo), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); //err_Hilo = GetLastError(); //if (err_Hilo == 0/* NO_ERROR */) break; //if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; //Sleep(5000); //} //break; //case 5: //for (c_Hilo = 0; c_Hilo < NumberOfTries_Hilo; c_Hilo++) { //ticket_Hilo = OrderSend(Symbol(), OP_SELLSTOP, pLots_Hilo, pPrice_Hilo, pSlippage_Hilo, StopShort_Hilo(pr_Hilo, sl_Hilo), TakeShort_Hilo(pPrice_Hilo, tp_Hilo), pComment_Hilo, pMagic_Hilo, pDatetime_Hilo, pColor_Hilo); //err_Hilo = GetLastError(); //if (err_Hilo == 0/* NO_ERROR */) break; //if (!(err_Hilo == 4/* SERVER_BUSY */ || err_Hilo == 137/* BROKER_BUSY */ || err_Hilo == 146/* TRADE_CONTEXT_BUSY */ || err_Hilo == 136/* OFF_QUOTES */)) break; //Sleep(5000); //} //break; return (ticket_Hilo); } //============================= double StopLong_Hilo(double price_Hilo, int stop_Hilo) { if (stop_Hilo == 0) return (0); else return (price_Hilo - stop_Hilo * Point); } //============================= double StopShort_Hilo(double price_Hilo, int stop_Hilo) { if (stop_Hilo == 0) return (0); else return (price_Hilo + stop_Hilo * Point); } //============================= double TakeLong_Hilo(double price_Hilo, int stop_Hilo) { if (stop_Hilo == 0) return (0); else return (price_Hilo + stop_Hilo * Point); } //============================= double TakeShort_Hilo(double price_Hilo, int stop_Hilo) { if (stop_Hilo == 0) return (0); else return (price_Hilo - stop_Hilo * Point); } //============================= double CalculateProfit_Hilo() { double Profit_Hilo = 0; for (cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo) if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit_Hilo += OrderProfit(); } return (Profit_Hilo); } //============================= void TrailingAlls_Hilo(int pType_Hilo, int stop_Hilo, double AvgPrice_Hilo) { int profit_Hilo; double stoptrade_Hilo; double stopcal_Hilo; if (stop_Hilo != 0) { for (int trade_Hilo = OrdersTotal() - 1; trade_Hilo >= 0; trade_Hilo--) { if (OrderSelect(trade_Hilo, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber_Hilo) { if (OrderType() == OP_BUY) { profit_Hilo = NormalizeDouble((Bid - AvgPrice_Hilo) / Point, 0); if (profit_Hilo < pType_Hilo) continue; stoptrade_Hilo = OrderStopLoss(); stopcal_Hilo = Bid - stop_Hilo * Point; if (stoptrade_Hilo == 0.0 || (stoptrade_Hilo != 0.0 && stopcal_Hilo > stoptrade_Hilo)) OrderModify(OrderTicket(), AvgPrice_Hilo, stopcal_Hilo, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { profit_Hilo = NormalizeDouble((AvgPrice_Hilo - Ask) / Point, 0); if (profit_Hilo < pType_Hilo) continue; stoptrade_Hilo = OrderStopLoss(); stopcal_Hilo = Ask + stop_Hilo * Point; if (stoptrade_Hilo == 0.0 || (stoptrade_Hilo != 0.0 && stopcal_Hilo < stoptrade_Hilo)) OrderModify(OrderTicket(), AvgPrice_Hilo, stopcal_Hilo, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } //============================= double AccountEquityHigh_Hilo() { if (CountTrades_Hilo() == 0) AccountEquityHighAmt_Hilo = AccountEquity(); if (AccountEquityHighAmt_Hilo < PrevEquity_Hilo) AccountEquityHighAmt_Hilo = PrevEquity_Hilo; else AccountEquityHighAmt_Hilo = AccountEquity(); PrevEquity_Hilo = AccountEquity(); return (AccountEquityHighAmt_Hilo); } //============================= double FindLastBuyPrice_Hilo() { double oldorderopenprice_Hilo; int oldticketnumber_Hilo; double unused_Hilo = 0; int ticketnumber_Hilo = 0; for (int cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo && OrderType() == OP_BUY) { oldticketnumber_Hilo = OrderTicket(); if (oldticketnumber_Hilo > ticketnumber_Hilo) { oldorderopenprice_Hilo = OrderOpenPrice(); unused_Hilo = oldorderopenprice_Hilo; ticketnumber_Hilo = oldticketnumber_Hilo; } } } return (oldorderopenprice_Hilo); } //============================= double FindLastSellPrice_Hilo() { double oldorderopenprice_Hilo; int oldticketnumber_Hilo; double unused_Hilo = 0; int ticketnumber_Hilo = 0; for (int cnt_Hilo = OrdersTotal() - 1; cnt_Hilo >= 0; cnt_Hilo--) { OrderSelect(cnt_Hilo, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_Hilo) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_Hilo && OrderType() == OP_SELL) { oldticketnumber_Hilo = OrderTicket(); if (oldticketnumber_Hilo > ticketnumber_Hilo) { oldorderopenprice_Hilo = OrderOpenPrice(); unused_Hilo = oldorderopenprice_Hilo; ticketnumber_Hilo = oldticketnumber_Hilo; } } } return (oldorderopenprice_Hilo); } //========================================================================== // пользовательские ф-ции 1.5_1.6 // //========================================================================== //========================================================================// //=========================CountTrades_15=================================// //========================================================================// int CountTrades_15() { int l_count_0_15 = 0; for (int l_pos_4_15 = OrdersTotal() - 1; l_pos_4_15 >= 0; l_pos_4_15--) { OrderSelect(l_pos_4_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) if (OrderType() == OP_SELL || OrderType() == OP_BUY) l_count_0_15++; } return (l_count_0_15); } void CloseThisSymbolAll_15() { for (int l_pos_0_15 = OrdersTotal() - 1; l_pos_0_15 >= 0; l_pos_0_15--) { OrderSelect(l_pos_0_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip_15, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip_15, Red); } Sleep(1000); } } } int OpenPendingOrder_15(int ai_0_15, double a_lots_4_15, double a_price_12_15, int a_slippage_20_15, double ad_24_15, int ai_32_15, int ai_36_15, string a_comment_40_15, int a_magic_48_15, int a_datetime_52_15, color a_color_56_15) { int l_ticket_60_15 = 0; int l_error_64_15 = 0; int l_count_68_15 = 0; int li_72_15 = 100; switch (ai_0_15) { case 0: for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { RefreshRates(); l_ticket_60_15 = OrderSend(Symbol(), OP_BUY, a_lots_4_15, NormalizeDouble(Ask,Digits), a_slippage_20_15, NormalizeDouble(StopLong_15(Bid, ai_32_15),Digits), NormalizeDouble(TakeLong_15(Ask, ai_36_15),Digits), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); l_error_64_15 = GetLastError(); if (l_error_64_15 == 0/* NO_ERROR */) break; if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 1: for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { l_ticket_60_15 = OrderSend(Symbol(), OP_SELL, a_lots_4_15, NormalizeDouble(Bid,Digits), a_slippage_20_15, NormalizeDouble(StopShort_15(Ask, ai_32_15),Digits), NormalizeDouble(TakeShort_15(Bid, ai_36_15),Digits), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); l_error_64_15 = GetLastError(); if (l_error_64_15 == 0/* NO_ERROR */) break; if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; Sleep(5000); } } // case 2: // for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { // l_ticket_60_15 = OrderSend(Symbol(), OP_BUYLIMIT, a_lots_4_15, a_price_12_15, a_slippage_20_15, StopLong_15(ad_24_15, ai_32_15), TakeLong_15(a_price_12_15, ai_36_15), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); // l_error_64_15 = GetLastError(); // if (l_error_64_15 == 0/* NO_ERROR */) break; // if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; // Sleep(1000); // } // break; // case 4: // for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { // l_ticket_60_15 = OrderSend(Symbol(), OP_BUYSTOP, a_lots_4_15, a_price_12_15, a_slippage_20_15, StopLong_15(ad_24_15, ai_32_15), TakeLong_15(a_price_12_15, ai_36_15), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); // l_error_64_15 = GetLastError(); // if (l_error_64_15 == 0/* NO_ERROR */) break; // if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; // case 3: // for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { // l_ticket_60_15 = OrderSend(Symbol(), OP_SELLLIMIT, a_lots_4_15, a_price_12_15, a_slippage_20_15, StopShort_15(ad_24_15, ai_32_15), TakeShort_15(a_price_12_15, ai_36_15), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); // l_error_64_15 = GetLastError(); // if (l_error_64_15 == 0/* NO_ERROR */) break; // if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; // case 5: // for (l_count_68_15 = 0; l_count_68_15 < li_72_15; l_count_68_15++) { // l_ticket_60_15 = OrderSend(Symbol(), OP_SELLSTOP, a_lots_4_15, a_price_12_15, a_slippage_20_15, StopShort_15(ad_24_15, ai_32_15), TakeShort_15(a_price_12_15, ai_36_15), a_comment_40_15, a_magic_48_15, a_datetime_52_15, a_color_56_15); // l_error_64_15 = GetLastError(); // if (l_error_64_15 == 0/* NO_ERROR */) break; // if (!(l_error_64_15 == 4/* SERVER_BUSY */ || l_error_64_15 == 137/* BROKER_BUSY */ || l_error_64_15 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_15 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; return (l_ticket_60_15); } double StopLong_15(double ad_0_15, int ai_8_15) { if (ai_8_15 == 0) return (0); else return (ad_0_15 - ai_8_15 * Point); } double StopShort_15(double ad_0_15, int ai_8_15) { if (ai_8_15 == 0) return (0); else return (ad_0_15 + ai_8_15 * Point); } double TakeLong_15(double ad_0_15, int ai_8_15) { if (ai_8_15 == 0) return (0); else return (ad_0_15 + ai_8_15 * Point); } double TakeShort_15(double ad_0_15, int ai_8_15) { if (ai_8_15 == 0) return (0); else return (ad_0_15 - ai_8_15 * Point); } double CalculateProfit_15() { double ld_ret_0_15 = 0; for (g_pos_300_15 = OrdersTotal() - 1; g_pos_300_15 >= 0; g_pos_300_15--) { OrderSelect(g_pos_300_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15) if (OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_0_15 += OrderProfit(); } return (ld_ret_0_15); } void TrailingAlls_15(int ai_0_15, int ai_4_15, double a_price_8_15) { int l_ticket_16_15; double l_ord_stoploss_20_15; double l_price_28_15; if (ai_4_15 != 0) { for (int l_pos_36_15 = OrdersTotal() - 1; l_pos_36_15 >= 0; l_pos_36_15--) { if (OrderSelect(l_pos_36_15, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == g_magic_176_15) { if (OrderType() == OP_BUY) { l_ticket_16_15 = NormalizeDouble((Bid - a_price_8_15) / Point, 0); if (l_ticket_16_15 < ai_0_15) continue; l_ord_stoploss_20_15 = OrderStopLoss(); l_price_28_15 = Bid - ai_4_15 * Point; if (l_ord_stoploss_20_15 == 0.0 || (l_ord_stoploss_20_15 != 0.0 && l_price_28_15 > l_ord_stoploss_20_15)) OrderModify(OrderTicket(), a_price_8_15, l_price_28_15, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { l_ticket_16_15 = NormalizeDouble((a_price_8_15 - Ask) / Point, 0); if (l_ticket_16_15 < ai_0_15) continue; l_ord_stoploss_20_15 = OrderStopLoss(); l_price_28_15 = Ask + ai_4_15 * Point; if (l_ord_stoploss_20_15 == 0.0 || (l_ord_stoploss_20_15 != 0.0 && l_price_28_15 < l_ord_stoploss_20_15)) OrderModify(OrderTicket(), a_price_8_15, l_price_28_15, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } double AccountEquityHigh_15() { if (CountTrades_15() == 0) gd_336_15 = AccountEquity(); if (gd_336_15 < gd_344_15) gd_336_15 = gd_344_15; else gd_336_15 = AccountEquity(); gd_344_15 = AccountEquity(); return (gd_336_15); } double FindLastBuyPrice_15() { double l_ord_open_price_8_15; int l_ticket_24_15; double ld_unused_0_15 = 0; int l_ticket_20_15 = 0; for (int l_pos_16_15 = OrdersTotal() - 1; l_pos_16_15 >= 0; l_pos_16_15--) { OrderSelect(l_pos_16_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15 && OrderType() == OP_BUY) { l_ticket_24_15 = OrderTicket(); if (l_ticket_24_15 > l_ticket_20_15) { l_ord_open_price_8_15 = OrderOpenPrice(); ld_unused_0_15 = l_ord_open_price_8_15; l_ticket_20_15 = l_ticket_24_15; } } } return (l_ord_open_price_8_15); } double FindLastSellPrice_15() { double l_ord_open_price_8_15; int l_ticket_24_15; double ld_unused_0_15 = 0; int l_ticket_20_15 = 0; for (int l_pos_16_15 = OrdersTotal() - 1; l_pos_16_15 >= 0; l_pos_16_15--) { OrderSelect(l_pos_16_15, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_15) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_15 && OrderType() == OP_SELL) { l_ticket_24_15 = OrderTicket(); if (l_ticket_24_15 > l_ticket_20_15) { l_ord_open_price_8_15 = OrderOpenPrice(); ld_unused_0_15 = l_ord_open_price_8_15; l_ticket_20_15 = l_ticket_24_15; } } } return (l_ord_open_price_8_15); } //============================================================// //======================CountTrades_16========================// //============================================================// int CountTrades_16() { int l_count_0_16 = 0; for (int l_pos_4_16 = OrdersTotal() - 1; l_pos_4_16 >= 0; l_pos_4_16--) { OrderSelect(l_pos_4_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) if (OrderType() == OP_SELL || OrderType() == OP_BUY) l_count_0_16++; } return (l_count_0_16); } void CloseThisSymbolAll_16() { for (int l_pos_0_16 = OrdersTotal() - 1; l_pos_0_16 >= 0; l_pos_0_16--) { OrderSelect(l_pos_0_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip_16, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip_16, Red); } Sleep(1000); } } } int OpenPendingOrder_16(int ai_0_16, double a_lots_4_16, double a_price_12_16, int a_slippage_20_16, double ad_24_16, int ai_32_16, int ai_36_16, string a_comment_40_16, int a_magic_48_16, int a_datetime_52_16, color a_color_56_16) { int l_ticket_60_16 = 0; int l_error_64_16 = 0; int l_count_68_16 = 0; int li_72_16 = 100; switch (ai_0_16) { case 0: for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { RefreshRates(); l_ticket_60_16 = OrderSend(Symbol(), OP_BUY, a_lots_4_16, NormalizeDouble(Ask,Digits), a_slippage_20_16, NormalizeDouble(StopLong_16(Bid, ai_32_16),Digits), NormalizeDouble(TakeLong_16(Ask, ai_36_16),Digits), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); l_error_64_16 = GetLastError(); if (l_error_64_16 == 0/* NO_ERROR */) break; if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 1: for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { l_ticket_60_16 = OrderSend(Symbol(), OP_SELL, a_lots_4_16, NormalizeDouble(Bid,Digits), a_slippage_20_16, NormalizeDouble(StopShort_16(Ask, ai_32_16),Digits), NormalizeDouble(TakeShort_16(Bid, ai_36_16),Digits), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); l_error_64_16 = GetLastError(); if (l_error_64_16 == 0/* NO_ERROR */) break; if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; Sleep(5000); } } // case 2: // for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { // l_ticket_60_16 = OrderSend(Symbol(), OP_BUYLIMIT, a_lots_4_16, a_price_12_16, a_slippage_20_16, StopLong_16(ad_24_16, ai_32_16), TakeLong_16(a_price_12_16, ai_36_16), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); // l_error_64_16 = GetLastError(); // if (l_error_64_16 == 0/* NO_ERROR */) break; // if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; // Sleep(1000); // } // break; // case 4: // for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { // l_ticket_60_16 = OrderSend(Symbol(), OP_BUYSTOP, a_lots_4_16, a_price_12_16, a_slippage_20_16, StopLong_16(ad_24_16, ai_32_16), TakeLong_16(a_price_12_16, ai_36_16), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); // l_error_64_16 = GetLastError(); // if (l_error_64_16 == 0/* NO_ERROR */) break; // if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; // case 3: // for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { // l_ticket_60_16 = OrderSend(Symbol(), OP_SELLLIMIT, a_lots_4_16, a_price_12_16, a_slippage_20_16, StopShort_16(ad_24_16, ai_32_16), TakeShort_16(a_price_12_16, ai_36_16), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); // l_error_64_16 = GetLastError(); // if (l_error_64_16 == 0/* NO_ERROR */) break; // if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; // case 5: // for (l_count_68_16 = 0; l_count_68_16 < li_72_16; l_count_68_16++) { // l_ticket_60_16 = OrderSend(Symbol(), OP_SELLSTOP, a_lots_4_16, a_price_12_16, a_slippage_20_16, StopShort_16(ad_24_16, ai_32_16), TakeShort_16(a_price_12_16, ai_36_16), a_comment_40_16, a_magic_48_16, a_datetime_52_16, a_color_56_16); // l_error_64_16 = GetLastError(); // if (l_error_64_16 == 0/* NO_ERROR */) break; // if (!(l_error_64_16 == 4/* SERVER_BUSY */ || l_error_64_16 == 137/* BROKER_BUSY */ || l_error_64_16 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64_16 == 136/* OFF_QUOTES */)) break; // Sleep(5000); // } // break; return (l_ticket_60_16); } double StopLong_16(double ad_0_16, int ai_8_16) { if (ai_8_16 == 0) return (0); else return (ad_0_16 - ai_8_16 * Point); } double StopShort_16(double ad_0_16, int ai_8_16) { if (ai_8_16 == 0) return (0); else return (ad_0_16 + ai_8_16 * Point); } double TakeLong_16(double ad_0_16, int ai_8_16) { if (ai_8_16 == 0) return (0); else return (ad_0_16 + ai_8_16 * Point); } double TakeShort_16(double ad_0_16, int ai_8_16) { if (ai_8_16 == 0) return (0); else return (ad_0_16 - ai_8_16 * Point); } double CalculateProfit_16() { double ld_ret_0_16 = 0; for (g_pos_300_16 = OrdersTotal() - 1; g_pos_300_16 >= 0; g_pos_300_16--) { OrderSelect(g_pos_300_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16) if (OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_0_16 += OrderProfit(); } return (ld_ret_0_16); } void TrailingAlls_16(int ai_0_16, int ai_4_16, double a_price_8_16) { int l_ticket_16_16; double l_ord_stoploss_20_16; double l_price_28_16; if (ai_4_16 != 0) { for (int l_pos_36 = OrdersTotal() - 1; l_pos_36 >= 0; l_pos_36--) { if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == g_magic_176_16) { if (OrderType() == OP_BUY) { l_ticket_16_16 = NormalizeDouble((Bid - a_price_8_16) / Point, 0); if (l_ticket_16_16 < ai_0_16) continue; l_ord_stoploss_20_16 = OrderStopLoss(); l_price_28_16 = Bid - ai_4_16 * Point; if (l_ord_stoploss_20_16 == 0.0 || (l_ord_stoploss_20_16 != 0.0 && l_price_28_16 > l_ord_stoploss_20_16)) OrderModify(OrderTicket(), a_price_8_16, l_price_28_16, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { l_ticket_16_16 = NormalizeDouble((a_price_8_16 - Ask) / Point, 0); if (l_ticket_16_16 < ai_0_16) continue; l_ord_stoploss_20_16 = OrderStopLoss(); l_price_28_16 = Ask + ai_4_16 * Point; if (l_ord_stoploss_20_16 == 0.0 || (l_ord_stoploss_20_16 != 0.0 && l_price_28_16 < l_ord_stoploss_20_16)) OrderModify(OrderTicket(), a_price_8_16, l_price_28_16, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } double AccountEquityHigh_16() { if (CountTrades_16() == 0) gd_336_16 = AccountEquity(); if (gd_336_16 < gd_344_16) gd_336_16 = gd_344_16; else gd_336_16 = AccountEquity(); gd_344_16 = AccountEquity(); return (gd_336_16); } double FindLastBuyPrice_16() { double l_ord_open_price_8_16; int l_ticket_24_16; double ld_unused_0_16 = 0; int l_ticket_20_16 = 0; for (int l_pos_16_16 = OrdersTotal() - 1; l_pos_16_16 >= 0; l_pos_16_16--) { OrderSelect(l_pos_16_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16 && OrderType() == OP_BUY) { l_ticket_24_16 = OrderTicket(); if (l_ticket_24_16 > l_ticket_20_16) { l_ord_open_price_8_16 = OrderOpenPrice(); ld_unused_0_16 = l_ord_open_price_8_16; l_ticket_20_16 = l_ticket_24_16; } } } return (l_ord_open_price_8_16); } double FindLastSellPrice_16() { double l_ord_open_price_8_16; int l_ticket_24_16; double ld_unused_0_16 = 0; int l_ticket_20_16 = 0; for (int l_pos_16_16 = OrdersTotal() - 1; l_pos_16_16 >= 0; l_pos_16_16--) { OrderSelect(l_pos_16_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_16) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_16 && OrderType() == OP_SELL) { l_ticket_24_16 = OrderTicket(); if (l_ticket_24_16 > l_ticket_20_16) { l_ord_open_price_8_16 = OrderOpenPrice(); ld_unused_0_16 = l_ord_open_price_8_16; l_ticket_20_16 = l_ticket_24_16; } } } return (l_ord_open_price_8_16); } //****время string TimeToString(int ai_0) { if (!show12HourTime) return (TimeToStr(ai_0, TIME_MINUTES)); int li_4 = TimeHour(ai_0); int l_minute_8 = TimeMinute(ai_0); string ls_12 = " AM"; if (li_4 >= 12) { li_4 -= 12; ls_12 = " PM"; } if (li_4 == 0) li_4 = 12; string ls_ret_20 = DoubleToStr(li_4, 0) + ":"; if (l_minute_8 < 10) ls_ret_20 = ls_ret_20 + "0"; ls_ret_20 = ls_ret_20 + DoubleToStr(l_minute_8, 0); ls_ret_20 = ls_ret_20 + ls_12; return (ls_ret_20); } string FormatDateTime(int ai_0, int ai_4, int ai_8, int ai_12, int ai_16, int ai_20) { string ls_24 = ai_4 + 100; ls_24 = StringSubstr(ls_24, 1); string ls_32 = ai_8 + 100; ls_32 = StringSubstr(ls_32, 1); string ls_40 = ai_12 + 100; ls_40 = StringSubstr(ls_40, 1); string ls_48 = ai_16 + 100; ls_48 = StringSubstr(ls_48, 1); string ls_56 = ai_20 + 100; ls_56 = StringSubstr(ls_56, 1); return (StringConcatenate(ai_0, ".", ls_24, ".", ls_32, " ", ls_40, ":", ls_48, ":", ls_56)); } //** int ObjectMakeLabel(string a_name_0, int a_x_8, int a_y_12) { ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0); ObjectSet(a_name_0, OBJPROP_CORNER, corner); ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12); ObjectSet(a_name_0, OBJPROP_BACK, TRUE); return (0); } int GMT_Offset(string as_0, int ai_8) { int li_ret_12 = 0; if (as_0 == "FRANKFURT") li_ret_12 = GMT1(ai_8); else { if (as_0 == "LONDON") li_ret_12 = GMT0(ai_8); else { if (as_0 == "US") li_ret_12 = GMT_5(ai_8); else if (as_0 == "TOKYO") li_ret_12 = GMT9(ai_8); } } return (li_ret_12); } int GMT0(int ai_0) { if (ai_0 > last_sunday(TimeYear(ai_0), 3) && ai_0 < last_sunday(TimeYear(ai_0), 10)) return (1); else return (0); } int GMT_5(int ai_0) { if (TimeYear(ai_0) < 2007) { if (ai_0 > first_sunday(TimeYear(ai_0), 4) && ai_0 < last_sunday(TimeYear(ai_0), 10)) return (-4); else return (-5); } else { if (ai_0 > second_sunday(TimeYear(ai_0), 3) && ai_0 < first_sunday(TimeYear(ai_0), 11)) return (-4); else return (-5); } } int GMT9(int ai_unused_0) { return (9); } bool is_leap_year(int ai_0) { if (MathMod(ai_0, 100) == 0.0 && MathMod(ai_0, 400) == 0.0) return (TRUE); else { if (MathMod(ai_0, 100) != 0.0 && MathMod(ai_0, 4) == 0.0) return (TRUE); else return (FALSE); } } int n_days(int ai_0, int ai_4) { int li_ret_8; if (ai_4 == 1) li_ret_8 = 31; else { if (ai_4 == 2) { if (is_leap_year(ai_0)) li_ret_8 = 29; else li_ret_8 = 28; } else { if (ai_4 == 3) li_ret_8 = 31; else { if (ai_4 == 4) li_ret_8 = 30; else { if (ai_4 == 5) li_ret_8 = 31; else { if (ai_4 == 6) li_ret_8 = 30; else { if (ai_4 == 7) li_ret_8 = 31; else { if (ai_4 == 8) li_ret_8 = 31; else { if (ai_4 == 9) li_ret_8 = 30; else { if (ai_4 == 10) li_ret_8 = 31; else { if (ai_4 == 11) li_ret_8 = 30; else if (ai_4 == 12) li_ret_8 = 31; } } } } } } } } } } return (li_ret_8); } int n_sdays(int ai_0, int ai_4) { int l_str2time_8; int li_12 = n_days(ai_0, ai_4); int l_count_20 = 0; for (int li_16 = 1; li_16 <= li_12; li_16++) { l_str2time_8 = StrToTime(DoubleToStr(ai_0, 0) + "." + DoubleToStr(ai_4, 0) + "." + DoubleToStr(li_16, 0) + " 00:00"); if (TimeDayOfWeek(l_str2time_8) == 0) l_count_20++; } return (l_count_20); } int last_sunday(int ai_0, int ai_4) { int l_str2time_24; int l_str2time_28; int li_12 = n_days(ai_0, ai_4); int li_20 = n_sdays(ai_0, ai_4); int l_count_16 = 0; for (int li_8 = 1; li_8 <= li_12; li_8++) { l_str2time_24 = StrToTime(DoubleToStr(ai_0, 0) + "." + DoubleToStr(ai_4, 0) + "." + DoubleToStr(li_8, 0) + " 00:00"); if (TimeDayOfWeek(l_str2time_24) == 0) l_count_16++; if (l_count_16 == li_20) { l_str2time_28 = l_str2time_24; break; } } return (l_str2time_28); } int first_sunday(int ai_0, int ai_4) { int l_str2time_24; int l_str2time_28; int li_12 = n_days(ai_0, ai_4); int li_20 = 1; int l_count_16 = 0; for (int li_8 = 1; li_8 <= li_12; li_8++) { l_str2time_24 = StrToTime(DoubleToStr(ai_0, 0) + "." + DoubleToStr(ai_4, 0) + "." + DoubleToStr(li_8, 0) + " 00:00"); if (TimeDayOfWeek(l_str2time_24) == 0) l_count_16++; if (l_count_16 == li_20) { l_str2time_28 = l_str2time_24; break; } } return (l_str2time_28); } int second_sunday(int ai_0, int ai_4) { int l_str2time_24; int l_str2time_28; int li_12 = n_days(ai_0, ai_4); int li_20 = 2; int l_count_16 = 0; for (int li_8 = 1; li_8 <= li_12; li_8++) { l_str2time_24 = StrToTime(DoubleToStr(ai_0, 0) + "." + DoubleToStr(ai_4, 0) + "." + DoubleToStr(li_8, 0) + " 00:00"); if (TimeDayOfWeek(l_str2time_24) == 0) l_count_16++; if (l_count_16 == li_20) { l_str2time_28 = l_str2time_24; break; } } return (l_str2time_28); } int GMT1(int ai_0) { if (ai_0 > last_sunday(TimeYear(ai_0), 3) && ai_0 < last_sunday(TimeYear(ai_0), 10)) return (2); else return (1); } //++++++++++++++