• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No OnBarUpdate calls in Strategy Analyzer

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

    No OnBarUpdate calls in Strategy Analyzer

    Hi,
    I'm going a bit nuts with a multi-timeframe strategy that loads an indicator. It works perfectly fine on a chart.

    In Strategy Analyzer, the indicator does not ever reach OnBarUpdate().

    It completes OnStartUp() sucessfully. Using print statements I can see this, as well as seeing it has loaded hundreds if not thousands of bars of data that it requires. BarsRequired is set to 3. It has enough bars!

    But then it comes to a halt and despite the strategy moving through its bars the indicator does not ever start. It's CurrentBar (if tested from the strategy) always reports as -1.
    A simple print statement at the very head of OnBarUpdate() in the indicator is never executed.

    Please, what can cause this behaviour? I've chucked a few hours at this now and frankly I'm out of ideas.

    Thanks,
    saltminer.

    #2
    Hello saltminer,

    Thank you for the post.

    Could you please copy/paste the section of your script where you are adding the additional series?

    Please also make a test strategy that does not include the custom indicator and see if this still happens. If OnBarUpdate is called after removing the indicator from the strategy, then this narrows down what is causing the issue to the indicator.

    I look forward to your reply.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      to be clearer - OnBarUpdate() is called for the strategy. It is not called in the indicator.
      Therefore removing the indicator from the strategy isn't a useful test.

      I made sure to have the strategy load any of the timeframes the indicator requires. Using Print statements in OnStartUp(), I can verify the indicator has successfully loaded these.

      The indicator contains an enum of timeframes:

      public enum TimeFrameTypes
      {
      Minute = PeriodType.Minute,
      Second = PeriodType.Second,
      Tick = PeriodType.Tick,
      Range = PeriodType.Range,
      Volume = PeriodType.Volume,
      Day = PeriodType.Day,
      Week = PeriodType.Week,
      _OFF_ = PeriodType.Month
      }

      The strategy loads 3 of these (so including the primary chart timeframe that is a total of four). It loads them like this:


      if (timeFrame2_Type != NinjaTrader.Indicator.KNanaSuperTrendMTFv1.TimeFra meTypes._OFF_)
      Add((PeriodType)TimeFrame2_Type,TimeFrame2_Value);
      else
      Add(PeriodType.Minute,1);

      if (timeFrame3_Type != NinjaTrader.Indicator.KNanaSuperTrendMTFv1.TimeFra meTypes._OFF_)
      Add((PeriodType)TimeFrame3_Type,TimeFrame3_Value);
      else
      Add(PeriodType.Minute,1);

      if (timeFrame4_Type != NinjaTrader.Indicator.KNanaSuperTrendMTFv1.TimeFra meTypes._OFF_)
      Add((PeriodType)TimeFrame4_Type,TimeFrame4_Value);
      else
      Add(PeriodType.Minute,1);


      The strategy loads a 1 Minute timeframe if one of the enum timeframes is not required so as to keep the length of BarsArray constant. I have found that useful in the past to avoid problems with hosted indicators and multiple timeframes.

      The indicator does the same loading:



      if (timeFrame2_Type != TimeFrameTypes._OFF_)
      Add((PeriodType)timeFrame2_Type,timeFrame2_Value);
      else
      Add(PeriodType.Minute,1);

      if (timeFrame3_Type != TimeFrameTypes._OFF_)
      Add((PeriodType)timeFrame3_Type,timeFrame3_Value);
      else
      Add(PeriodType.Minute,1);

      if (timeFrame4_Type != TimeFrameTypes._OFF_)
      Add((PeriodType)timeFrame4_Type,timeFrame4_Value);
      else
      Add(PeriodType.Minute,1);


      Then in the OnStartUp() section of each, the loaded DataSeries are Printed out:


      for (int a = 0; a<BarsPeriods.Length; a++)
      Print(Name+" INDICATOR bars "+a+" "+Instruments[a].FullName+" "+BarsPeriods[a].ToString()+" of count "+BarsArray[a].Count);

      With this information I can verify that the strategy and the indicator have four identical dataseries successfully loaded and with hundreds or thousands of bars in each.

      But the indicator NEVER gets to OnBarUpdate() to do anything. Its baffling.

      Cheers,
      saltminer

      Comment


        #4
        Hello saltminer,

        Thank you for the reply.

        Using a variable in the Add() method is not recommended as it does not guaranteed to be reliably obtained while initialize is called. This is likely the reason that you are not seeing OnBarUpdate functionality in the strategy analyzer. NinjaTrader 8 describes this in a note on the NT8 AddDataSeries() help guide page, the same applies for NinjaTrader 7:

        https://ninjatrader.com/support/help...dataseries.htm

        We suggest users add data series using hard coded values in the Add() parameter list like in the examples on the help guide page to avoid this.

        https://ninjatrader.com/support/help.../nt7/?add3.htm

        Please let me know if you see the same behavior after changing this implementation.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          I am aware of this recommendation.
          However, in my testing the settings for the additional timeframes are not being changed from their default values, therefore only one configuration is ever used which is identical to them being hard coded.
          I don't believe this is the problem.

          Any other ideas please?

          saltminer

          Comment


            #6
            Hello saltminer,

            Thanks for the reply.

            I will need to test your strategy to investigate this further.

            Please export the strategy using these instructions:
            https://ninjatrader.com/support/help...t7/?export.htm

            After that, please write an email to platformsupport[at]ninjatrader[dot]com and attach the .zip file to your email. Please also include the link to this forum post in the body.

            I primarily want to test the additional data series as it seems like they are not loading.

            I look forward to your reply.
            Last edited by NinjaTrader_ChrisL; 04-30-2018, 05:31 AM.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by saltminer, Today, 05:19 PM
            0 responses
            3 views
            0 likes
            Last Post saltminer  
            Started by martyn73, Today, 04:18 PM
            0 responses
            2 views
            0 likes
            Last Post martyn73  
            Started by aprendiz, Today, 03:42 PM
            0 responses
            2 views
            0 likes
            Last Post aprendiz  
            Started by 1001111, Today, 09:10 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by usero86, Today, 06:02 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X