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

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 -

    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 gemify, 11-11-2022, 11:52 AM
                6 responses
                803 views
                2 likes
                Last Post ultls
                by ultls
                 
                Started by ScottWalsh, Today, 04:52 PM
                0 responses
                3 views
                0 likes
                Last Post ScottWalsh  
                Started by ScottWalsh, Today, 04:29 PM
                0 responses
                7 views
                0 likes
                Last Post ScottWalsh  
                Started by rtwave, 04-12-2024, 09:30 AM
                2 responses
                22 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Started by tsantospinto, 04-12-2024, 07:04 PM
                5 responses
                70 views
                0 likes
                Last Post tsantospinto  
                Working...
                X