Can I somehow test to see if a certain indicator lives on current chart and test for its exposed values ?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Programatically access list of indicators loaded on chart
Collapse
X
-
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 ? -
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
-
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.Originally posted by tickling View PostIs 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 ?
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.
Open the Output Window and you will see the what the return is.Code:if (CurrentBar == 0) for (int index = 0; index < ChartControl.Indicators.Length; index++) Print ("ChartControl.Indicators " + "[" + index.ToString() +"] is " + ChartControl.Indicators[index].Name);
Comment
-
strange error
Originally posted by koganam View PostAfter 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.
Open the Output Window and you will see the what the return is.Code:if (CurrentBar == 0) for (int index = 0; index < ChartControl.Indicators.Length; index++) Print ("ChartControl.Indicators " + "[" + index.ToString() +"] is " + ChartControl.Indicators[index].Name);
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
-
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: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 ?
That is just on principle: I have not yet tried it myself.Code:maSlopeMulti = (MASlopeMulti)ChartControl.Indicators[index];
Comment
-
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
-
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.Originally posted by andrei.reiand View PostAh, 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 ...
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
-
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
-
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.Originally posted by andrei.reiand View Postit'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
-
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
-
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
630 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
566 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment