Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-instrument suggestion/request

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

    Multi-instrument suggestion/request

    I've been working on some multi-instrument indicators and strategies, and I have a suggestion for how to make writing them dramatically easier.

    It's conceptually easy to write a multi-instrument indicator or strategy. In practice, it's pretty hard to make one that's robust, especially in the face of missing data bars.

    It would be fairly easy if Closes[0][x] and Closes[1][x] always referred to the same time & date (for bars of the same time frame). But if either bar series is missing a bar, they don't, they refer to different times or dates. There are a lot of stocks etc. that sometimes have no trades over a 1-minute or 5-minute or longer periods. I've even seen stocks that got out of sync on daily bars.

    It's quite a pain to write code that produces good results when bars are missing, but it can be done, and right now it must be done or you will sometimes have garbage for output.

    There's a fairly simple solution that I'd like to suggest:

    For indicators or strategies which have more than one bar series with the same time frame, you should have the option (settable in Initialize(), defaulting to On) to keep all bars in sync, by ignoring data unless all bar series of that time frame have data. If one bar series is missing a bar, throw away the bars of the other series even if they are present.

    This would make it dramatically easier to write robust multi-instrument indicators and strategies. If programmers could be sure that Closes[0][x] and Closes[1][x] always referred to the same time/date, a whole lot of code/development time/debugging/testing/risk/learning curve/ goes away.

    I expect that it won't really be very hard for you to implement. When processing incoming bars from realtime or from history, just throw away any bars for a time frame if there are any missing bars from that time frame. While it may sound wrong at first to throw away data, in a multi-instrument environment you really don't want the data from one instrument unless you have data from the other(s), and it's a whole lot of work to filter it out at the indicator/strategy level.

    Thanks,

    -Kevin

    #2
    I think this goes back to the idea of being able to easily plot spreads, which is a huge weakness on NT right now. I can understand that coding an autospreader that would work with all supported brokers would be a challange, but being able to plot a spread on a chart between two time series needs to be more intuitive than it is now.

    Comment


      #3
      Spread indicator isn't too hard, I posted one a while back:

      http://www.ninjatrader-support2.com/...ad.php?t=22954

      For a spread, you only need to refer to the current bar [0], and if one bar is missing, then [0] refers to the most recent bar, which is a reasonable thing to do for a spread.

      For indicators that refer back in time (i.e. correlation), it gets much harder, because only certain [x] bars will have a time-synchronized [y] bar in the other series, and x != y. I now know how to deal with it, but it's just way too hard, and it really doesn't have to be.

      Comment


        #4
        Kev call me an idiot (I've been called worse!) but I couldn't get that indicator to plot a line in NT7B5. Can you post a screen shot on your indicator and chart settings for say, CL 01-10 (5Min) and CL 02-10 (5Min) so I can see what I'm doing wrong? Thanks.

        Correllation, Cointegration, etc are probably best done using other tools outside NT but it might be nice to use NT as a database. Calling NT7 data into Matlab or R without an intermediate Excel or CSV thing would be cool.

        Comment


          #5
          Thank you for the suggestion Kevin, but bar objects are independent of each other. We can't just throw out data. Let us say you are running 1 minute bars. If instrument A is a very liquid instrument and B is not so much. Just because B hasn't received any ticks yet for the new minute, we can't negate all of the ticks coming in for instrument A. What happens when B gets a tick 30 seconds into the minute. Then those first 30 seconds of A ticks is gone. Even if we didn't throw them out and just showed them when B updated, it would be extremely delayed and that wouldn't work well either.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Josh, If I am processing 1-Minute bars (with calculate on bar close = true) for 2 instruments, then at the close of the minute, if one of the instruments hasn't received any ticks, in most cases I don't want to see the bar for the other one.

            It's quite complicated to write reliable code that can reference back in time, if Closes[0][x] and Closes[1][x] might refer to different dates/times. You could make NT7 much better for multi-instrument work if you could come up with a way to make [x] always refer to the same date/time for bars of the same timeframe. I'd be fine with throwing away unsynchronized bars, but if that's impractical I encourage you to think of an alternative.

            Thanks,
            Kevin

            Comment


              #7
              MXASJ,

              My spread indicator works with CL 01-10 & CL 02-10; for Symbol2 you need to specify "CL 02-10", and I changed the quantities to .001/-.001 to undo the contract multiplier (with +1/-1 it would plot the spread of the full contract value).

              I made a revision (attached) to allow non-integer quantities, and to display the contract expiry in the indicator label.

              -Kevin
              Attached Files

              Comment


                #8
                Kevin,

                NT is event driven not time driven. Bars do not close at the end of the minute. They close when a tick comes in with a timestamp past the minute. This is the nature of being event driven.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                625 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                359 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                562 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                567 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X