<code> //+------------------------------------------------------------------+ //| HighLowXZ.mq4 | //| Copyright 2021, AM2 | //| http://www.forexsystems.biz | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, AM2" #property link "http://www.forexsystems.biz" #property version "1.00" #property strict //--- Inputs extern double Lots = 0.1; // лот extern double MaxLot = 5; // максимальный лот extern int StopLoss = 222; // лось extern int TakeProfit = 333; // язь extern int Count = 2; // число поз extern int Delta = 20; // дополнение к стопу extern int Slip = 30; // реквот extern int Magic = 123; // магик //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Comment(""); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); } //+------------------------------------------------------------------+ //| Одна сделка за свечу | //+------------------------------------------------------------------+ bool OneCandleDeal() { if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderOpenTime()>Time[0] && OrderOpenTime()<Time[0]+PeriodSeconds()) { return(false); } } } return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CountTrades(int type) { int count=0; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==type) count++; } } } return(count); } //+------------------------------------------------------------------+ //| Подсчет профита по типу ордеров | //+------------------------------------------------------------------+ double AllProfit(int ot=-1) { double pr=0; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==0 && (ot==0 || ot==-1)) { pr+=OrderProfit()+OrderCommission()+OrderSwap(); } if(OrderType()==1 && (ot==1 || ot==-1)) { pr+=OrderProfit()+OrderCommission()+OrderSwap(); } } } } return(pr); } //------------------------------------------------------------------------ //+------------------------------------------------------------------+ //| Автор функции подсчета профита последней | //| группы закрытых ордеров"Vitalie Postolache" | //+------------------------------------------------------------------+ double lastloss() { double lastlos=0,op=0; int cnt=0; datetime time=0; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) { if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic && OrderType()<2) { if(cnt==0 && OrderCloseTime()!=0) time=OrderCloseTime(); if(OrderCloseTime()+PeriodSeconds()<time) break; op=NormalizeDouble(OrderProfit()+OrderSwap()+OrderCommission(),2); lastlos+=op; cnt++; } } } return(lastlos); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ModeB() { bool m=1; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==0) { if(OrderOpenPrice()< OrderTakeProfit()) m=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-NormalizeDouble(StopLoss*_Point,_Digits),0,Yellow); } { if(OrderOpenPrice()> OrderTakeProfit()) m=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderTakeProfit()-NormalizeDouble(StopLoss*_Point,_Digits),0,Yellow); } } } } } //-------------------------------------------------------------------------------------------------- void ModeS() { bool m=1; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==1) { if(OrderOpenPrice()> OrderTakeProfit()) m=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+NormalizeDouble(StopLoss*_Point,_Digits),0,Yellow); } { if(OrderOpenPrice()< OrderTakeProfit()) m=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderTakeProfit()+NormalizeDouble(StopLoss*_Point,_Digits),0,Yellow); } } } } } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int r=0; if(Bid>=High[1]) { if(CountTrades(0)<Count) { if(OneCandleDeal()) { r=OrderSend(NULL,0,Lots,NormalizeDouble(Ask,_Digits),Slip,0,NormalizeDouble(Bid+TakeProfit*_Point,_Digits),"",Magic,0,Blue); if(lastloss()>0) ModeS(); } } } if(Bid<=Low[1]) { if(CountTrades(1)<Count) { if(OneCandleDeal()) { r=OrderSend(NULL,1,Lots,NormalizeDouble(Bid,_Digits),Slip,0,NormalizeDouble(Ask-TakeProfit*_Point,_Digits),"",Magic,0,Red); if(lastloss()>0) ModeB(); } } } Comment("\n Buy: ",CountTrades(0), "\n Sell: ",CountTrades(1), " \n", "\n Крайний профит: ",lastloss()); } //+------------------------------------------------------------------+ </code>
GAWroch