//ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK #property copyright "Глебыч, logix edit" #property link "" //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK extern bool NewBarOpen = TRUE; extern bool Buy = TRUE; // при FALSE новые ордера открываться не будут, усредняющие ордера (колена) - будут extern bool Sell = TRUE; // при FALSE новые ордера открываться не будут, усредняющие ордера (колена) - будут extern double LotExponent = 1.8; // на сколько умножать лот при выставлении следующего колена. пример: первый лот 0.1, серия: 0.16, 0.26, 0.43 ... extern double LockExp = 1.8; // на сколько умножать общий лот серии extern double slip = 3.0; // на сколько может отличаться цена в случае если ДЦ запросит реквоты (в последний момент немного поменяет цену) extern double Lots = 0.1; // разер лота для начала торгов extern int lotdecimal = 2; // сколько знаков после запятой в лоте рассчитывать 0 - нормальные лоты (1), 1 - минилоты (0.1), 2 - микро (0.01) extern double TakeProfit1 = 10.0; extern double TakeProfit2 = 4; // Тейкпрофит основной серии, когда уже выставлен лок extern double Pipstep = 12.0; // шаг между выставление новых колен extern double PipStepExponent = 1.3; // на сколько увеличивается след шаг extern int MaxTrades = 5; // Вместо колена под этим номерм выставиться лок extern int MagicNumber = 2233; // волшебное число (помогает советнику отличить свои ставки от чужих) //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK extern int PerMFI = 4; extern int RSI_Per = 16; extern double RsiMinimum = 50.0; // этот индикатор тут используется как показатель тренда extern double RsiMaximum = 50.0; // а не прекупленнности/перепроданности //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK extern bool UseEquityStop = FALSE; extern double TotalEquityRisk = 20.0; extern bool UseTrailingStop = FALSE; extern double TrailStart = 30.0; extern double TrailStop = 20.0; extern bool UseTimeOut = FALSE; // использовать таймаут (закрывать сделки если они "висят" слишком долго) extern double MaxTradeOpenHours = 48.0; // время таймаута сделок в часах (через сколько закрывать зависшие сделки) extern double Reinvest = 0; // реинвестирование в процентах от депозита, при Reinvest = 0 работает фиксированным лотом //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double KolLock, TakeProfit; int Nbar = 2; double Stoploss = 500.0; // уровень безубытка double PriceTarget, StartEquity, BuyTarget, SellTarget; double AveragePrice, SellLimit, BuyLimit; double LastBuyPrice, LastSellPrice, Spread; bool flag; extern string EAName="Ilan1.6"; int timeprev = 0, expiration; int NumOfTrades = 0; double iLots; double PipStep; int cnt = 0, total; double Stopper = 0.0; bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE; int ticket; bool NewOrdersPlaced = FALSE; double AccountEquityHighAmt, PrevEquity; //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK int init() { Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point; return (0); } int deinit() { return (0); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK int start() { total = CountTrades(); KolLock = MaxTrades; if (total >= MaxTrades - 1 && total >= 1) { TakeProfit = TakeProfit2; } else TakeProfit = TakeProfit1; double MFI = iMFI(NULL,0,PerMFI,1); double MFI0 = iMFI(NULL,0,PerMFI,0); double RSI = iRSI(NULL,0,RSI_Per,0,0); double SignCCI = iCCI(NULL,0,55,0,0); PipStep = NormalizeDouble(Pipstep * MathPow(PipStepExponent, NumOfTrades), 0); if (UseTrailingStop && total < MaxTrades) TrailingAlls(TrailStart, TrailStop, AveragePrice); if (UseTimeOut) { if (TimeCurrent() >= expiration) { CloseThisSymbolAll(); Print("Closed All due to TimeOut"); } } double CurrentPairProfit = CalculateProfit(); if (UseEquityStop) { if (CurrentPairProfit < 0.0 && MathAbs(CurrentPairProfit) > TotalEquityRisk / 100.0 * AccountEquityHigh()) { CloseThisSymbolAll(); Print("Closed All due to Stop Out"); NewOrdersPlaced = FALSE; } } if (total > MaxTrades) { if (CurrentPairProfit > 100.0 * GetLots()) { CloseThisSymbolAll(); Print("Closed All due to Lock Profit"); NewOrdersPlaced = FALSE; } } if (total > KolLock && LockExp == 1) { PriceTarget = 0; for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderTakeProfit() > 0) OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(),Digits), NormalizeDouble(OrderStopLoss(),Digits), NormalizeDouble(PriceTarget,Digits), 0, Yellow); } } if (NewBarOpen) { if (timeprev == Time[0]) return (0); timeprev = Time[0]; } if (total == 0) flag = FALSE; for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { LongTrade = TRUE; ShortTrade = FALSE; break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_SELL) { LongTrade = FALSE; ShortTrade = TRUE; break; } } } if (total > 0 && total <= MaxTrades) { RefreshRates(); LastBuyPrice = FindLastBuyPrice(); LastSellPrice = FindLastSellPrice(); if (total >= KolLock) MFI = 10; if (NewBarOpen) { if (LongTrade && LastBuyPrice - Ask >= PipStep * Point && MFI<20) TradeNow = TRUE; } else if (LongTrade && LastBuyPrice - Ask >= PipStep * Point) TradeNow = TRUE; if (total >= KolLock) MFI = 90; if (NewBarOpen) { if (ShortTrade && Bid - LastSellPrice >= PipStep * Point && MFI>80) TradeNow = TRUE; } else if (ShortTrade && Bid - LastSellPrice >= PipStep * Point) TradeNow = TRUE; } if (total < 1) { ShortTrade = FALSE; LongTrade = FALSE; TradeNow = TRUE; StartEquity = AccountEquity(); } if (TradeNow) { LastBuyPrice = FindLastBuyPrice(); LastSellPrice = FindLastSellPrice(); if (ShortTrade) { NumOfTrades = total; iLots = NormalizeDouble(GetLots() * MathPow(LotExponent, NumOfTrades), lotdecimal); RefreshRates(); if (KolLock == total){ ticket = OpenPendingOrder(0, NormalizeDouble(SumLots()*LockExp, lotdecimal), NormalizeDouble(Ask,Digits), slip, NormalizeDouble(Bid,Digits), 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, Blue); }else{ ticket = OpenPendingOrder(1, iLots, NormalizeDouble(Bid,Digits), slip, NormalizeDouble(Ask,Digits), 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink); } if (ticket < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice = FindLastSellPrice(); TradeNow = FALSE; NewOrdersPlaced = TRUE; } else { if (LongTrade) { NumOfTrades = total; iLots = NormalizeDouble(GetLots() * MathPow(LotExponent, NumOfTrades), lotdecimal); if (KolLock == total){ ticket = OpenPendingOrder(1, NormalizeDouble(SumLots()*LockExp, lotdecimal), NormalizeDouble(Bid,Digits), slip, NormalizeDouble(Ask,Digits), 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink); }else{ ticket = OpenPendingOrder(0, iLots, NormalizeDouble(Ask,Digits), slip, NormalizeDouble(Bid,Digits), 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, Blue); } if (ticket < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice = FindLastBuyPrice(); TradeNow = FALSE; NewOrdersPlaced = TRUE; } } } if (TradeNow && total < 1) { double PrevCl = iClose(Symbol(), 0, Nbar); double CurrCl = iClose(Symbol(), 0, 0); SellLimit = NormalizeDouble(Bid, Digits); BuyLimit = NormalizeDouble(Ask, Digits); if (!ShortTrade && !LongTrade) { NumOfTrades = total; iLots = NormalizeDouble(GetLots() * MathPow(LotExponent, NumOfTrades), lotdecimal); if (Sell) { if (PrevCl > CurrCl && MFI0 > 20 && RSI < RsiMinimum && SignCCI > (-100)) { ticket = OpenPendingOrder(1, iLots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink); if (ticket < 0) { Print("Error: ", GetLastError()); return (0); } LastSellPrice = FindLastSellPrice(); NewOrdersPlaced = TRUE; } } if (Buy) { if (PrevCl < CurrCl && MFI0 < 80 && RSI > RsiMaximum && SignCCI < 100) { ticket = OpenPendingOrder(0, iLots, BuyLimit, slip, BuyLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, Blue); if (ticket < 0) { Print("Error: ", GetLastError()); return (0); } LastBuyPrice = FindLastBuyPrice(); NewOrdersPlaced = TRUE; } } if (ticket > 0) expiration = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours); TradeNow = FALSE; } } total = CountTrades(); AveragePrice = 0; double Count = 0; for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { AveragePrice += OrderOpenPrice() * OrderLots(); Count += OrderLots(); if (total <= MaxTrades && OrderTakeProfit() == 0) NewOrdersPlaced = TRUE; } } } if (total > 0) AveragePrice = NormalizeDouble(AveragePrice / Count, Digits); if (NewOrdersPlaced) { for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { PriceTarget = AveragePrice + TakeProfit * Point; BuyTarget = PriceTarget; Stopper = AveragePrice - Stoploss * Point; flag = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_SELL) { PriceTarget = AveragePrice - TakeProfit * Point; SellTarget = PriceTarget; Stopper = AveragePrice + Stoploss * Point; flag = TRUE; } } } } if (NewOrdersPlaced&&CountTrades()<=MaxTrades) { if (flag == TRUE) { for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), NormalizeDouble(AveragePrice,Digits), NormalizeDouble(OrderStopLoss(),Digits), NormalizeDouble(PriceTarget,Digits), 0, Yellow); NewOrdersPlaced = FALSE; } } } return (0); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double SumLots() { double sumLot = 0; for (int trade = OrdersTotal() - 1; trade >= 0; trade--) { OrderSelect(trade, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() == OP_SELL || OrderType() == OP_BUY)sumLot = sumLot+OrderLots(); } return (sumLot); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK int CountTrades() { int count = 0; for (int trade = OrdersTotal() - 1; trade >= 0; trade--) { OrderSelect(trade, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++; } return (count); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK void CloseThisSymbolAll() { for (int trade = OrdersTotal() - 1; trade >= 0; trade--) { OrderSelect(trade, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), slip, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), slip, Red); } Sleep(1000); } } } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK int OpenPendingOrder(int pType, double pLots, double pLevel, int sp, double pr, int sl, int tp, string pComment, int pMagic, int pDatetime, color pColor) { int ticket = 0; int err = 0; int c = 0; int NumberOfTries = 100; switch (pType) { case 2: for (c = 0; c < NumberOfTries; c++) { ticket = OrderSend(Symbol(), OP_BUYLIMIT, pLots, pLevel, sp, StopLong(pr, sl), TakeLong(pLevel, tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(1000); } break; case 4: for (c = 0; c < NumberOfTries; c++) { ticket = OrderSend(Symbol(), OP_BUYSTOP, pLots, pLevel, sp, StopLong(pr, sl), TakeLong(pLevel, tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 0: for (c = 0; c < NumberOfTries; c++) { RefreshRates(); ticket = OrderSend(Symbol(), OP_BUY, pLots, NormalizeDouble(Ask,Digits), sp, StopLong(NormalizeDouble(Bid,Digits), sl), TakeLong(NormalizeDouble(Ask,Digits), tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 3: for (c = 0; c < NumberOfTries; c++) { ticket = OrderSend(Symbol(), OP_SELLLIMIT, pLots, pLevel, sp, StopShort(pr, sl), TakeShort(pLevel, tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 5: for (c = 0; c < NumberOfTries; c++) { ticket = OrderSend(Symbol(), OP_SELLSTOP, pLots, pLevel, sp, StopShort(pr, sl), TakeShort(pLevel, tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 1: for (c = 0; c < NumberOfTries; c++) { ticket = OrderSend(Symbol(), OP_SELL, pLots, NormalizeDouble(Bid,Digits), sp, StopShort(NormalizeDouble(Ask,Digits), sl), TakeShort(NormalizeDouble(Bid,Digits), tp), pComment, pMagic, pDatetime, pColor); err = GetLastError(); if (err == 0/* NO_ERROR */) break; if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break; Sleep(5000); } } return (ticket); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double StopLong(double price, int stop) { if (stop == 0) return (0); else return (price - stop * Point); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double StopShort(double price, int stop) { if (stop == 0) return (0); else return (price + stop * Point); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double TakeLong(double price, int stop) { if (stop == 0) return (0); else return (price + stop * Point); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double TakeShort(double price, int stop) { if (stop == 0) return (0); else return (price - stop * Point); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double CalculateProfit() { double Profit = 0; for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit += OrderProfit(); } return (Profit); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK void TrailingAlls(int pType, int stop, double AvgPrice) { int profit; double stoptrade; double stopcal; if (stop != 0) { for (int trade = OrdersTotal() - 1; trade >= 0; trade--) { if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { profit = NormalizeDouble((Bid - AvgPrice) / Point, 0); if (profit < pType) continue; stoptrade = OrderStopLoss(); stopcal = Bid - stop * Point; if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal > stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { profit = NormalizeDouble((AvgPrice - Ask) / Point, 0); if (profit < pType) continue; stoptrade = OrderStopLoss(); stopcal = Ask + stop * Point; if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal < stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double AccountEquityHigh() { if (CountTrades() == 0) AccountEquityHighAmt = AccountEquity(); if (AccountEquityHighAmt < PrevEquity) AccountEquityHighAmt = PrevEquity; else AccountEquityHighAmt = AccountEquity(); PrevEquity = AccountEquity(); return (AccountEquityHighAmt); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double FindLastBuyPrice() { double oldorderopenprice; int oldticketnumber; double unused = 0; int ticketnumber = 0; for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) { oldticketnumber = OrderTicket(); if (oldticketnumber > ticketnumber) { oldorderopenprice = OrderOpenPrice(); unused = oldorderopenprice; ticketnumber = oldticketnumber; } } } return (oldorderopenprice); } double FindLastSellPrice() { double oldorderopenprice; int oldticketnumber; double unused = 0; int ticketnumber = 0; for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) { oldticketnumber = OrderTicket(); if (oldticketnumber > ticketnumber) { oldorderopenprice = OrderOpenPrice(); unused = oldorderopenprice; ticketnumber = oldticketnumber; } } } return (oldorderopenprice); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK double GetLots() { double minLot = MarketInfo(Symbol(), MODE_MINLOT); double maxLot = MarketInfo(Symbol(), MODE_MAXLOT); double balance = AccountBalance(); if(Reinvest!=0) { double lot = NormalizeDouble(balance * Reinvest / 1000 / 100, 2); if(lot < minLot) lot = minLot; if(lot > maxLot) lot = maxLot; } else lot = Lots; return(lot); } //ILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCKILANLOCK