I am trying to add to my strategy a trailing stop. The below code I was playing around with is not working well.
When a trade is entered. A preset stop loss is set. After a bar candle move I would like the trailing stop start based on the high/low (high if a sell, low if a buy) of the previous candle.
The code is partially working for me, except if after several candles there's an inside bar it stops and exit the strategy do to an error in putting the new SL. I would like the SL to remain with the past candle if there is a new inside bar candle that does not take out the high or low the previous candle.
// Set 7
if ((Position.MarketPosition != MarketPosition.Flat) && (BarsInProgress >= 1))
{
if ((Position.MarketPosition == MarketPosition.Short)
&& (Open[0] < High[1]) && ((High[1] - Open[0])>3))
{
SetStopLoss(CalculationMode.Price, High[1]);
}
else if ((Position.MarketPosition == MarketPosition.Long)
&& (Open[0] > Low[1]) && ((Open[0] - Low[1])>3))
{
SetStopLoss(CalculationMode.Price, Low[1]);
}
else return;
}

Comment