I am trading the following CrossAbove/Below Strategy that enters into position via LimitOrder, below the code:
protected override void OnBarUpdate() {//Enter short if (Position.MarketPosition == MarketPosition.Flat && entryOrder == null && CrossBelow(...)) { entryOrder = EnterShortLimit(0, true, DefaultQuantity, Close[0] + 0.35 * (High[0] - Low[0]),"Short"); barNumberOfOrder = CurrentBar; } //Cancel limit order if not done within lookback period if(CurrentBar > barNumberOfOrder +1 && entryOrder != null) { CancelOrder(entryOrder); } protected override void OnOrderUpdate(IOrder order) { if (entryOrder != null && entryOrder == order) { if (order.OrderState == OrderState.Cancelled && order.Filled == 0) { entryOrder = null; } } } protected override void OnExecution(IExecution execution) { if (entryOrder != null && entryOrder == execution.Order) { if (execution.Order.OrderState != OrderState.PartFilled) { entryOrder = null; } } }
Close[0] + 0.35 * (High[0] - Low[0]
It seems very simple, It works great in back testing, as you can see from the attached, however in real time trading the limit orders often are completely different from what I would expect them to be looking at the high/low/close of the previous bar session. As an example see attached the log of my real time trading, the same code/strategy that in back testing is leaving a EnterShortLimit at 131.55 in real time trading is leaving the order at 131.65. Any idea why this happens?
Please help, this is driving me crazy
Comment