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

can i create an indicator which refers to other indicators?

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

    can i create an indicator which refers to other indicators?

    If so, how do I refer to the other indicators? Do I have to code them into the new indicator? Or can I call them? If so, how do I call them?

    Regards

    Kay Wai

    #2
    Kay, you can just call other indicators in your current indicator script, if your indicator you wish to call is for example named CustomSMA and has two parameters the call could look like this below -

    double myIndValue = CustomSMA(Close, Parameter1, Parameter2)[0];
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Not sure what I'm doing wrong but I keep getting "The name 'result1' does not exist in the current context".

      Here is the code:
      Code:
      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
      double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] D*****erIvalue = tdd*****erI(result1[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]];[/COLOR]
      [/SIZE][/FONT][/SIZE][/FONT]
      result1 is a double value generated from the code and its value is plotted on the chart. It isn't the dataseries.

      If I were to substitute 'result1' with the DataSeries which I have called DeMax, I get the same error message. DeMax is a private DataSeries.

      Could you please assist?

      Regards

      Kay Wai

      Comment


        #4
        Kay, I guess I'm not sure I follow what you like to achieve here - if you would like to calculate an indicator you need pass in a series to the IDateSeries interface indicators would implement, not a double value - if you would like to access a series from another script you would need to call the script that exposes that series, so far example an SMA on the CCI looks like this below :

        double myCCI = SMA(CCI(14), 20)[0];
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand, I'm actually trying to call the values generated from a few indicators to create another indicator based on those values. all the existing indicators have their values stored in a private DataSeries and what I want to do in the new indicator is to get the value from those indicators to ascertain the value I determine for my new indicator.

          For example,
          if (indicator A > 60), then valueX = 1; else valueX = 0;
          if (indicator B >90), then valueY =1; else valueY =0;

          value A = valueX + valueY

          myDataSeries.Set(valueA);

          Trying to create something like the above but have no idea how to call the value of the indicators to the new indicator.

          Regards
          Kay Wai

          Comment


            #6
            Kay, this will unfortunately not work as private DataSeries need to be exposed first before they could be accessed from other scripts - http://www.ninjatrader.com/support/f...ead.php?t=4991
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks Bertrand. Lemme try that link.

              Comment


                #8
                Hi Bertrand,

                I followed the example to exposed the DataSeries, tried to call it to the new indicator and got this message "NinjaTrader.Indicator.Indicator.tdd*****erI() ' is a method, which is not valid in the given context".

                Here is my code:-
                Code:
                [FONT=Courier New][SIZE=2][COLOR=#0000ff]
                [SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000](tdd*****erI().DEMAX[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]part1 = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (tdd*****erI.DEMAX[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]<[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]40[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]part1 = -[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((tdd*****erI.DEMAX[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]40[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) && (tdd*****erI.DEMAX[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]part1 = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [/SIZE][/FONT]
                where part1 is a double, DEMAX is the exposed DataSeries from tdd*****erI indicator.

                This is the code from the exposed DataSeries:-
                Code:
                [FONT=Courier New][SIZE=2]
                [SIZE=2][FONT=Courier New][Browsable([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])][/SIZE][/FONT]
                [SIZE=2][FONT=Courier New][XmlIgnore()][/FONT][/SIZE]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] DataSeries DEMAX[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] DeMax; }[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][Browsable([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])]
                [XmlIgnore()]
                [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ExposedVariable
                {
                [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { Update(); [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] exposedVariable; }
                }
                [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]
                Can you please tell me what I am doing wrong?

                Regards

                Kay Wai
                Last edited by kaywai; 03-20-2011, 07:19 AM.

                Comment


                  #9
                  It looks like you're not calling the indicator correctly in some places of your code - does the snippet below compile?

                  if(tdd*****erI().DEMAX[0] > 60)
                  {
                  part1 = 1;
                  }
                  elseif (tdd*****erI().DEMAX[0]<40)
                  {
                  part1 = -1;
                  }
                  elseif ((tdd*****erI().DEMAX[0] > 40) && (tdd*****erI().DEMAX[0] < 60))
                  {
                  part1 = 0;
                  }
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Bertrand,

                    As I mentioned in my earlier query, it doesn't. I get the error message "NinjaTrader.Indicator.Indicator.tdd*****erI() ' is a method, which is not valid in the given context".

                    I just followed the example from the link you provided earlier. Not sure what I'm doing wrong to be honest...which is why I asked for help.

                    I've attached the code in case you need it
                    Attached Files
                    Last edited by kaywai; 03-21-2011, 08:56 PM.

                    Comment


                      #11
                      Hi Bertrand,

                      Sort of got it fixed. Please ignore my response below.

                      Cheers

                      Kay Wai

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Conceptzx, 10-11-2022, 06:38 AM
                      3 responses
                      60 views
                      0 likes
                      Last Post NinjaTrader_SeanH  
                      Started by f.saeidi, Today, 01:32 PM
                      1 response
                      2 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by mmckinnm, Today, 01:34 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post mmckinnm  
                      Started by traderqz, Today, 12:06 AM
                      9 responses
                      16 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by kevinenergy, 02-17-2023, 12:42 PM
                      117 responses
                      2,766 views
                      1 like
                      Last Post jculp
                      by jculp
                       
                      Working...
                      X