Please find the trailing stop code I've been testing below. The code works fine expect that the trailing stop doesn't stay fixed. I can see that as the price changes the code will adjust the trailing stoploss but I'm not sure how to fix the stoploss so that as a limit is hit the stop moves and stays fixed until the next target is hit.
I'm not a programmer, I know the issue just not sure how to fix it so the code behaves this way.
Any help would be appreciated.
// Resets stoploss to original value when all positions closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, 10);
}
// If a short position is open all for stoploss modification
else if (Position.MarketPosition == MarketPosition.Short)
{
//Prices hit 5 ticks setstop loss to breakeven
if (Low[0] <= Position.AveragePrice + -10 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice + -2 * TickSize);
}
//Prices hit 8 ticks setstop loss to 2 ticks
if (Low[0] <= Position.AveragePrice + -16 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice + -4 * TickSize);
}
Thanks.
Comment