Announcement

Collapse
No announcement yet.

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.

    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.

        Comment


          #5
          Great. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          367 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          571 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X