![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
For one of my indicators I am trying to access information from previous bars, but can't find a readily available way to do so. In strategies I could just go Close[5] but from what I can tell only Close[0] works in indicators. Currently I am just passing the value along a 5-variable daisy chain so I can have access to Close[5]. There has to be a better way of doing this. Any suggestions?
I think I am using the data series thing wrong. Here is my awkward code Code:
protected override void Initialize()
{
Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[1]"));
Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[2]"));
Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[3]"));
Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[4]"));
Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[5]"));
}
Code:
protected override void OnBarUpdate()
{
PriorRegCh.Set(currentRegCh);
PriorRegCh2.Set(RegCh1);
PriorRegCh3.Set(RegCh2);
PriorRegCh4.Set(RegCh3);
PriorRegCh5.Set(RegCh4);
currentRegCh = RegressionChannel(60, 2).Middle[0];
RegCh1 = PriorRegCh[0];
RegCh2 = PriorRegCh2[0];
RegCh3 = PriorRegCh3[0];
RegCh4 = PriorRegCh4[0];
Code:
#region Properties
[Browsable(false)]
[XmlIgnore()]
public DataSeries PriorRegCh
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries PriorRegCh2
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries PriorRegCh3
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries PriorRegCh4
{
get { return Values[3]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries PriorRegCh5
{
get { return Values[4]; }
}
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
The "barsAgo" logic like in Close[5] (meaning 5 bars ago) works in indicators as well as in strategies.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Hmm. When I put a very simple test it breaks my indicator for no apparent reason.
Code:
if (Close[1] != Close[0]) Print("Test Success");
I can't make any sense as to why this is happening. |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Close[1] references one bar back, On bar 0 there is no such bar -> crash
You need to put in something like: if (CurrentBar < 1) return;
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Genius! Thanks. Before I had the BarsRequired setting thinking it would do the job of preventing referencing to nonexistent bars.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Update frequency of multiple data series in a Strategy | ThePatientOne | Strategy Development | 1 | 05-02-2007 10:05 AM |
| Format Data Series Unhandled Exception on startDate = lastDate | KBJ | Charting | 9 | 04-30-2007 08:39 PM |
| NT6 Drop down menu-data series | LG | Charting | 4 | 11-27-2006 01:05 PM |
| Pivot Series | wagross | Charting | 1 | 02-09-2006 07:36 AM |