Close all order in one currency

hello master master goodnight, I want to ask how to make a script on mql4 to close all orders in just one currency only.

example:

I trade in many currencies with a lot of open positions, but when the EURUSD currency I see false position,then all orders in the EURUSD currency will close all position .and positions are pending or which are still open.




// Закрывает позиции, описание - 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);
}

Thank for share,

If I want to change it, and work in one currency only, what should I edit. For example: EURUSD

Run the script on the EURUSD-chart.

Ok…Thank you very much…