Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please Explain how Data is Loaded

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

    Please Explain how Data is Loaded

    Hello,

    Been lurking for a while and finally decided I'd make a post. I am trying to figure out the way data is loaded and read in NinjaTrader.

    Question 1
    My first question is really an issue I can't seem to get around that has to do with multi-instruments. When I only have instrument on the chart and enable my strategy, everything works fine and looks like this:

    Single Instrument Loaded


    When I add a second instrument using Add("ES 03-12", PeriodType.Day, 1);, NO MATTER how I use BarsInProgress or anything else I've tried to do, it always looks like this:

    My goal was to create an indicator or a method within a strategy that would allow me to generate entry/exit signals based on on calculating something using another indicators price/volume data.

    Two Instruments Loaded


    I eventually found out that you can set the BarsIndex with a the entry/exit methods, but that didn't work either. So any help with this would be appreciated.


    Question 2
    How does data (price data, indicator data, etc) get loaded in relationship to NinjaScript? If I have a chart open and I enable the strategy, does one bar load and then strategy code is executed to see if signal exists, then next bar gets loaded and code is executed again? Or does all the Bar Data get loaded first, then the strategy code goes through each bar and see if it should generate a signal?

    My question arises from the use of a method that requires comparing bars to one another. For example, say I create a method to calculate Spread using High[0] - Low[0] and then call it from OnBarUpdate(), does NT understand, that I want it to calculate spread on each bar and not just the last one?

    Any and all input will be greatly appreciated! I am fairly new to C# and NinjaTrader so I'm still learning a lot.

    #2
    Welcome to our forums and thanks for the post. How much historical data are you loading / is available for all series needed? In a MultiSeries script the OnBarUpdate() would only be called if the BarsRequired period for all involved series is fullfilled.

    NinjaTrader would first load all series needed and then progress through the OnBarUpdate() from CurrentBar == 0 to the right most bar.

    It depends from where and at which point you call the Spread calcs then, if you call it in the OnBarUpdate() and use no filters for BarsInProgress it would do this calculation for any event triggering the OnBarUpdate(), may it be an update from the primary, secondary etc series involved.

    If you want to access historical calculated values for the spread, be sure to use a dataseries object and not just a double value to store it, the double value would only update with each call and thus only contain the last calculated value.



    Hope that helps,

    Comment


      #3
      Hi,

      Sorry for the long response time. Lots going on! I load 4500 bars of data but ES has way less than that. So If I'm looking at AAPL which loads all 4500 bars and try to Add("ES 03-12") which has less than 4500 bars, that would cause an issue? Could I alleviate this using BarsInProgress, CurrentBars and BarsRequired?

      So as for how the data moves, let me see if I understsand. Say for example, I have loaded January 1st, 2011 through December 31st, 2011. All of the series bar data will load first, then OnBarUpdate() will start at Jan 1st, 2011 and at that point Close[0] is referring to Jan 1st, 2011.

      Then on the next OnBarUpdate() it moves to Jan 2nd, 2011 and now Close[0] refers to Jan 2nd and Close[1] would refer to Jan 1st, 2011?

      Comment


        #4
        No worries! It would not create an issue per se, but you would need to understand the first OnBarUpdate() call for the script is then not seen until the BarsRequired set for all series is fullfilled, which is a means to ensure all series / calcs have seen enough data to provide meaningful outputs.

        For your example, it would be start getting called bar per bar for each series, once your BarsRequired is satisfied.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        657 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        373 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X