//+------------------------------------------------------------------+ //| DubleIlan_16TD_CCI_1.2.mq4 | //| За основу взят Ilan_16TD_CCI_1.2.mq4 от Night | //| | //| FastProfit© 2011 | //+------------------------------------------------------------------+ #define START 1 #define STOP 0 extern string t1 = "Режим Turbo"; extern bool Turbo = true; // режим Турбо extern string t2 = "Режим Dynamic"; extern bool FlagDynamic = true; // режим Dynamic extern string t3 = "№ ордера для начала работы Dynamic (не < 4)"; extern int StartDynamic = 4; // ордер, с которого начинает работать режим Dynamic extern string t4 = "NewCycle режим отмены выставления новых ордеров"; extern bool NewCycle = true; // Режим отмены выставления новых ордеров extern string t5 = "Период MA"; extern int PerMA = 20; extern string t6 = "уровень CCI для входов"; extern double Drop1 = 100; // уровень CCI для входов extern double Drop2 = 105; // уровень CCI для входов string t7 = "Таймфреймы CCI"; int timefr1 = 1; // ТФ CCI int timefr2 = 5; // ТФ CCI extern string t8 = "Периоды CCI"; extern double Per1 = 95; // период CCI extern double Per2 = 70; // период CCI extern int applied_price = 6; //способ расчёта цены внутри бара. Для расчёта ССИ. не больше 6!!!!!!!!!!! //************************************************************************************************************* extern string t9 = "Общие настройки Илана 1"; extern double LotExponent = 1.95; extern double slip = 5.0; extern double Lots = 0.1; extern int lotdecimal = 2; extern double TakeProfit = 10.0; extern double PipStep_ = 30.0; double PipStep,PipS ; extern int MaxTrades = 10; extern int g_magic_176 = 1111; //МАГИК ПЕРВОГО ИЛАНА extern string t10 = "Общие настройки илан2"; extern double LotExponent_2 = 1.95; extern double slip_2 = 5.0; extern double Lots_2 = 0.1; extern int lotdecimal_2 = 2; extern double TakeProfit_2 = 10.0; extern double PipStep_2_ = 30.0; double PipStep_2,PipS_2 ; extern int MaxTrades_2 = 10; extern int g_magic_176_2 = 2222; //МАГИК ВТОРОГО ИЛАНА extern string t11 = "Включен второй илан"; bool Ilan1 = true; extern bool Ilan2 = true; //***************************** bool UseEquityStop = FALSE; double TotalEquityRisk = 20.0; bool UseTrailingStop = FALSE; double TrailStart = 10.0; double TrailStop = 10.0; double Stoploss = 500.0; // ******************************* переменные *********************************************************** double gd_unused_196_2; double gd_unused_204_2; double MarginUsed_2; double LastBuyPrice_2; double LastSellPrice_2; double ProfitSerii_2; bool FlagMarketOrders_2; string gs_ilan_272_2 = "Ilan_2"; int TimeBar_0_2 = 0; int TimeOut_2,OrdersQuantity_2 ,ord_N_2 ; int N_for_Opening_2 = 0; double LotSizeForOpen_2; int OrderPosition_2 = 0; int amountTrades_2; double gd_308_2 = 0.0; bool FlagStartTrade_2 = STOP; bool FlagStartBuy_2 = STOP; bool FlagStartSell_2 = STOP; int TiketOpened_2; bool FlagStartModifyOrders_2 = STOP; //************************************************************************************************************* // extern string t_ = "Удачной торговли!"; double ProfitSerii, Balans, Sredstva ; // double gd_188; double gd_unused_196; double gd_unused_204; double MarginUsed; double LastBuyPrice; double LastSellPrice; double PriceSpread; bool FlagMarketOrders; string gs_ilan_272 = "Ilan_1"; int TimeBar_0 = 0; int TimeOut,OrdersQuantity ,ord_N ; int N_for_Opening = 0; double LotSizeForOpen; int OrderPosition = 0; int amountTrades; double gd_308 = 0.0; #define START 1 #define STOP 0 bool FlagStartTrade = STOP; bool FlagStartBuy = STOP; bool FlagStartSell = STOP; bool UseTimeOut = STOP; int TiketOpened; bool FlagStartModifyOrders = STOP; double Equity; double Equity1; //============================== string txt,txt1; string txt2=""; string txt3=""; color col = ForestGreen; //============================== int start() { //**********************************START******************************************* double l_iclose_8; double l_iclose_16; if (UseTrailingStop) TrailingAlls(TrailStart, TrailStop, MarginUsed); PrintChartComment(); if (Ilan1) { //*****************// Турбо-режим ********* //========= OrdersQuantity = CountTrades(g_magic_176); if (Turbo) { if (OrdersQuantity == 1) PipStep = PipStep_/3; if (OrdersQuantity == 2) PipStep = PipStep_/3*2; if (OrdersQuantity >= 3) PipStep = PipStep_; } else PipStep = PipStep_; //========= //***************************************** { //=================Dynamic-режим ord_N = CountTrades(g_magic_176); {if (ord_N >= StartDynamic) if (FlagDynamic) { double hival=High[iHighest(NULL,0,MODE_HIGH,36,1)]; // вычисление наибольшей цены за последние 36 бара double loval=Low[iLowest(NULL,0,MODE_LOW,36,1)]; // вычисление наименьшей цены за последние 36 бара//chart used for symbol and time period PipS=NormalizeDouble((hival-loval)/3/Point,0); // расчёт PipStep //if (PipStepPipStep_*2) PipStep = PipStep_*2; // Если рассчетный шаг больше чем PipStep в 2 раза, то уменьшаем его } else PipStep = PipStep_; } } //================= PrintBalans(); //================== if (TimeBar_0 == Time[0]) return (0); // Если нет нового бара, то выходим TimeBar_0 = Time[0]; double ld_0 = CalculateProfit(g_magic_176); if (UseEquityStop) { if (ld_0 < 0.0 && MathAbs(ld_0) > TotalEquityRisk / 100.0 * AccountEquityHigh()) { // Если Эквити упало ниже заданного предела, то все закрываем и запрещаем торговлю CloseThisSymbolAll(); Print("Closed All due to Stop Out"); FlagStartModifyOrders = STOP; } } ChekAmountTrades(); if (amountTrades > 0 && amountTrades <= MaxTrades) { RefreshRates(); LastBuyPrice = FindLastBuyPrice(g_magic_176); LastSellPrice = FindLastSellPrice(g_magic_176); if (FlagStartBuy && LastBuyPrice - Ask >= PipStep * Point) FlagStartTrade = START; if (FlagStartSell && Bid - LastSellPrice >= PipStep * Point) FlagStartTrade = START; } if (amountTrades < 1) { FlagStartSell = STOP; FlagStartBuy = STOP; FlagStartTrade = START; // gd_188 = AccountEquity(); } if (FlagStartTrade) { LastBuyPrice = FindLastBuyPrice(g_magic_176); LastSellPrice = FindLastSellPrice(g_magic_176); if (FlagStartSell) { N_for_Opening = amountTrades; LotSizeForOpen = NormalizeDouble(Lots * MathPow(LotExponent, N_for_Opening), lotdecimal); RefreshRates(); TiketOpened = OpenPendingOrder(OP_SELL , LotSizeForOpen, gs_ilan_272 + "-" + N_for_Opening, g_magic_176, 0, HotPink); if (TiketOpened < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice = FindLastSellPrice(g_magic_176); FlagStartTrade = STOP; FlagStartModifyOrders = START; } else { if (FlagStartBuy) { N_for_Opening = amountTrades; LotSizeForOpen = NormalizeDouble(Lots * MathPow(LotExponent, N_for_Opening), lotdecimal); TiketOpened = OpenPendingOrder(OP_BUY, LotSizeForOpen, gs_ilan_272 + "-" + N_for_Opening, g_magic_176, 0, Lime); if (TiketOpened < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice = FindLastBuyPrice(g_magic_176); FlagStartTrade = STOP; FlagStartModifyOrders = START; } } } if (NewCycle) { ChekAmountTrades_2(); if (FlagStartTrade && amountTrades < 1) { l_iclose_8 = iMA(NULL,0,PerMA,0,MODE_LWMA,PRICE_WEIGHTED,3);//первичное определение.. l_iclose_16 = iMA(NULL,0,PerMA,0,MODE_LWMA,PRICE_WEIGHTED,1);//..направления тренда if (!FlagStartSell && !FlagStartBuy) { N_for_Opening = amountTrades; LotSizeForOpen = NormalizeDouble(Lots * MathPow(LotExponent, N_for_Opening), lotdecimal); if (l_iclose_8 != l_iclose_16) // не входим, если нет движения цены { if (l_iclose_8 > l_iclose_16)// если есть движение, определяем направление... { if ((FlagStartBuy_2 || !FlagMarketOrders_2) && (iCCI(NULL,timefr1,Per1,applied_price,0)<(-Drop1))&&(iCCI(NULL,timefr2,Per2,applied_price,0)<(-Drop2)))//...и ждём подтверждение на 2-х ТФ по уровням ССИ { TiketOpened = OpenPendingOrder(OP_SELL, LotSizeForOpen, gs_ilan_272 + "-" + N_for_Opening, g_magic_176, 0, HotPink); if (TiketOpened < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice = FindLastBuyPrice(g_magic_176); FlagStartModifyOrders = START; } } else {if ((FlagStartSell_2 || !FlagMarketOrders_2) && (iCCI(NULL,timefr1,Per1,applied_price,0)>(Drop1))&&(iCCI(NULL,timefr2,Per2,applied_price,0)>(Drop2))) { TiketOpened = OpenPendingOrder(OP_BUY, LotSizeForOpen, gs_ilan_272 + "-" + N_for_Opening, g_magic_176, 0, Lime); if (TiketOpened < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice = FindLastSellPrice(g_magic_176); FlagStartModifyOrders = START; } } } //if (TiketOpened > 0) TimeOut = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours); FlagStartTrade = STOP; } } } amountTrades = CountTrades(g_magic_176); MarginUsed = 0; double SummaLotov = 0; for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { MarginUsed += OrderOpenPrice() * OrderLots(); SummaLotov += OrderLots(); } } } if (amountTrades > 0) MarginUsed = NormalizeDouble(MarginUsed / SummaLotov, Digits); if (FlagStartModifyOrders) { for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_BUY) { ProfitSerii = MarginUsed + TakeProfit * Point; gd_unused_196 = ProfitSerii; gd_308 = MarginUsed - Stoploss * Point; FlagMarketOrders = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_SELL) { ProfitSerii = MarginUsed - TakeProfit * Point; gd_unused_204 = ProfitSerii; gd_308 = MarginUsed + Stoploss * Point; FlagMarketOrders = TRUE; } } } } if (FlagStartModifyOrders) { if (FlagMarketOrders == TRUE) { // Print("первый илан модификация"); for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) //OrderModify(OrderTicket(), MarginUsed, OrderStopLoss(), ProfitSerii, 0, Yellow); //=== while(!OrderModify(OrderTicket(), MarginUsed, OrderStopLoss(), ProfitSerii, 0, Yellow))// модифицируем все открытые ордера... {Sleep(1000);RefreshRates();} //..причём здесь добавлена проверка, котрая должна по идее исключить.. //=== //..открытие ордеров без ТР FlagStartModifyOrders = STOP; } } } } //* return (0); //********************************************* ИЛАН 2 ********************************************************************************** // double l_iclose_8; // double l_iclose_16; if (Ilan2) { //if (UseTrailingStop) TrailingAlls(TrailStart, TrailStop, MarginUsed); //PrintChartComment(); //***************** Турбо-режим ********* //========= OrdersQuantity_2 = CountTrades(g_magic_176_2); if (Turbo) { if (OrdersQuantity_2 == 1) PipStep_2 = PipStep_2_/3; if (OrdersQuantity_2 == 2) PipStep_2 = PipStep_2_/3*2; if (OrdersQuantity_2 >= 3) PipStep_2 = PipStep_2_; } else PipStep_2 = PipStep_2_; //========= //***************************************** { //=================Dynamic-режим ord_N_2 = CountTrades(g_magic_176_2); {if (ord_N_2 >= StartDynamic) if (FlagDynamic) { double hival_2=High[iHighest(NULL,0,MODE_HIGH,36,1)]; // вычисление наибольшей цены за последние 36 бара double loval_2=Low[iLowest(NULL,0,MODE_LOW,36,1)]; // вычисление наименьшей цены за последние 36 бара//chart used for symbol and time period PipS_2=NormalizeDouble((hival_2-loval_2)/3/Point,0); // расчёт PipStep //if (PipStepPipStep_2_*2) PipStep_2 = PipStep_2_*2; // Если рассчетный шаг больше чем PipStep в 2 раза, то уменьшаем его } else PipStep_2 = PipStep_2_; } } //================= // PrintBalans(); //================== if (TimeBar_0 == Time[0] && !Ilan1 ) return (0); // Если нет нового бара и на первом илане мы еще не делали эту проверку, то выходим TimeBar_0 = Time[0]; double ld_0_2 = CalculateProfit(g_magic_176_2); if (UseEquityStop) { if (ld_0_2 < 0.0 && MathAbs(ld_0_2) > TotalEquityRisk / 100.0 * AccountEquityHigh()) { // Если Эквити упало ниже заданного предела, то все закрываем и запрещаем торговлю CloseThisSymbolAll(); Print("Closed All due to Stop Out"); FlagStartModifyOrders_2 = STOP; } } ChekAmountTrades_2(); if (amountTrades_2 > 0 && amountTrades_2 <= MaxTrades) { RefreshRates(); LastBuyPrice_2 = FindLastBuyPrice(g_magic_176_2); LastSellPrice_2 = FindLastSellPrice(g_magic_176_2); if (FlagStartBuy_2 && LastBuyPrice_2 - Ask >= PipStep_2 * Point) FlagStartTrade_2 = START; if (FlagStartSell_2 && Bid - LastSellPrice_2 >= PipStep_2 * Point) FlagStartTrade_2 = START; } if (amountTrades_2 < 1) { FlagStartSell_2 = STOP; FlagStartBuy_2 = STOP; FlagStartTrade_2 = START; // gd_188 = AccountEquity(); } if (FlagStartTrade_2) { LastBuyPrice_2 = FindLastBuyPrice(g_magic_176_2); LastSellPrice_2 = FindLastSellPrice(g_magic_176_2); if (FlagStartSell_2) { N_for_Opening_2 = amountTrades_2; LotSizeForOpen_2 = NormalizeDouble(Lots_2 * MathPow(LotExponent_2, N_for_Opening_2), lotdecimal); RefreshRates(); TiketOpened_2 = OpenPendingOrder(OP_SELL , LotSizeForOpen_2, gs_ilan_272_2 + "-" + N_for_Opening_2, g_magic_176_2, 0, HotPink); if (TiketOpened_2 < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice_2 = FindLastSellPrice(g_magic_176_2); FlagStartTrade_2 = STOP; FlagStartModifyOrders_2 = START; } else { if (FlagStartBuy_2) { N_for_Opening_2 = amountTrades_2; LotSizeForOpen_2 = NormalizeDouble(Lots_2 * MathPow(LotExponent_2, N_for_Opening_2), lotdecimal); TiketOpened_2 = OpenPendingOrder(OP_BUY, LotSizeForOpen_2, gs_ilan_272_2 + "-" + N_for_Opening_2, g_magic_176_2, 0, Lime); if (TiketOpened_2 < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice_2 = FindLastBuyPrice(g_magic_176_2); FlagStartTrade_2 = STOP; FlagStartModifyOrders_2 = START; } } } if (NewCycle) { ChekAmountTrades(); if ((FlagStartTrade_2 && amountTrades_2 < 1) && (amountTrades >= 3)) { l_iclose_8 = iMA(NULL,0,PerMA,0,MODE_LWMA,PRICE_WEIGHTED,3);//первичное определение.. l_iclose_16 = iMA(NULL,0,PerMA,0,MODE_LWMA,PRICE_WEIGHTED,1);//..направления тренда if (!FlagStartSell_2 && !FlagStartBuy_2) { N_for_Opening_2 = amountTrades_2; LotSizeForOpen_2 = NormalizeDouble(Lots_2 * MathPow(LotExponent_2, N_for_Opening_2), lotdecimal); if (l_iclose_8 != l_iclose_16) // не входим, если нет движения цены { if (l_iclose_8 > l_iclose_16)// если есть движение, определяем направление... { if ((iCCI(NULL,timefr1,Per1,applied_price,0)<(-Drop1))&&(iCCI(NULL,timefr2,Per2,applied_price,0)<(-Drop2)))//...и ждём подтверждение на 2-х ТФ по уровням ССИ { if (FlagStartBuy) { TiketOpened_2 = OpenPendingOrder(OP_SELL, LotSizeForOpen_2, gs_ilan_272_2 + "-" + N_for_Opening_2, g_magic_176_2, 0, HotPink); if (TiketOpened_2 < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice_2 = FindLastBuyPrice(g_magic_176_2); FlagStartModifyOrders_2 = START; } } } else {if ((iCCI(NULL,timefr1,Per1,applied_price,0)>(Drop1))&&(iCCI(NULL,timefr2,Per2,applied_price,0)>(Drop2))) { if (FlagStartSell) { TiketOpened_2 = OpenPendingOrder(OP_BUY, LotSizeForOpen_2, gs_ilan_272_2 + "-" + N_for_Opening_2, g_magic_176_2, 0, Lime); if (TiketOpened_2 < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice_2 = FindLastSellPrice(g_magic_176_2); FlagStartModifyOrders_2 = START; } } } } //if (TiketOpened > 0) TimeOut = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours); FlagStartTrade_2 = STOP; } } } amountTrades_2 = CountTrades(g_magic_176_2); MarginUsed_2 = 0; double SummaLotov_2 = 0; for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_2) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { MarginUsed_2 += OrderOpenPrice() * OrderLots(); SummaLotov_2 += OrderLots(); } } } if (amountTrades_2 > 0) MarginUsed_2 = NormalizeDouble(MarginUsed_2 / SummaLotov_2, Digits); if (FlagStartModifyOrders_2) { for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_2) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) { if (OrderType() == OP_BUY) { ProfitSerii_2 = MarginUsed_2 + TakeProfit_2 * Point; gd_unused_196_2 = ProfitSerii_2; gd_308_2 = MarginUsed_2 - Stoploss * Point; FlagMarketOrders_2 = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) { if (OrderType() == OP_SELL) { ProfitSerii_2 = MarginUsed_2 - TakeProfit_2 * Point; gd_unused_204_2 = ProfitSerii_2; gd_308_2 = MarginUsed_2 + Stoploss * Point; FlagMarketOrders_2 = TRUE; } } } } if (FlagStartModifyOrders_2) { if (FlagMarketOrders_2 == TRUE) { // Print("второй илан модификация"); for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_2) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) //OrderModify(OrderTicket(), MarginUsed, OrderStopLoss(), ProfitSerii, 0, Yellow); //=== while(!OrderModify(OrderTicket(), MarginUsed_2, OrderStopLoss(), ProfitSerii_2, 0, Yellow))// модифицируем все открытые ордера... {Sleep(1000);RefreshRates();} //..причём здесь добавлена проверка, котрая должна по идее исключить.. //=== //..открытие ордеров без ТР FlagStartModifyOrders_2 = STOP; } } } } return (0); } //***************************************************************************************************************************************** int init() { PriceSpread = 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, 11); // txt1="Ilan_16TD_CCI_1.2"+CharToStr(174)+"Night "; ObjectSetText("Lable1",txt1,15,"Times New Roman",DodgerBlue); //------------------------- return (0); } int deinit() { //---- ObjectDelete("Lable"); ObjectDelete("Lable1"); ObjectDelete("Lable2"); ObjectDelete("Lable3"); //---- return (0); } //*********************************************** Функции ****************************************************************************** void ChekAmountTrades() { amountTrades = CountTrades(g_magic_176); if (amountTrades == 0) FlagMarketOrders = FALSE; // Если не нашли открытых ордеров илана, то FlagMarketOrders = FALSE for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_BUY) { FlagStartBuy = START; FlagStartSell = STOP; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_SELL) { FlagStartBuy = STOP; FlagStartSell = START; break; } } } } //---------- void ChekAmountTrades_2() { amountTrades_2 = CountTrades(g_magic_176_2); if (amountTrades_2 == 0) FlagMarketOrders_2 = FALSE; // Если не нашли открытых ордеров илана, то FlagMarketOrders = FALSE for (OrderPosition_2 = OrdersTotal() - 1; OrderPosition_2 >= 0; OrderPosition_2--) { OrderSelect(OrderPosition_2, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_176_2) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) { if (OrderType() == OP_BUY) { FlagStartBuy_2 = START; FlagStartSell_2 = STOP; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176_2) { if (OrderType() == OP_SELL) { FlagStartBuy_2 = STOP; FlagStartSell_2 = START; break; } } } } //-------------- int CountTrades(int magic) { int l_count_0 = 0; for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) if (OrderType() == OP_SELL || OrderType() == OP_BUY) l_count_0++; } return (l_count_0); } void CloseThisSymbolAll() { for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red); } Sleep(1000); } } } int OpenPendingOrder(int ai_0, double a_lots_4, string a_comment_40, int a_magic_48, int a_datetime_52, color a_color_56) { int l_ticket_60 = 0; int l_error_64 = 0; int l_count_68 = 0; int li_72 = 100; for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { RefreshRates(); l_ticket_60 = OrderSend(Symbol(), ai_0, a_lots_4, NormalizeDouble(Bid * ai_0 - Ask * (ai_0 - 1),Digits), slip, 0, 0, a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } return (l_ticket_60); } double CalculateProfit(int magic) { double ld_ret_0 = 0; for (OrderPosition = OrdersTotal() - 1; OrderPosition >= 0; OrderPosition--) { OrderSelect(OrderPosition, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) if (OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_0 += OrderProfit(); } return (ld_ret_0); } void TrailingAlls(int ai_0, int ai_4, double a_price_8) { int li_16; double l_ord_stoploss_20; double l_price_28; if (ai_4 != 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) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == g_magic_176) { if (OrderType() == OP_BUY) { li_16 = NormalizeDouble((Bid - a_price_8) / Point, 0); if (li_16 < ai_0) continue; l_ord_stoploss_20 = OrderStopLoss(); l_price_28 = Bid - ai_4 * Point; if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 > l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { li_16 = NormalizeDouble((a_price_8 - Ask) / Point, 0); if (li_16 < ai_0) continue; l_ord_stoploss_20 = OrderStopLoss(); l_price_28 = Ask + ai_4 * Point; if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 < l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } double AccountEquityHigh() { if (CountTrades(g_magic_176) == 0) Equity = AccountEquity(); if (Equity < Equity1) Equity = Equity1; else Equity = AccountEquity(); Equity1 = AccountEquity(); return (Equity); } double FindLastBuyPrice(int magic) { double l_ord_open_price_8; int l_ticket_24; double ld_unused_0 = 0; int l_ticket_20 = 0; for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY) { l_ticket_24 = OrderTicket(); if (l_ticket_24 > l_ticket_20) { l_ord_open_price_8 = OrderOpenPrice(); ld_unused_0 = l_ord_open_price_8; l_ticket_20 = l_ticket_24; } } } return (l_ord_open_price_8); } double FindLastSellPrice(int magic) { double l_ord_open_price_8; int l_ticket_24; double ld_unused_0 = 0; int l_ticket_20 = 0; for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL) { l_ticket_24 = OrderTicket(); if (l_ticket_24 > l_ticket_20) { l_ord_open_price_8 = OrderOpenPrice(); ld_unused_0 = l_ord_open_price_8; l_ticket_20 = l_ticket_24; } } } return (l_ord_open_price_8); } void PrintChartComment() { Comment("" +"\n" + "Открыто ордеров Ilan1:" + CountTrades(g_magic_176) + "\n" + "magik=" + g_magic_176 + "\n" + "Открыто ордеров Ilan2:" + CountTrades(g_magic_176_2) + "\n" + "magik=" + g_magic_176_2 + "\n" + "_______________________________"); } void PrintBalans() { //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, 33); ObjectSet("Lable2", OBJPROP_YDISTANCE, 31); txt2=(DoubleToStr(AccountBalance(), 2)); ObjectSetText("Lable2","БАЛАНС "+txt2+"",16,"Times New Roman",DodgerBlue); //------------------------- ObjectDelete("Lable3"); ObjectCreate("Lable3",OBJ_LABEL,0,0,1.0); ObjectSet("Lable3", OBJPROP_CORNER, 3); ObjectSet("Lable3", OBJPROP_XDISTANCE, 33); ObjectSet("Lable3", OBJPROP_YDISTANCE, 11); txt3=(DoubleToStr(AccountEquity(), 2)); ObjectSetText("Lable3","СРЕДСТВА "+txt3+"",16,"Times New Roman",col); } //-------------------------