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

Referencing an exposed variable

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

    Referencing an exposed variable

    I have 3 indicators with several exposed variables -- the results of its many calculations. I am trying to write another indicator that looks at the exposed variables of all three.

    Most of the time, this works as expected. For some reason, one variable refuses to be read correctly most of the time. As I have been re-compiling and changing other sections of code, I have seen it work, at least twice this morning, and then stop after the next compile.

    One input indicator has
    Code:
    [Browsable(false)]    
            [XmlIgnore()]        
            public int LTS
            {
                get { return dirLTS[0]; }
            }
    Another is
    Code:
    [Browsable(false)]
            [XmlIgnore()]    
            public int STS
            {
                get { return dirHIST[0]; }
            }
    STS is always read, LTS is typically not. The input indicators work as I have both on the chart and can see when these variables change.

    Every so often, after a new compile, LTS is read correctly. Then the next compile & it is back to always being 0. All I did in the calling indicator was near the beginning of OnBarUpdate
    Code:
                LTS = ERG_L(Input).LTS;
                STS = ERG_S(Input).STS;
    Was I supposed to do something in Initialize or OnStartUp? I do wait for CurrentBar to reach a minimal level before looking at the inputs. I have referenced other indicators and never had this problem.

    #2
    Hello LostTrader,

    One thing is you're missing the Update() call in the properties region. You can see example of this here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I stopped putting Update() in the outputs once I discovered that it forces a re-calculation from bar 0 on the chart -- it can take a full minute for this input indicator to calculate the first pass on a chart -- forcing it to do so again for every single output variable would be a truly asinine waste of resource. There are a dozen exposed outputs.

      However, I found that putting one reference to an input indicator output that is guaranteed to be assigned within the input indicator every single bar will cause one Update automatically, and from then on, all the other exposed variables are correct as well, without forcing additional multiple Update() passes.

      Comment


        #4
        If the goal is to ensure the input indicator has calculated its OnBarUpdate() prior to the calling OnBarUpdate(), then it would be more lgoical to put a SINGLE reference in the calling Indicator to ensure this:
        something like IndicatorName(Input).Update();
        once at the beginning of the caller's OnBarUpdate() where it matters, instead of putting it in every output variable of IndicatorName....

        Comment


          #5
          Thanks for the feedback. We recommend using Update() in the properties region but you're of course free to try other approaches.
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          0 responses
          3 views
          0 likes
          Last Post helpwanted  
          Started by Brevo, Today, 01:45 AM
          0 responses
          7 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X