Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Indicator vs Strategy Calculate settings

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

    Indicator vs Strategy Calculate settings

    Can you help me understand how strategies and indicators with different calculate settings interplay?

    I have an indicator that works correctly on it's own. It is set to Calculate.OnBarClose

    If I instantiate an instance of the indicator and add it to the chart via my strategy, the indicator works correctly if the strategy is also set to Calculate.OnBarClose. However, if I change the strategy to Calculate.OnEachTick, my indicator stops working correctly, I get incorrect values.

    I am invoking the .Update() of my indicator both in the strategies OnBarUpdate as well as the property definition of my indicator. I started doing this as standard operating procedure because I've had previous indicator issues where different indicator and strategy were receiving updates out of synch leaving the strategy with no values from the indicator occasionally.

    Where am I going wrong?

    #2
    Hello,

    Thank you for the post.

    In this case, the setting of the hosting script would be used. So if the strategy was set to OnEachTick, the indicator should also work that way.

    To get around this, in the indicator you would need to read what the Calculate setting is, and delegate logic based on that. If the logic is OnEachTick, you could use IsFirstTickOfBar to know when a bar changes otherwise OnBarUpdate would denote a Bar close.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Ok, thanks for confirming the behavior of the hosting script, I had missed that in the docs.

      I need to be handling barsAgo indexes differently in an OnEachTick vs OnBarClose indicator, right?

      I think I wasn't doing that correctly because I changed my code to do something like this and it now works correctly in either mode:

      protected override void OnBarUpdate()
      {

      if ( Calculate == Calculate.OnBarClose )
      myBarsAgoIndex = 0;
      else if ( Calculate == Calculate.OnEachTick )
      myBarsAgoIndex = 1;

      if ( IsFirstTickOfBar )
      {
      ...rest of code that now references Close[myBarsAgoIndex], Open[myBarsAgoIndex], etc...
      }
      }


      This results in me referencing the same bar in either mode, right?

      Comment


        #4
        Hello,

        Correct there would be a 1 bar difference in the values being referenced between these modes. When using OnBarClose you would never reference the building bar and when using OnEachTick you do.

        You would need to handle this change if you utilize any BarsAgo or indexes which it looks like you have already.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Great. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          40 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Today, 08:51 AM
          2 responses
          15 views
          0 likes
          Last Post bill2023  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          167 responses
          2,260 views
          0 likes
          Last Post jeronymite  
          Started by warreng86, 11-10-2020, 02:04 PM
          7 responses
          1,362 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Perr0Grande, Today, 08:16 PM
          0 responses
          5 views
          0 likes
          Last Post Perr0Grande  
          Working...
          X