• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Global Variable?

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

    Global Variable?

    I want to share a variable between indicators and strategies. can I do that with a global variable and if so how and where do I define/declare said variable?

    #2
    Joe, there's unfortunately no global variable per default available.

    If you want to expose anything else from indicator besides the regular exposed plot, that's possible with this technique -

    http://www.ninjatrader.com/support/f...ead.php?t=4991
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand

      WOW! I'm totally overwhelmed by the complexity of making a value calculated in the code for one indicator available to the code in another indicator. I have a vague understanding, at best, of many of the terms and concepts encountered.

      Perhaps I have misstated my problem, which restated is: I calculate a single variable 'redline' in the code for an indicator. I want to make 'redline' available to other indicators and strategies. I was hoping I could do so by somehow making 'redline' global instead of public?

      if necessary, maybe I can simply repeat the calculation wherever needed?

      Comment


        #4
        Correct, then you would either need to expose the variable for access if it's not a plot or reuse the calcs in all scripts where you want to need to it.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Re: 'expose the variable for access'
          In summary, my understanding is that:
          'expose the variable for access' mean 'pass it on'. But I understand that I can't simply pass it on by means of a simple 'Global variable'' concept. Instead I must pattern my 'pass it on' method after the techniques demonstrated in the download link you provided earlier.
          Alternatively I hopefully can explicitly calculate 'redline' everywhere needed. At this time that is obviously the far easier choice for me if it works.

          Re: 'if it's not a plot'
          I'm not sure I understand the meaning or significance of 'if it's not a plot'. 'redline', the variable I want to share, is a variable, not a plot I'm guessing. What is a 'plot'? Is it an indicator which gets plotted, which is an array of values and not a single value?

          If there is not a good reason to not do so, kindly pass on a request to program development to consider adding such a 'Global variable' feature.

          thanks a whole lot for your help. much appreciated.

          Comment


            #6
            Your understanding is correct, this is not a Global Variable concept, but specifically exposing what you wanted to give access to - that being said a Global Variable framework in on our list of feedback and I will make sure to add your vote in as well.

            A plot is a visualized data series from your indicator - the values would for example see in the databox, those are 'auto exposed' if you will.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              You have been VERY helpful ..... saved me tons learning curve time.

              Comment


                #8
                Originally posted by joemiller View Post
                Re: 'expose the variable for access'
                In summary, my understanding is that:
                'expose the variable for access' mean 'pass it on'. But I understand that I can't simply pass it on by means of a simple 'Global variable'' concept. Instead I must pattern my 'pass it on' method after the techniques demonstrated in the download link you provided earlier.
                Alternatively I hopefully can explicitly calculate 'redline' everywhere needed. At this time that is obviously the far easier choice for me if it works.

                Re: 'if it's not a plot'
                I'm not sure I understand the meaning or significance of 'if it's not a plot'. 'redline', the variable I want to share, is a variable, not a plot I'm guessing. What is a 'plot'? Is it an indicator which gets plotted, which is an array of values and not a single value?

                If there is not a good reason to not do so, kindly pass on a request to program development to consider adding such a 'Global variable' feature.

                thanks a whole lot for your help. much appreciated.
                There is no such thing really as a "Global" variable in C#. Something akin to it would be a "static variable". Your Google-Fu should be able to help you find information about it. Heed all the warnings.

                Using static variables is generally a bad idea: they are just sometimes a necessary evil, so one should be careful about using them all willy-nilly. So far, I have no code that uses static variables, but that is simply because I have never needed them, and my coding style is to generally control everything, including exposing outputs, from within that class. That way, everything is self-contained, and I do not need to worry about breaking dependencies when I export my code. Static classes are a different kettle of fish.

                OOP principles generally frown on code that is not controlled directly from its object.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NinjaTrader_Brandon, Today, 01:19 PM
                0 responses
                4 views
                0 likes
                Last Post NinjaTrader_Brandon  
                Started by nedstrader, Today, 01:01 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by tvaughan4, Today, 01:02 PM
                0 responses
                5 views
                0 likes
                Last Post tvaughan4  
                Started by RolloHarper, Today, 12:59 PM
                0 responses
                5 views
                0 likes
                Last Post RolloHarper  
                Started by Aporshnev, Today, 11:11 AM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X