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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mgco4you, Today, 09:46 PM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by wzgy0920, Today, 09:53 PM
        0 responses
        3 views
        0 likes
        Last Post wzgy0920  
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X