I am coding a dynamic trailing stop as per the following sample:
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetTrailStop(CalculationMode.Ticks, TrailingStop10);
Trail = 166;
highestHigh = High[0];
}
// If a long position is open, allow for stop loss modification.
elseif (Position.MarketPosition == MarketPosition.Long)
{
// if high of current bar greater than prior high, modify stop loss.
if (High[0] > highestHigh)
{
Trail = Trail - (Factor/10 * (High[0] - highestHigh));
SetTrailStop(CalculationMode.Ticks, Trail);
highestHigh = High[0];
}
The issue is that if the trailing stop value (Trail) < 0 AND the the high of the next bar is lower than that of the previous bar, then the trade exits at the current price of Trail - which is higher than any tick of the current bar. i.e. trade exits in mid-air !
Is this clear ??? ---it is difficult to explain without pictures. I am struggling to attached a screenshot.
thx
David
Comment