Here is the code:
Replace line 674
orderResponse = AddToCurrentPosition(symbol, type, lots, price, slippage, stoploss, takeprofit, magic);
with:
if (positions > 20)
{
int newLots = lots + PositionLots;
orderResponse = CloseCurrentPosition(symbol, slippage);
orderResponse = OpenNewPosition(symbol, type, newLots, price, slippage, stoploss, takeprofit, magic);
}
else
orderResponse = AddToCurrentPosition(symbol, type, lots, price, slippage, stoploss, takeprofit, magic);
where the max count of open positions is 20.
I can make this code standard in the expert.
Number of 20 can be adjusted experimentally for achieving best performance. We have to take into account that we will loose PositionLots * Spread in that operation.