I've an automated strategy and as a part of it if the price moves 6 ticks in the favor of trade, initial stoploss is brought to breakeven.
But if you were to look at the chart below, for the two short trades via the strategy today, it did not bring the stoploss back to breakeven and instead exited the position at the initial stoploss of 8 ticks.
Here is the code I am using and I have it placed under OnBarUpdate. Can someone please help to understand what could be wrong here?
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, stoplossticks);
}
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price +6 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 6 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is greater than entry price - 6 ticks, set stop loss to breakeven
if (Close[0] < Position.AvgPrice - 6 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
Comment