Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 06-01-2007, 02:47 PM   #1
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default Accessing Multiple Custom Indicator Plots within a Strategy

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!
whitmark is offline  
Reply With Quote
Old 06-01-2007, 03:10 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 10,084
Thanks: 2
Thanked 32 times in 25 posts
Default

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];
NinjaTrader_Dierk is offline  
Reply With Quote
Old 06-01-2007, 03:22 PM   #3
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default

Thanks Dierk,

so the general case is:

strategyVar = indicatorName(parm1, parm2, ...).indicatorPlotName[barsago];

Perfect!
whitmark is offline  
Reply With Quote
Old 06-01-2007, 04:21 PM   #4
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default

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.
whitmark is offline  
Reply With Quote
Old 06-01-2007, 10:20 PM   #5
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 10,084
Thanks: 2
Thanked 32 times in 25 posts
Default

Again, not sure I follow. Below you pointed out the current usage already. What are you looking for?
NinjaTrader_Dierk is offline  
Reply With Quote
Old 06-02-2007, 06:07 AM   #6
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default

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
whitmark is offline  
Reply With Quote
Old 06-02-2007, 08:20 AM   #7
NinjaTrader_Ray
Founder and CEO
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,159
Thanks: 36
Thanked 337 times in 128 posts
Default

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] -->
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-02-2007, 10:49 AM   #8
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default

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
whitmark is offline  
Reply With Quote
Old 06-02-2007, 02:06 PM   #9
NinjaTrader_Ray
Founder and CEO
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,159
Thanks: 36
Thanked 337 times in 128 posts
Default

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])
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-13-2007, 05:09 AM   #10
whitmark
Vendor
 
whitmark's Avatar
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 464
Thanks: 6
Thanked 19 times in 13 posts
Default

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])
whitmark is offline  
Reply With Quote
Old 06-13-2007, 07:06 AM   #11
NinjaTrader_Ray
Founder and CEO
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,159
Thanks: 36
Thanked 337 times in 128 posts
Default

That is correct.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-25-2009, 03:58 PM   #12
fttbb
Junior Member
 
Join Date: Feb 2009
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default Collections/Arrays of DataSeries objects

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.
fttbb is offline  
Reply With Quote
Old 03-25-2009, 04:17 PM   #13
NinjaTrader_Ray
Founder and CEO
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,159
Thanks: 36
Thanked 337 times in 128 posts
Default

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
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-26-2009, 03:44 PM   #14
fttbb
Junior Member
 
Join Date: Feb 2009
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Unhappy Collections/Arrays of DataSeries objects

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.
fttbb is offline  
Reply With Quote
Old 03-26-2009, 03:51 PM   #15
NinjaTrader_Ray
Founder and CEO
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,159
Thanks: 36
Thanked 337 times in 128 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Print() from custom class... funk101 Indicator Development 10 06-28-2013 04:33 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 Development 5 06-23-2007 11:30 AM
Custom Plot colors & Thresholds & Price marker colors higler General Development 5 06-22-2007 07:47 AM
Accessing Custom Indicator Functions in Strategies ThePatientOne Strategy Development 1 05-29-2007 01:29 PM


All times are GMT -6. The time now is 09:59 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.