Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Common variable between an indicator and a strategy?

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

    Common variable between an indicator and a strategy?

    Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?

    #2
    Originally posted by joemiller View Post
    Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?

    Comment


      #3
      Originally posted by joemiller View Post
      Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?
      You do not really want to use static variables. Even seasoned programmers try to avoid them: there are just too many gotchas.

      Just like the often derided goto statement, there are times when using static variables borders on inevitable, but generally, they are just a PITA.

      If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states.

      Comment


        #4
        reply to Sledge and Koganam

        1)
        when I put the indicator and the strategy in my UserDefinedMethods files,
        which presently are as shown below, will I then be able to have then share a common value?

        2)
        Re: “If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states” …. please forgive me, much appreciated but I have no idea what you are trying to tell me.



        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        /// <summary>
        /// This file holds all user defined strategy methods.
        /// </summary>
        partial class Strategy
        {
        }
        }

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// This file holds all user defined indicator methods.
        /// </summary>
        partial class Indicator
        {
        }
        }

        Comment


          #5
          Hello joemiller,

          Thank you for your post.

          Sledge is correct to use the User Defined Methods. However, you can not share user defined methods created for custom strategies with custom indicators.

          There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies found under Tools > Edit NinjaScript > Strategy.
          There is one UserDefinedMethods.cs file that contain your user defined methods for custom indicators found under Tools > Edit NinjaScript > Indicator.

          Please let me know if I may be of further assistance.

          Comment


            #6
            Originally posted by koganam View Post
            You do not really want to use static variables. Even seasoned programmers try to avoid them: there are just too many gotchas.

            Just like the often derided goto statement, there are times when using static variables borders on inevitable, but generally, they are just a PITA.

            If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states.
            statics, I've only found useful as object creation/removal counters in NT...

            Comment


              #7
              so must I just move, not copy, [and do nothing else] the indicator and the strategy to their respective UserDefinedMethods.cs files?

              if so, will that then allow the indicator and strategy to share common variables?

              Comment


                #8
                Hello joemiller,

                Thank you for your response.

                Unfortunately, the User Defined Methods cannot be shared between strategies and indicators. However, writing items outside of the namespace should make them global.

                Comment


                  #9
                  thank you Patrick,

                  1) does that mean I should forget altogether about UserDefinedMethods files? I suspect obviously not, otherwise why would UserDefinedMethods files ever have entered this dialogue?

                  2) so my understanding now is that I can make variables global between indicators and strategies by integrating the use of UserDefinedMethods files with "writing items outside the namespace". my problem is I don't have the foggiest idea of what that means or what to do to make it happen".

                  if the following request is reasonable ...please just simply do me a great service and give me a short list of a few explicit steps to take from here. I really sincerely appreciate explanations from everyone of why things work or not, but I just don't understand the significance of most of what is explained and therefore cannot make any use of what is presented. after nine posts now I am still dead in the water.

                  Comment


                    #10
                    Originally posted by joemiller View Post
                    thank you Patrick,

                    1) does that mean I should forget altogether about UserDefinedMethods files? I suspect obviously not, otherwise why would UserDefinedMethods files ever have entered this dialogue?

                    2) so my understanding now is that I can make variables global between indicators and strategies by integrating the use of UserDefinedMethods files with "writing items outside the namespace". my problem is I don't have the foggiest idea of what that means or what to do to make it happen".

                    if the following request is reasonable ...please just simply do me a great service and give me a short list of a few explicit steps to take from here. I really sincerely appreciate explanations from everyone of why things work or not, but I just don't understand the significance of most of what is explained and therefore cannot make any use of what is presented. after nine posts now I am still dead in the water.
                    Maybe if you explained in more detail what you are seeking to do? As it is, your general inquiry would point to wanting to access and modify a variable from different classes. In the general sense, that is too broad for a targeted answer, as the method to use will depend on how the classes are related.

                    Comment


                      #11
                      Post #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”

                      I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello joemiller,

                        Thank you for your post.

                        Sledge is correct to use the User Defined Methods. However, you can not share user defined methods created for custom strategies with custom indicators.

                        There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies found under Tools > Edit NinjaScript > Strategy.
                        There is one UserDefinedMethods.cs file that contain your user defined methods for custom indicators found under Tools > Edit NinjaScript > Indicator.

                        Please let me know if I may be of further assistance.
                        My bad.. I assumed there was one.. I didn't read the further description.. The 1st sentence in the help made it appear like the logical option (I haven't set up and udf).... I didn't read the further details.


                        You can create user defined methods (global methods or functions) that can be accessed by all custom indicators and strategies. User defined methods should ONLY be created if you intend to re-use these methods over and over again across different custom indicators or strategies. Otherwise, just code your method logic directly into your indicator or strategy.
                        Last edited by sledge; 10-28-2013, 05:02 PM.

                        Comment


                          #13
                          Originally posted by joemiller View Post
                          Post #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”

                          I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.
                          So the indicator has the static variable and the strategy can read it.

                          Yes it is possible. make the static variable public.

                          Comment


                            #14

                            to be clear, when I make the variable public in the indicator and strategy it doesn't result in the variable becoming one common shared value ... which of course is how I got started on this in the first place.

                            should I move or copy the indicator and the strategy to their respective UserDefinedMethods.cs files?

                            Comment


                              #15
                              Originally posted by joemiller View Post
                              Post #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”

                              I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.
                              A common variable between the indicator and the strategy is a matter of:
                              1. Create the variable in the indicator.
                              2. Expose the variable as public in the indicator. This must be done using the Properties of the variable.

                              You should now be able to access the variable from either entity. Which is what I meant when I wrote: "If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states."

                              To access the variable from the Strategy, you will have to use standard OOP syntax on the indicator variable:
                              indicatorName([]parameters).variableName
                              I still do not understand what you can be wanting to track, so this is just a generalized method that can be used to share any variable that can be properly exposed as public. What are trying to track that is not in the report from the Strategy Analyzer?
                              Last edited by koganam; 10-29-2013, 08:15 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fernandobr, Today, 09:11 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post fernandobr  
                              Started by itrader46, Today, 09:04 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by timmbbo, Today, 08:59 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post timmbbo
                              by timmbbo
                               
                              Started by bmartz, 03-12-2024, 06:12 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              14 views
                              0 likes
                              Last Post Aviram Y  
                              Working...
                              X