• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


NT8: multi-frame syntax

  • Filter
  • Time
  • Show
Clear All
new posts

    NT8: multi-frame syntax

    Dear NT team,

    I am experiencing issues with backtesting a multi-frame strategy in NT8 RC2. Here is the background:
    1. Main instrument frame is set for 3 minutes
    2. BarsArray[1] is set to 100 tick, same instrument as main
    3. strategy includes user coded classes performing various tests, including tests using with indicator values. These custom classes hold nested references to NT factory indicators, either for the main instrument or BarsArray[1] (an so one instance of the test class is working with the main instrument, another - with the 100 tick series)
    4. AddDataSeries() for the 100 tick frame is called from State.Configure
    5. NT factory indicators working with the main instrument are initialized in State.Configure
    6. NT factory indicators working with BarsArray[1] are initialized in State.DataLoaded
    7. IsInstantiatedOnEachOptimizationIteration = false;

    The main issue is that in backtesting through analyzer an out of range exception is raised when an indicator tries to access price series (eg DM accesses High[0]). In debug mode, I can see that the price series has no elements at that time. Now, I think that the optimizer always runs multithreaded, so I cannot state this with confidence, but expect that the High series being accessed then is for BarsArray[1]. Importantly, an exception is NOT raised if the strategy is simply applied to a chart rather than backtested in an analyzer. (so somehow this suggests that either High is not reflected when the indicator value is being used or that the test is prior to any bars being "added" to Highs).

    In the above context, could you please help with the following Qs to try to narrow down the issue:
    • are there any particular issues to consider when using nested indicator references as per item 3 above. To be clear, I am not asking here about re-setting user variables for each optimizer pass: this is obvious and in this particular instance cannot cause an exception of the type described
    • NT helpguide states that AddDataSeries() cannot be used dynamically. However, does the same apply to indicators working with BarsArray[1]? Eg, is it legit to have in State.DataLoaded: if (bTestDMUserFlag == true) { myDM = (BarsArray[1], iPeriod); myTestClass.myDM = myDM; }
    • in NT factory sample strategies references to indicators using BarsArray[1] are being tested for null values in OBU and then (re-)initialized (these strategies have code in OBU along the following lines: if (adx1 == null) adx1 = ADX(BarsArray[1], 14);) What is the purpose here? Would it not be sufficient to initialize adx1 reference in DataLoaded without any additional OBU checks? Other threads seem to simply use DataLoaded (eg here)?
    • do you know of any other likely reason(s) why an exception could be raised as described above?

    Thank you,
    Last edited by roman_ch; 11-04-2016, 10:15 AM.

    Hello roman_ch,

    Thank you for your post.
    1. Just as you said, I believe this is due to the data just not being there yet. So I would recommend a CurrentBars check on each BarsArray added. For Example:
      protected override void OnBarUpdate()
          // Checks to ensure all Bars objects contain enough bars before beginning.
          // If this is a strategy, use BarsRequiredToTrade instead of BarsRequiredToPlot
          if (CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot || CurrentBars[2] <= BarsRequiredToPlot)
      Taken from Using Bars Objects as Input to Indicator Methods: http://ninjatrader.com/support/helpG...dicatorMethods

    2. Since you are adding the data series in your strategy and not the indicator's code then you do not need to worry about the dynamic adding of the data series since you are not doing this.
    3. You are correct on the instantiation of the objects. This should be fine to do so in DataLoaded.
    Patrick H.NinjaTrader Customer Service


      Hi Patrick,

      Many thanks, great answer.

      Just as a quick update for the benefit of the forum, it seems that the NT documented approach re multi-frame initialization works for indicators, but not for strategies. Initialising BarsArray[>0] indicators in DataLoaded either caused exceptions or "incorrect" optimizer behaviour (eg in the attached screenshot the iterations no. is frozen at 9, but the optimizer continues to run as per the output prints). This only applies to the optimizer (not backtesting over a single run or historical performance stats). A strategy using the DataLoaded approach will also work fine in a chart. However, the optimizer work only when initializing these indicators in Configure. For purposes of development, I feel this (ie, Configure) to be is a much better option consistent with the general structure of SetDefault, Configure, DataLoaded events, so I would keep it this way.

      Best regards,
      Attached Files


      • Latest Posts


        Topics Statistics Last Post
        Started by Impeesa, Today, 09:19 AM
        0 responses
        1 view
        Last Post Impeesa
        by Impeesa
        Started by halozone, Today, 08:33 AM
        1 response
        Last Post NinjaTrader_Jim  
        Started by persoguillermo, Yesterday, 04:38 PM
        1 response
        Last Post NinjaTrader_Marco  
        Started by algunion, Today, 03:56 AM
        0 responses
        Last Post algunion  
        Started by memonolog, Today, 03:22 AM
        0 responses
        Last Post memonolog