Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Instruments and Event Firing Order

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

    Multiple Instruments and Event Firing Order

    Hello.

    I am developing a strategy and have come across some weird behaviour, and wanted to know if this is the expected behaviour, and if there is any way of circumventing this.

    The strategy uses the swing indicator, and defines stop losses and take profit targets based on the swing values. The strategy supports multi instruments, by having a parameter where the user can input one or several symbols to be tested.

    The problem here lies in the different behaviour when using the strategy by defining the instruments to use by setting them in the parameter, versus selecting an instrument from the left pane on the backtest window.

    If I select instrument A from the pane, and leave my parameter empty, the stop loss of an opened position is updated on OnBarUpdate, before the end of day events are triggered, and the position is not closed at the previous stop loss, since the stop loss is updated before. If I insert an instrument in my parameter, that instrument is added, but the same position is closed before being able to update its stop loss.

    For what I could detect in the backtest (using Kinetick end of day), it appears that the event OnBarUpdate is called for instrument 0 (BarsInProgress = 0), then the events for closing positions at stop losses, and then OnBarUpdate for the remaining instruments. This does not affect the working of the strategy when I select the instrument from the left pane, but if I use anything other than that, having my tested instruments with BarsInProgress != 0, their events are called too late, and the position is already closed by the time they recalculate the stop loss price based on the swing indicator.

    Is this the usual behaviour of NinjaTrader? Is there a way to make the OnBarUpdate to be called for all the instruments, before triggering the event that closes the positions if their stop loss price has been reached?

    What I want to be able to do is:
    OnBarUpdate 0
    OnBarUpdate 1
    OnBarUpdate N
    EndOfDayPositionsClose

    instead of:
    OnBarUpdate 0
    EndOfDayPositionsClose
    OnBarUpdate 1
    OnBarUpdate N

    Thank you in advance for your time.

    #2
    Hello blunt,

    This would expected case since that is due to the Event-Driven methods.


    If you do not want the Exit to be handled you would either want to set your stop loss to outside of the price action or use Intraday Data.

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello.

      I am unsure if you understood my issue.

      I want the exits to be handled, I just don't know why OnBarUpdate for BarsInProgress 0 is called before the exits are handled, but OnBarUpdate for BarsInProgress 1 to BarsInProgress N are handled after the exits are processed.

      Is there a way to tell ninjatrader to process the exits only after OnBarUpdate has been called for all instruments, and not just the first?

      Comment


        #4
        Hello blunt,

        There is not a way to do this as using Daily Data NinjaTrader will process the orders generated by the OnBarUpdate() immediately after it is finished. This is how the core NinjaTrader Engine works.

        Using Intraday data you still will see the execution of your order after the OnBarUpdate() but the other OnBarUpdate() s will be called as long the order is not filled.

        Let me know if you have any questions.
        JCNinjaTrader Customer Service

        Comment


          #5
          Hello.

          Thank you for the clarification.

          I do have another question, related with the same strategy I am developing. If I set the instruments I want to use in the parameter I have in the strategy, the instruments are added dinamically to the strategy, using Add().

          If I try to backtest several instruments since 2000, for example JPM and GOOG, the backtest only starts in 2004. But if I try to backtest JPM separately, I can see results starting from 2000.

          Is this limitation due to the fact that GOOG data is only available from 2004, and so when I test several instruments in the same strategy, the backtest starts from oldest date across all used instruments?

          Thank you again for your help.

          Comment


            #6
            Correct - all of the Minimum Bars required for each series needs to be satisfied for OnBarUpdate to run your backtest. In the case where historical data is missing for one instrument, you will not see it run until the historical data is available for all.
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            639 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            572 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X