![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Certified NinjaScript Consultant
|
What is the best approach to access a custom indicator from within a strategy given the following general case example:
myCustomIndicator has three parameters (parmA, parmB, parmC) and outputs four plots - "plot1", "plot2", "plot3", "plot4". 1) Within the strategy code, how would I assign the variable myIndicatorValue to the current value of the MyCustomIndicator "plot3"? 2) What if I wanted the value 10 bars ago for "plot3"? A specific example for each is appreciated. Thanks! |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Not sure I follow. There is no difference between your custom indicator in a strategy and a standard NT indicator like e.g. MACD (which has 3 plots) which you would access like this:
double d = MACD(fast, slow, smooth).Avg[10];
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Certified NinjaScript Consultant
|
Thanks Dierk,
so the general case is: strategyVar = indicatorName(parm1, parm2, ...).indicatorPlotName[barsago]; Perfect! |
|
|
|
|
|
#4 |
|
Certified NinjaScript Consultant
|
As a follow-up question, what is the general case code (or example) if I wanted to plot the "plot3" series of a custom indicator for the current bar value or the value 10 bars back? This seems to work differently than the assignment example. Thanks.
|
|
|
|
|
|
#5 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Again, not sure I follow. Below you pointed out the current usage already. What are you looking for?
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Certified NinjaScript Consultant
|
Hi Dierk,
What I am trying to understand is how to reference different plots from a custom indicator to 1) be accessed for subsequent calculations in the strategy logic or 2) pass plots to the chart, perhaps with some style changes. In this case I might only want to plot some, but not all, of the indicator plots on the strategy chart. For use case #1 it would appear that I can reference the plot name directly and can address specific bars in a series (e.g., ".plot3[0]"). In use case #2, I would need to reference the plot number (e.g., ".Plots[2]") realizing it is zero based as sequenced in the custom indicator. In this case there is no addressing of the plot by name, only by its slot number. Seeking clarification on what seems to be two approaches to reference plots of a custom (or standard) indicator. Thanks. Whitmark |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Yes, you can only access plots by their index within the Plots[] collection.
For clarification, a plot is only the visual representation of data contained in a DataSeries. So if you have a plot named "Plot1" and its the only plot within the indicator, you can access this plot object via Plots[0] and manipulate its properties. The underlying data point of that plot are contained in a DataSeries object exposed by a property such as "public DataSeries Plot1". So, you get at the the plot and the underlying data, you always: myIndicator.Plots[plot index] myIndicator[n barsAgo] --> Default plot myIndicator.DataSeriesPropertyName[n barsAgo] -->
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Certified NinjaScript Consultant
|
Ray, thanks for the thorough explanation. One more follow-up question to complete the thread:
If I have a custom indicator with several parameters, do I have to restate all of the parameters with each indicator call or is there a way to forgo these references each time if I am looking for a way to just access values for different n barsago using the same parm set? For example; As you can imagine, coding expressions like if (myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[0] > myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[1]) etc, can be pretty cumbersome, yet there is always this remedy: double myValue0 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[0]; double myValue1 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[1]; double myValue2 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[2]; double myValue3 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[3]; But there may be best practice for how to do this. Thanks, Whitmark |
|
|
|
|
|
#9 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Yes, you have to restate them unless you assign the indicator to a variable.
For example: MyCustomIndicator myCustomIndicator = myCustomIndicator(parm1, parm2, parm3, parm4, parm5); if (myCustomIndicator.myDSName[0] > myCustomIndicator.myDSName[1])
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Certified NinjaScript Consultant
|
Thanks Ray, that works well, but if I understand the OOP concept correctly, your example should read as follows where the MyCustomIndicator is the indicator name and the myCustomIndicator is the name of the instance of the indicator that you would like to reference in your strategy. Typically, I will shorten myCustomIndicator to something pithy like myCI since I will be referring to it frequently.
For example: MyCustomIndicator myCustomIndicator = MyCustomIndicator(parm1, parm2, parm3, parm4, parm5); if (myCustomIndicator.myDSName[0] > myCustomIndicator.myDSName[1]) |
|
|
|
|
|
#11 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
That is correct.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Feb 2009
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
This thread seems to come close to what I'm after but not quite. Apologies if this is a silly question, I'm more of a VB background. How does one obtain an array/collection of DataSeries objects, but WITHOUT using the Add() function (which puts them into the Values collection and would mean that they are plotted)? The reason I don't want to use Add() is that I don't want the group of DataSeries objects being plotted. What won't work here is putting them all into the Values collection (via Add() method) and making some plots "invisible"/transparent, as that would adversely affect the DataSeries that I do want to plot. Some background: what I am trying to achieve is an indicator which is built up from an arbitrary number of components, where each component is weighted according to how well it performs over time under a particular measure. So in one version of the indicator I want to be able to keep the performance over time of each component as an array of DataSeries but not plot these - what I want to plot is the measure of performance for each component (so I'd put the component performance DataSeries into the Values collection via Add()). Cheers, fttbb. |
|
|
|
|
|
#13 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Do you mean you just want an array of data points that are in sync with the number of bars on your chart?
If yes, please check out the DataSeries class - http://www.ninjatrader-support.com/H...iesObject.html
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Junior Member
Join Date: Feb 2009
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Hi NinjaTrader_Ray,
How can you ask that having read my message? ![]() I said that I want "an array/collection of DataSeries objects" but without using the Add() method or the Values collection of DataSeries objects. Do you understand this? Clearly then: 1. I know what the DataSeries class is; and 2. I've read the help function about DataSeries objects, the Add() method and the Values collection, since I explained why the Values collection of DataSeries objects is not the collection that I want. So please don't just refer me to the help information about the DataSeries object. I look forward to a considered answer. Regards, fttbb. |
|
|
|
|
|
#15 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Sorry, misunderstanding.
There is no supported class for a collection of DataSeries objects. You will need to use a standard C# collection class such as an ArrayList.
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing Print() from custom class... | funk101 | Indicator Development | 9 | 04-27-2012 04:15 PM |
| Accessing value from custom indicator from strategy | funk101 | Strategy Development | 12 | 08-19-2008 08:41 AM |
| Changing plot colors inside of a strategy or indicator | NinjaTrader_Ray | General Programming | 5 | 06-23-2007 11:30 AM |
| Custom Plot colors & Thresholds & Price marker colors | higler | General Programming | 5 | 06-22-2007 07:47 AM |
| Accessing Custom Indicator Functions in Strategies | ThePatientOne | Strategy Development | 1 | 05-29-2007 01:29 PM |