Can I somehow test to see if a certain indicator lives on current chart and test for its exposed values ?
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!
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
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
-
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.
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.
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
-
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 ?
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
-
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
-
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 mjairg, 07-20-2023, 11:57 PM
|
3 responses
213 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
||
Started by TheWhiteDragon, 01-21-2019, 12:44 PM
|
4 responses
544 views
0 likes
|
Last Post
by PaulMohn
Today, 04:09 AM
|
||
Started by GLFX005, Today, 03:23 AM
|
0 responses
3 views
0 likes
|
Last Post
by GLFX005
Today, 03:23 AM
|
||
Started by XXtrader, Yesterday, 11:30 PM
|
2 responses
12 views
0 likes
|
Last Post
by XXtrader
Today, 03:07 AM
|
||
Started by Waxavi, Today, 02:10 AM
|
0 responses
7 views
0 likes
|
Last Post
by Waxavi
Today, 02:10 AM
|
Comment