Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Share variables between 2 or more indicators

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

    Share variables between 2 or more indicators

    Hello Support.

    I'm developing 2 indicators to calculate position size and Risk, the results of both indicators are shown in data box.

    The Position size tells me how many contracts should I open the trade. The risk indicator show me the maximum risk per day and the risk in points and dollars of the trade.

    The Risk indicator needs to use several values of the Position size indicator, some of these are calculated, like number of contracts and others come from the parameters like risk percentage of account per day, to calculate the máximun risk per day in dollars.

    Im try use public properties but when these are called from the risk indicator, for example PositionSize.Contracts, the following error is displayed:

    'NinjaTrader.Indicator.Indicator.PositionSize(int, double, double, int, double)' is 'method', that is no valid in the context.

    There are any way of share the value of variables between 2 indicators?

    Thank you for advance.

    #2
    Hi Federico,

    It depends if these are both in indicator scripts. If they're both indicator scripts, you can access the plot value simply enough, by calling the indicator.

    Example with SMA:
    double mySMAValue = SMA(14)[0];

    If it's not a plot, you can access it using the technique shown here:


    You are not able to get the input from a user defined field belonging to a specific indicator instance. If you access these values, you'll always get the default value used.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Federico View Post
      Hello Support.

      I'm developing 2 indicators to calculate position size and Risk, the results of both indicators are shown in data box.

      The Position size tells me how many contracts should I open the trade. The risk indicator show me the maximum risk per day and the risk in points and dollars of the trade.

      The Risk indicator needs to use several values of the Position size indicator, some of these are calculated, like number of contracts and others come from the parameters like risk percentage of account per day, to calculate the máximun risk per day in dollars.

      Im try use public properties but when these are called from the risk indicator, for example PositionSize.Contracts, the following error is displayed:

      'NinjaTrader.Indicator.Indicator.PositionSize(int, double, double, int, double)' is 'method', that is no valid in the context.

      There are any way of share the value of variables between 2 indicators?

      Thank you for advance.
      So the PositionSize is an indicator that you wrote or acquired somehow?

      In that case, are you sure that you are calling it with ALL the declared properties? Despite what Intellisense would appear to suggest, you will generally have to call indicators with all their adjustable parameters, even if you are going to use default values.

      Comment


        #4
        Thanks for all Ryan.

        I will try what you mention.

        Comment


          #5
          Thank you Koganan.

          I'm developing oritionSize Indicator.

          The problem is this, I need to call the indicator without parameters. I need to use the values changed for the user on PositionSize into Risk Indicator.
          Last edited by Federico; 07-07-2011, 06:17 AM.

          Comment


            #6
            Is There any way to overload an indicator? that's mean, any way to create an indicator with 2 constructors.

            For example, to call indicator without parameters and call indicator with parameters.

            Thanks

            Comment


              #7
              Originally posted by Federico View Post
              Thank you Koganan.

              I'm developing oritionSize Indicator.

              The problem is this, I need to call the indicator without parameters. I need to use the values changed for the user on PositionSize into Risk Indicator.
              Is the PositionSize not being calculated off the user inputs?

              Comment


                #8
                Hello Hoganam.

                Thank yopu for your interest.


                Really I do this in only one indicator and give options to show or not data for risk. It's is more a fad.

                In short, I try to do this:

                In PositionSize Indicator, user can set parameters like account size, loss percent per day, and others; and shown in data box, the quantity of contracts to trade, the stop size and the minimum target.

                The risk indicator must use account size and lost percentage per day (both, set for the user in PositionSize) to show maximum ammount of risk per day, and must use number of contracts (calculated in PiositionSize) to show risk (in $) for the trade.

                Thanks
                Last edited by Federico; 07-07-2011, 09:03 AM.

                Comment


                  #9
                  Originally posted by Federico View Post

                  The risk indicator must use account size and lost percentage per day (both, set for the user in PositionSize) to show maximum ammount of risk per day, ...

                  Thanks
                  Then these parameters, at the very least, must be passed when you call the indicator. As they are user variables, you can expose them as doubles, so that you can capture them for calling the indicator.

                  Comment


                    #10
                    Hello Koganam.

                    I don't understand what you say. I have wrote 2 samples indicators (Indicator1 and Indicator2). In Indicator1 user can set parameters; Indicator2 use parameters and calculations from Indicator1 to generate new results. Can you review these.

                    I would appreciate if you can review.

                    Thank you for advance.
                    Attached Files

                    Comment


                      #11
                      Originally posted by Federico View Post
                      Hello Koganam.

                      I don't understand what you say. I have wrote 2 samples indicators (Indicator1 and Indicator2). In Indicator1 user can set parameters; Indicator2 use parameters and calculations from Indicator1 to generate new results. Can you review these.

                      I would appreciate if you can review.

                      Thank you for advance.
                      I will take a look after the market closes.

                      Comment


                        #12
                        OK. Thank you very much.

                        Comment


                          #13
                          Originally posted by Federico View Post
                          Hello Koganam.

                          I don't understand what you say. I have wrote 2 samples indicators (Indicator1 and Indicator2). In Indicator1 user can set parameters; Indicator2 use parameters and calculations from Indicator1 to generate new results. Can you review these.

                          I would appreciate if you can review.

                          Thank you for advance.
                          While you could probably do what you are attempting to do using static variables to pass data between the 2 classes, for me, there is a much simpler approach, simply because NinjaTrader does not make it easy to access a particular instance of a class.

                          Think of Indicator1() as simply a processor of data, that you call when you need it, (standard OOP stuff) by encapsulating its data and structures in a class.

                          Then all you need to do it call Indicator1() from Indicator2() with parameters that match what you want Indicator1() to process. In other words, add parameters to Indicator2 that would be the parameters that need to be used in Indicator1(), then call Indicator1() from Indicator2() with those user supplied parameters. What this means is that NOTHING needs to be specified in Indicator1() at all, and it does not need to be running for Indicator2() to function. Indicator1() just needs to have the correct inputs, as dummy parameters, so to speak.

                          As an analogy, how would you process the WMA, using the RSI as input? You would simply write your WMA indicator to have the correct inputs for the RSI, and then you would pass them in directly to the RSI indicator that is being processed by the WMA code.

                          In this instance, Indicator1() is little more than a helper class. You just have to use it as such. The notion of calling it without parameters does not exist, unless you are going to use hard-coded variables that never change. If the indicator solicits input, it MUST be called with the inputs specified.
                          Last edited by koganam; 01-25-2014, 11:46 AM.

                          Comment


                            #14
                            So I did.

                            I understand the NinjaTrader Scripts not have capabilities to share variables.

                            What I wanted to make is that user can use Indicator1 independently without use Indicator2 necessarily. And if user use indicator2, will not have to set parameters again.

                            I'll do this in a single indicator and put options to show or not the risk data.

                            Thank you very much again.

                            Comment


                              #15
                              Originally posted by Federico View Post
                              So I did.

                              I understand the NinjaTrader Scripts not have capabilities to share variables.

                              What I wanted to make is that user can use Indicator1 independently without use Indicator2 necessarily. And if user use indicator2, will not have to set parameters again.

                              I'll do this in a single indicator and put options to show or not the risk data.

                              Thank you very much again.
                              Well, the solution that I have outlined does leave Indicator1() as a separate entity that may be used on its own. That is part of the reason why when programming in NT, I generally recommend one class per file, instead of putting helper classes in the same file as the main class.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X