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

Programatically access list of indicators loaded on chart

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

    Programatically access list of indicators loaded on chart

    Is there a way to know programatically in run time which indicators are currently running on a chart ?
    Can I somehow test to see if a certain indicator lives on current chart and test for its exposed values ?

    #2
    Hello tickling,

    Thank you for your post.

    Unfortunatley, there is no method or function available in NinjaScript to pull the indicators applied to a chart.

    Comment


      #3
      Thanks. Is this something that you are willing to consider ? It can allow for example a strategy that has logic dependent on current user-selected indicators.

      Comment


        #4
        Hello tickling,

        Thank you for your response.

        I will forward this to our development team as a suggestion. However, you can add the indicators to your strategy and set a user variable that disables or enables different logic and/or indicators added through the code. Please let me know if you have any questions.

        Comment


          #5
          Originally posted by tickling View Post
          Is there a way to know programatically in run time which indicators are currently running on a chart ?
          Can I somehow test to see if a certain indicator lives on current chart and test for its exposed values ?
          After I make the usual caveat about ChartControl being unsupported, and so risky to use, as NT can change it anytime that they wish with no notice (that is what unsupported portends), the indicators on a chart are merely another collection of objects, so you can query them.

          Here is some code to do so, and output their names. You are most certainly going to have to massage the code to get what you seek, but evidently each indicator on the chart can be individually accessed.

          Code:
          if (CurrentBar == 0) 
                          for (int index = 0; index < ChartControl.Indicators.Length; index++) 
                              Print ("ChartControl.Indicators " + "[" + index.ToString() +"] is " + ChartControl.Indicators[index].Name);
          Open the Output Window and you will see the what the return is.

          Comment


            #6
            Hello tickling,

            Thank you for your suggestion on how we can improve our product. It has been inserted into our tracking system with the unique ID # 2671

            Comment


              #7
              Thanks for considering it. I would just add that it could also be useful to have access to the parameters used for each such indicator that is currently applied on the current chart. Just my two cents.

              Comment


                #8
                strange error

                Originally posted by koganam View Post
                After I make the usual caveat about ChartControl being unsupported, and so risky to use, as NT can change it anytime that they wish with no notice (that is what unsupported portends), the indicators on a chart are merely another collection of objects, so you can query them.

                Here is some code to do so, and output their names. You are most certainly going to have to massage the code to get what you seek, but evidently each indicator on the chart can be individually accessed.

                Code:
                if (CurrentBar == 0) 
                                for (int index = 0; index < ChartControl.Indicators.Length; index++) 
                                    Print ("ChartControl.Indicators " + "[" + index.ToString() +"] is " + ChartControl.Indicators[index].Name);
                Open the Output Window and you will see the what the return is.

                Well, if things were that simple. I can indeed iterate the indicators on a chart, but when I want to grab the one I'm interested in, if I don't cast the return of ChartControl.Indicators[index] to my indicator type, I get an error:
                ( Cannot implicitly convert type 'NinjaTrader.Indicator.IndicatorBase' to 'NinjaTrader.Indicator.MASlopeMulti'. An explicit conversion exists (are you missing a cast?) )

                If I cast explicitly through: maSlopeMulti = ChartControl.Indicators[index];
                Then I get the following error:

                **NT** Error on calling 'OnBarUpdate' method for strategy 'SlopStrategy/1463353c221946d3b95b56ff3ad1b2c7': Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                But the types are the same ... the cast should succeed, isn't it ?

                Else, how do you access methods/attributes of your indicator ?

                Comment


                  #9
                  Originally posted by andrei.reiand View Post
                  ...

                  If I cast explicitly through: maSlopeMulti = ChartControl.Indicators[index];
                  Then I get the following error:

                  **NT** Error on calling 'OnBarUpdate' method for strategy 'SlopStrategy/1463353c221946d3b95b56ff3ad1b2c7': Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                  But the types are the same ... the cast should succeed, isn't it ?

                  Else, how do you access methods/attributes of your indicator ?
                  I do not see an explicit cast there. Cast it to the type/class that you are trying to use. I presume that it is MASlopeMulti, so try:
                  Code:
                  maSlopeMulti = (MASlopeMulti)ChartControl.Indicators[index];
                  That is just on principle: I have not yet tried it myself.

                  Comment


                    #10
                    Ah, my fault when pasting - the explicit cast was there, hence I get error:

                    Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                    Equally, that is not just on principle ... it should work if it's clean c# ... we have two identical types here ...

                    Comment


                      #11
                      Originally posted by andrei.reiand View Post
                      Ah, my fault when pasting - the explicit cast was there, hence I get error:

                      Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                      Equally, that is not just on principle ... it should work if it's clean c# ... we have two identical types here ...
                      Not knowing the parts of your code, it is not possible for me to see what may not be kosher. Regardless, the cast does work, as far as I can see. Here is an example.
                      Code:
                      //Variables
                      		private SMA	_smaTest;
                      Code:
                      //OnStartUp()
                      			Print("Indicators Enumerated from 'for' loop");
                      			for (int index = 0; index < ChartControl.Indicators.Length; index++)
                      			{
                      				Print(String.Format("ChartControl.Indicator[{0}] : {1}", index, ChartControl.Indicators[index].Name));
                      				if (ChartControl.Indicators[index].Name == "SMA") this._smaTest = (SMA)ChartControl.Indicators[index];
                      				if (this._smaTest != null) Print ("SMA Period : " + this._smaTest.Period);
                      				else Print("That one was not an SMA!");
                      			}

                      Comment


                        #12
                        it's always working with SMAs, isn't it ... too bad they're a bit useless in systems' development

                        My code is pretty simple:

                        1) Take the MASlopeMulti indicator from BMT site (search for it, it's easy to find) & compile it.
                        2) Add it to a chart.
                        3) Build a simple strategy that iterates through the chart's indicators, where you add an MASlopeMulti variable, find the MASlopeMulti index using the for loop and assign the found object to your variable:

                        maSlopeMulti = (MASlopeMulti)ChartControl.Indicators[index];
                        It compiles just fine ... if you try to apply the strategy to a chart, you get the error:

                        Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                        should't be rocket science, it should work.

                        Comment


                          #13
                          Originally posted by andrei.reiand View Post
                          it's always working with SMAs, isn't it ... too bad they're a bit useless in systems' development

                          My code is pretty simple:

                          1) Take the MASlopeMulti indicator from BMT site (search for it, it's easy to find) & compile it.
                          2) Add it to a chart.
                          3) Build a simple strategy that iterates through the chart's indicators, where you add an MASlopeMulti variable, find the MASlopeMulti index using the for loop and assign the found object to your variable:

                          maSlopeMulti = (MASlopeMulti)ChartControl.Indicators[index];
                          It compiles just fine ... if you try to apply the strategy to a chart, you get the error:

                          Unable to cast object of type 'NinjaTrader.Indicator.MASlopeMulti' to type 'NinjaTrader.Indicator.MASlopeMulti'.

                          should't be rocket science, it should work.
                          I simply gave you an example. I picked SMA because it was the first that we all tend to think about. They are all classes of the same type and should work the same way. Unfortunately, I do not have download rights at BMT, so I cannot test your particular indicator. Test with the SMA. If that works, then you know that the issue is something with how your indicator is written.

                          Comment


                            #14
                            Wont show second panel indicators

                            Hello, this approach won't show the indicators on my second panel. All of them from the first panel show fine. Is there a way to show the indicators on the second (or greater) panel.

                            Comment


                              #15
                              Hello Doogiefala,

                              Thank you for your post and welcome to the NinjaTrader Support Forum!

                              You can set the Overlay in the indicator's Initialize() method to false. For information on Overlay please visit the following link: http://ninjatrader.com/support/helpG...t7/overlay.htm

                              Please let me know if you have any questions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              7 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by merzo, 06-25-2023, 02:19 AM
                              10 responses
                              823 views
                              1 like
                              Last Post NinjaTrader_ChristopherJ  
                              Started by frankthearm, Today, 09:08 AM
                              5 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X