Trailing stop plot not lining up with ApplyStop level

I'm using a trailing stop of 22 points, and am plotting this same 22 points as a trailing stop. I'm finding they don't quite line up, as shown below. What might be a reason for this slight difference please? The difference is always 1 point, so I could just shift the plot down by 1 point, but I'd like to know why it's happening.

ApplyStop(stopTypeTrailing, stopModePoint,22);

trailARRAY = Null;
trailstop = 0;

StopLevel = 1 - 22;


trailARRAY = Null;
trailstop = 0;

for( i = 1; i < BarCount; i++ )
{

   if( trailstop == 0 AND Buy[ i ] ) 
   { 
      trailstop = High[ i ] + stoplevel;
   }
   else Buy[ i ] = 0; // remove excess buy signals

   if( trailstop > 0 AND Low[ i ] < trailstop )
   {
      Sell[ i ] = 1;
      SellPrice[ i ] = trailstop;
      trailstop = 0;
   }

   if( trailstop > 0 )
   {
      trailstop = Max( High[ i ] + stoplevel, trailstop );
      trailARRAY[ i ] = trailstop;
   }

}

Plot( trailARRAY,"trailing stop level", colorRed ) ;

x

1 minus 22 is -21!
So your loop has 21 points stop but not 22 as your Applystop line.

1 Like

Thanks very much for replying, fx.

I can't figure out the reverse (Short version) of the trailing stop shown in the kb, if anyone has a moment please. This is where I'm at.

StopLevelx = 22;

trailARRAYx = Null;
trailstopx = 0;

for( i = 1; i < BarCount; i++ )
{

   if( trailstopx == 0 AND Short[ i ] ) 
   { 
      trailstopx = low[ i ] + stoplevelx;
   }
   else Short[ i ] = 0; // remove excess buy signals

   if( trailstopx > 0 AND high[ i ] < trailstopx )
   {
      cover[ i ] = 1;
      coverPrice[ i ] = trailstopx;
      trailstopx = 0;
   }

   if( trailstopx > 0 )
   {
      trailstopx = Max( high[ i ] - stoplevelx, trailstopx );
      trailARRAYx[ i ] = trailstopx;
   }

}

Plot( trailARRAYx,"trailing stop level", colorgreen ) ;

->

if( trailstopx > 0 AND high[ i ] > trailstopx )

->

trailstopx = Min( high[ i ] - stoplevelx, trailstopx );

1 Like

Works great, thanks again.

With my long trail stop, it now lines up with the exit price (hollow square). But strangely with short trades, it doesn't. Yet I'm using the same ApplyStop for both long and short entries. I've never done a short system before. Do I need to use separate ApplyStop for long and short trades?

x

->

trailstopx = Min( Low[ i ] + stoplevelx, trailstopx );

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.