I am having a problem with setting a stop loss which seems to be due to a gap down in price on the bar after my entry signal triggers. What seems to be happening is that on the close of bar X my short signal triggers so I enter my short. I then calculate my stoploss by adding a number of ticks above my AvgFillPrice. The problem is that on the bar after my entry signal, price has gapped down, so that when my stoploss is entered it is below the Close of the trigger bar. I need to run CalculateOnBarClose = true;
Below is my stoploss code
{
if (order1 != null && order1 == execution.Order && Position.MarketPosition == MarketPosition.Short)
{
order1Target = ExitShortLimit(0, true, 1, order1.AvgFillPrice - profitTarget * TickSize, "order1Target", "order1");
order1StopLoss = ExitShortStop(0, true, 1, order1.AvgFillPrice + stopLoss * TickSize, "order1StopLoss", "order1");
}
elseif (order2 != null && order2 == execution.Order && Position.MarketPosition == MarketPosition.Short)
{
Print(Time[0] + " " + Close[0]);
order2StopLoss = ExitShortStop(0, true, 1, order2.AvgFillPrice + stopLoss * TickSize, "order2StopLoss", "order2");
}
}
How can I get around this issue?
Comment