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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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:	298
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.
            JesseNinjaTrader Customer Service

            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

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Karado58, 11-26-2012, 02:57 PM
                  8 responses
                  14,825 views
                  0 likes
                  Last Post Option Whisperer  
                  Started by Option Whisperer, Today, 09:05 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Option Whisperer  
                  Started by cre8able, Yesterday, 01:16 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post cre8able  
                  Started by Harry, 05-02-2018, 01:54 PM
                  10 responses
                  3,203 views
                  0 likes
                  Last Post tharton3  
                  Started by ChartTourist, Today, 08:22 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post ChartTourist  
                  Working...
                  X