Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling a custom indicator from another indicator

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

    Calling a custom indicator from another indicator

    Hi,
    I'm attempting to retrieve the value of a plot in another indicator (PTline) which has three parameters, all boolean.
    In the calling script, (in State.DataLoaded) I'm using an instruction of the form:
    PlotVal = PTline(true, false, false).PT[0] where PT is a public series<double> in PTline.
    However, no value is returned.
    Is there another step I need to complete in order to retrieve the plot values?

    #2
    Hello Scotty33,

    You need to call the indicator in OnBarUpdate to get values, DataLoaded would just be to create a variable of the indicator but you would not use it there.

    Comment


      #3
      Thanks for your reply Jesse.
      I included a call to the indicator in OnBarUpdate, but still don't get any values. Do I still need to include a reference to the called indicator in OnDataLoaded? If so, does that reference use the same format as the call?

      Comment


        #4
        Hello Scotty33,

        I would suggest doing the following so you can have the platform generate the correct code to use the indicator. In the strategy builder create a simple condition that uses that indicator, it can be anything you just need to use it once then click view code. You should see a private variable created, the indicator is created in DataLoaded and then the indicator variable is used in OnBarUpdate.

        You can also see the following sample which shows how to create an indicator that exposes a series and then a strategy that accesses it.



        With either of these approaches it would be the same code used in an indicator accessing another indicator.

        Comment


          #5
          Hello Jesse,
          Thanks for your reply.
          I tried the Strategy Builder approach but when I get to the Condition Builder and click on it, I get the following error:
          Click image for larger version

Name:	Strategy Builder Error.png
Views:	1478
Size:	12.1 KB
ID:	1270528
          Once it reaches this point, it's impossible to continue and the only way to exit is to use the Task Manager to end the NinjaTrader task.
          Thinking that it might need a newer version of the .NET framework, I downloaded the latest .NET version, but still get the same error.

          Looking at the example you suggested, I can see that it explains how to expose a series, but where is the strategy to access it? I expanded the Properties section that is flagged as important, but that doesn't fully explain things (at least to me). Also, you had mentioned the creation of the variable in DataLoaded, but there's no mention of DataLoaded in the example.
          Do you have an example of one custom indicator accessing the plot values of another custom indicator?

          Comment


            #6
            Hello Scotty33,

            You would have to look at the strategy in that sample to see how the indicator is used. Its the same to call an indicator from a strategy or indicator so there is no specific sample showing calling a series from another indicator. You can see indicators that call other indicators plots by using the NinjaScript editor. A lot of the stock indicators reference other stock indicators. for example the APZ accesses the EMA.

            If you are getting errors while opening the builder I would suggest to re install the platform to make sure all the core files are present and correct.

            Comment


              #7
              Hello Jesse,
              Thanks for your help.
              I finally got this working. However, another problem has cropped up.
              In the host script that accesses the PTline indicator, I have the following statement :

              Code:
              private PTline PTline1;
              and PTline1 is used to access the values from PTline, which I set up as a standalone indicator for testing.
              Now, I want to add the PTline indicator to an existing package of indicators, PTpack, but when I change the namespace declaration in PTline from
              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              to
              Code:
              namespace NinjaTrader.NinjaScript.Indicators.PTpack
              the compilation throws an error in the host script accessing the indicator, saying that, in the line,

              Code:
              private PTline PTline1;
              PTline is a method but is used like a type.
              Nothing has changed apart from adding the .PTpack to the namespace declaration in PTline.
              How do I resolve this, so I can add PTline to the package?

              Thanks in advance for any help.​

              Comment


                #8
                Hello Scotty33,

                Declare the variable using the fully qualified namespace path.


                private NinjaTrader.NinjaScript.Indicators.PTpack.PTline PTline1;​
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Chelsea. That worked.

                  Comment


                    #10
                    Hi!

                    I am also trying to use a plot from one of my custom indicators in another one. I followed Jesse's advice from earlier in this thread, and I have gotten as far as receiving this compile error:

                    Code:
                    NinjaScript File,Error,Code,Line,Column,
                    PrintTag.cs,Cannot implicitly convert type 'NinjaTrader.NinjaScript.Series<double>' to 'double',CS0029,229,15,
                    
                    ​
                    I looks to me like both types are double, so I'm not sure what the problem is.

                    Here is the code I am using to call/initialize the indicator:

                    Code:
                    public class MyIndicator : Indicator
                        {
                            private MyOldIndicator MyOldIndicator1;​
                    .......
                    
                    else if (State == State.DataLoaded)
                                {                
                                    double myDouble = 2.5;
                                    float myFloat = (float)myDouble;
                                    MyOldIndicator1  = MyOldIndicator(Close, myFloat);
                                }​
                    ........
                    
                    protected override void OnBarUpdate()
                    {
                      .........
                               MyVariable = MyOldIndicator1.HighLine;
                      .........
                    }
                    All of this is code that was generated by the Strategy Builder, so I'm not sure why it doesn't work.
                    Last edited by NjTMatthew; 08-28-2024, 10:46 AM.

                    Comment


                      #11
                      Hello NjTMatthew,

                      It looks like you forgot the bars ago, you should have [0] at the end of that code to get a double from the series.


                      MyVariable = MyOldIndicator1.HighLine[0];

                      Comment


                        #12
                        Yup, that worked. Thank you!

                        Comment

                        Latest Posts

                        Collapse

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