Script to stop all trades and close out all positions in MQL5?

 

I am aware that there is a script to stop all trades and close out all positions in MQL4.


But I am not aware of such code's existence in MQL5.


I couldn't find such script in there - where should I find such script which will stop all trades and close out all positions, or will the code from MQL4 work on MQL5 to have the same effect?

 
fctwoqula:

I am aware that there is a script to stop all trades and close out all positions in MQL4.


But I am not aware of such code's existence in MQL5.


I couldn't find such script in there - where should I find such script which will stop all trades and close out all positions, or will the code from MQL4 work on MQL5 to have the same effect?


Example of the function of closing all the position in the code of the expert Autotrade, in function "CloseAllPositions".
 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Особенности языка mql4, тонкости и приёмы работы

fxsaber, 2017.04.09 11:40

// Закрывает позиции, описание - https://www.mql5.com/ru/code/17943
sinput int RTOTAL = 4;            // Число повторов при неудачных сделках
sinput int SLEEPTIME = 1;         // Время паузы между повторами в секундах
sinput int Deviation_ = 10;       // Отклонение цены
sinput bool exAllSymbols = false; // false - только текущий, true - все символы

#define _CS(A) ((!IsStopped()) && (A))

bool CloseAllPositions( const bool AllSymbols = true, const int Slippage = 0 )
{
  bool Res = true;
  
  for (int i = OrdersTotal() - 1; _CS(i >= 0); i--)
    if (OrderSelect(i, SELECT_BY_POS) && (OrderType() <= OP_SELL) &&
        (AllSymbols ? true : (OrderSymbol() == Symbol())))
      Res &= OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage);
      
  return(Res);
}

void OnStart()
{
  for (int i = 0; _CS((i < RTOTAL) && (!CloseAllPositions(exAllSymbols, Deviation_))); i++)
    Sleep(SLEEPTIME * 1000);
}
 
fxsaber:
The question is about mql5.
 
Alain Verleyen:
The question is about mql5.
Reason: