Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling indicator members from within another indicator.

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

    Calling indicator members from within another indicator.

    Hi guys,

    I have written Indicator1 which accepts 2 parameters and appears to work fine and do what I want it to.

    I have created Indicator2 which uses the output of Indicator1. (Indicator1 actually uses a Dictionary to store key-value pairs rather than a Series or DataSeries object, since the indicator stores events (bar index, value) )l

    Basically I create an instance of the Indicator1 object inside Indicator2 and initialize it. All compiles fine.

    However, when I go to call members of Indicator1 none of the values are updated bar-by-bar - they are all set to their initial values i.e. zero.
    This is true even if I create a simple int member of Indicator1 to store the CurrentBar.

    e.g.
    Code:
    //inside Indicator1
    public int dummy = 0;
    
    protected override void OnBarUpdate()
    {
       dummy = CurrentBar;
    }
    Code:
    //inside Indicator2
    private Indicator1 myIndicator;
    
    if(State == State.DataLoaded}
    {
       myIndicator = Indicator1(parameter1, parameter2)
    }
    
    protected override void OnBarUpdate()
    {
       Print(dummy);
    }
    The printed value of dummy remains stuck at 0 on each bar however.

    Any ideas?

    thanks

    #2
    Hello trader_rick,

    Thank you for the post.

    You can force Indicator1 to update by calling the Update method right before you request data from inside of indicator2
    Code:
      //inside Indicator2
    
    private Indicator1 myIndicator;
    if (State == State.DataLoaded)
    {
     myIndicator = Indicator1(parameter1, parameter2)
    }
    protected override void OnBarUpdate() {  
     MyIndictor.Update();
     Print(myIndicator.dummy);
    }
    Please let me know if I can assist further.
    Last edited by NinjaTrader_ChrisL; 12-05-2018, 03:45 PM.

    Comment


      #3
      Thanks Chris, that did the trick!

      But I'm curious - for example when Bollinger calls an SMA object (i.e. a built-in indicator) there is no need to call Update(). Also, the examples which use Series or DataSeries to store indicator values don't seem to require a call to Update() either. Any particular reason for this that I should know about?

      thanks once again

      Comment


        #4
        Hello trader_rick,

        Thank you for the reply.

        Using Update is just a formality to make sure that the OnBarUpdate function is activated for the child indicator. It can be used to synchronize indicators that calculate on each tick. In the original code snippet, you did not use the dot operator to access the "dummy" variable, that was likely the source of the problem.

        Please let me know if I can assist further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X