Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order enters and exits on same bar

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

    Order enters and exits on same bar

    I am doing some testing using a strategy and running into the following situation. Assume there's a breakout bar that forms and the strategy goes long on high+1 tick. If the stop order is not triggered in the next bar and since NT cancels the order if not filled in the strategy, I reenter the stop order long. The logic works very well with the intended consequences except for the following. I cannot track if the strategy enters and exits an order on the same bar, hence if that happens, my code does not know, and re-enters the long stop order of the initial breakout.

    Is there a way I can prevent this from happening? I know how to do it for real-time where I set the Calculate On Bar Close to False, and hence monitor each tick, but this defeats the purpose of backtesting accurately the results.

    Any help would be appreciated.

    Thanks.

    #2
    Hi Shadowfax,

    You could add a condition to your entries that checks the number of bars since exit. A convenient feature of this method is that it returns a value of -1 before the first exit, so could use something like this:

    if (myEntryConditions && (BarsSinceExit() == -1 || BarsSinceExit() > 0))
    {
    //EnterHere
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response Ryan. Is there a way to execute some code as soon as a price hits the buy stop order, or as soon as the order is executed/filled without having to dive too deep into event-handling, etc.?

      Thanks.

      Comment


        #4
        There's unfortunately no way to do this without working with the advanced event handlers: OnExecution for order fills. This sample can get you started on monitoring for filled order states for a given order and taking action.

        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks. That did it...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          670 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X