//+------------------------------------------------------------------+ //| Ala-Lavina.mq4 | //| Maxim A.Kuznetsov | //| luxtrade.tk | //+------------------------------------------------------------------+ #property copyright "Maxim A.Kuznetsov" #property link "luxtrade.tk" #property version "1.00" #property strict //--- input parameters input int TP=900; input int SL=100; input int MAGIC=11; double MIN_EQUITY,MAX_EQUITY; int OnInit() { double equity=AccountEquity()-AccountProfit(); MIN_EQUITY=equity/2; MAX_EQUITY=equity*2; return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } int lastKnown=-1; void OnTick() { double equity; if ((equity=AccountEquity())MAX_EQUITY) { // достигнута цель по балансу - закончить работу for(int pos=OrdersTotal()-1;pos>=0;pos--) { if (!OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) continue; if (OrderMagicNumber()!=MAGIC) continue; if (OrderCloseTime()!=0) continue; if (OrderSymbol()!=_Symbol) continue; OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0); } ExpertRemove(); return; } else { // проверить на сработку SL/TP все ордера datetime newestTime=0; int newestTicket=-1; for(int pos=OrdersHistoryTotal()-1;pos>=0;pos--) { if (!OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)) continue; if (OrderTicket()==lastKnown) break; // знакомый ордер, значит знаем и более старые, завершить цикл if (OrderMagicNumber()!=MAGIC) continue; if (OrderSymbol()!=_Symbol) continue; if (newestTicket==-1) { // сохранить тикет самого первого встретившегося newestTicket=OrderTicket(); } string comment=OrderComment(); if (OrderProfit()<0) { OpenPair(OrderLots()); } else { //OpenPair(OrderLots()); } } if (newestTicket!=-1) lastKnown=newestTicket; RefreshRates(); if (OrdersTotal()<2) { // если осталось маловато OpenPair(); } } } void OpenPair(double lots=0) { if (lots==0) { lots=MarketInfo(_Symbol,MODE_MINLOT); } else if (lots