Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Possible to cancel and submit opposite pending order on same bar?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Possible to cancel and submit opposite pending order on same bar?

    I am using the managed order approach. I understand that if I submit a long stop entry order (using EnterLongStopMarket) in OnBarUpdate, and then that order does not fill over the next bar, it will automatically get canceled. But if I call EnterLongStopMarket again in OnBarUpdate (ie just before the order gets automatically canceled), I can keep the order alive or even change the entry price. So far so good.

    But I have a problem if I want to cancel that long order and go short instead. If I try to just call EnterShortStopMarket, that order gets ignored (the entry rules in NT8 say this will happen). The only way I can send a reverse entry order is to first let the long be automatically canceled and then send the EnterShortStopMarket in the OnBarUpdate after that. In other words, it takes two bars to submit an opposite stop (or limit) or der - the first bar to let the long stop (or limit) get canceled, and then the second bar to actually submit the short.

    So is it possible to submit an opposite order on the same bar using the managed approach? I have tried explicitly canceling the long order and then calling EnterShortStopMarket right after the call to CancelOrder but that does not work.

    Is it possible to submit opposite orders in one bar using the managed approach, or is this only possible if we use the unmanaged approach? In the unmanaged approach, it appears I would have to add a 1 tick data series and submit the CancelOrder and opposite orders on the 1 tick data series so that my opposite order gets submitted after only a few ticks. Is this really the only option?

    #2
    So It appears that there is also the possibility of submitting orders to a second data series using the managed approach. I see from this page on Advanced Order Handling: https://ninjatrader.com/support/help...?enterlong.htm in "Working with a Multi-Instrument Strategy", that I can add a second data series with the same isntrument as the primary data series, and then use a method like this: EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName). So, if my primary data is M5 on ES futures, I can have my secondary data series be a 1 tick data series. My trade logic goes in OnBarUpdate for M5 (ie if BarsInProgress == 0 then this is the M5 series and I can execute my trade logic). So, if I am currently in (say) a submitted EnterLongStopMarket and that order does not fill, I can use CancelOrder to cancel it. Then in OnOrderUpdate, I can get notified that the order was canceled, and I can call EnterShortStopMarket(1,.....) so that it submits a short stop market entry order on the next tick. Is this the correct approach?

    One more question - does this added 1 tick data series cause problems with backtesting? I thought I read somewhere that tick charts/data series are not supported for backtesting. If this is the case, how do we do backtesting on strategies like this?

    Comment


      #3
      Hello westofpluto,

      If you are wanting to submit an order at the immediate time another order has cancelled, you can detect that order has cancelled in OnOrderUpdate() with OrderState.Cancelled.



      Calling a method like CancelOrder() or EnterLong() does not cause the order to instantaneously change. It takes time for the cancel to be processed. It takes time for an order submission to be processed. It takes time for the position to update. This will happen asynchronously. None of this will happen by the time the code on the line below, in the same run of OnBarUpdate, is executed.

      You could choose to wait until the next run of OnBarUpdate() and likely the cancel or submission will have been processed and the order and/or position may have updated.

      Setting Calculate to OnEachTick would cause OnBarUpdate() to run.
      In historical this would required TickReplay.

      Or you can add a 1 tick series, and OnBarUpdate() will update for both series.

      Below is a link to a forum post that details intra-bar granularity.



      If your connection provides historical tick data for the instrument you are backtesting, this can be used for backtesting (or using for a chart's historical data).
      Loading and processing tick data does require more computer hardware resources for processing.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AttiM, 02-14-2024, 05:20 PM
      12 responses
      213 views
      0 likes
      Last Post DrakeiJosh  
      Started by cre8able, 02-11-2023, 05:43 PM
      3 responses
      238 views
      0 likes
      Last Post rhubear
      by rhubear
       
      Started by frslvr, 04-11-2024, 07:26 AM
      8 responses
      117 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      10 responses
      47 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by rocketman7, Today, 09:41 AM
      3 responses
      13 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X