Topic: Use Trailing stop without settings of strategy

Hi,

we have now a trailing stop integrated in the code. But it uses the trailing from the strategy each. Now i think about how can we change the code so i use a trailing stop for all strategys with same global settings. So the trailing not depends on the strategy but for all on the magicnumber. Maybe @Popov can help.

Re: Use Trailing stop without settings of strategy

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

Re: Use Trailing stop without settings of strategy

Popov wrote:

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

ok thanks i will try