This is my code where I am testing canceling order and submitting the new one at the same bar.
When such situation occurs the order is cancelled but the strategy is not placing new order. It works in backtest but does not work in real time.
Please support.
My code:
protected override void OnBarUpdate() { Print("----------"); Print(Time[0]+ " START OrderLong1 = " +OrderLong1); if (Position.MarketPosition == MarketPosition.Long && CurrentBar == bar1 + 5) { ExitLong(); OrderLong1 = null; Print(Time[0]+ " | Zamkniecie otwartej pozycji LONG"); Print(Time[0]+ " OrderLong1 = " +OrderLong1); } if (OrderLong1 != null && Position.MarketPosition == MarketPosition.Flat && CurrentBar == bar1 + 1) { CancelOrder(OrderLong1); Print(Time[0]+ " | Anulowanie zlecenia LONG"); Print(Time[0]+ " OrderLong1 = " +OrderLong1); OrderLong1 = null; Print(Time[0]+ " | OrderLong1 null"); Print(Time[0]+ " OrderLong1 = " +OrderLong1); } if (OrderLong1 == null && Position.MarketPosition == MarketPosition.Flat && Close[0] > Close[1]) { double entry = High[0] + ((3 * 10) + 10) * TickSize; sl = DonchianChannel(5).Lower[0] - 10 * TickSize; OrderLong1 = EnterLongStop(0, true, 1000, entry, "Long 1"); SetStopLoss("Long 1", CalculationMode.Price, sl, false); bar1 = CurrentBar; DrawLine("Long" +CurrentBar, false, 0, entry, -1, entry, Color.Green, DashStyle.Solid, 2); DrawLine("SL "+CurrentBar, false, 0, sl, -1, sl, Color.Red, DashStyle.Solid, 2); Print(Time[0]+ " | Ustawienie zlecenia LONG"); Print(Time[0]+ " OrderLong1 = " +OrderLong1); } Print(Time[0]+ " KONIEC OrderLong1 = " +OrderLong1); }
Comment