You can make a "MQL script" that loops over all the open positions and modify the SL as needed.
You can make a separate script for each case.
Here is how we loop over the positions:
for(int i = PositionsTotal() - 1; i >= 0; i -= 1)
{
const ulong ticket = PositionGetTicket(i);
if(ticket == 0 || !PositionSelectByTicket(ticket))
continue;
const string posSymbol = PositionGetString (POSITION_SYMBOL);
const long posMagic = PositionGetInteger(POSITION_MAGIC);
// ...
}
Take a look at these two functions:
- GetTrailingStopPrice - it calculates the new value of Traling SL according to the current price and a given Stop Loss
- ManageTrailingStop - it either closes a position or modifies it if the SL needs trailing
- ModifyPosition - does the actual SL modification (Trailing)
Look for these function in a Portfolio Expert or in a single Expert file