protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
if (marketPosition == MarketPosition.Flat) return; // do nothing if position is flat
if (marketPosition == MarketPosition.Long && execution.Order.OrderAction == OrderAction.Sell) // if long position was stopped out
{
EnterShortLimit(IQ, Close[0]); // enter short position
SetStopLoss(CalculationMode.Price, Close[0] + StopLossATR * ATR(40)[0] );
}
else if (marketPosition == MarketPosition.Short && execution.Order.OrderAction == OrderAction.Buy) // if short position was stopped out
{
EnterLongLimit(IQ, Close[0]); // enter long position
SetStopLoss(CalculationMode.Price, Close[0] - StopLossATR * ATR(40)[0] );
}
}
I am wondering if it's because the market position cannot be NOT flat and a stop loss order is hit at the same time. Is there something I'm missing, or a different way to approach this?

Comment