PDA

View Full Version : Length-Parameter of DataSeries


Joerg
05-31-2010, 07:00 AM
Hello,

the following example for working with dataseries I copied from the sample reference of this forum.



protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Bar, "Average Range"));

myDataSeries = new DataSeries(this);

CalculateOnBarClose = true;
Overlay = false;
}

protected override void OnBarUpdate()
{
myDataSeries.Set(Math.Abs(Close[0] - Open[0]));
AvgR.Set(SMA(myDataSeries, Period)[0]);
}





Is my understanding right, that the Period of the SMA of the myDataSeries references to the BarArray? So if I am working on a 1-Min-Bar Chart and Period of this SMA is 20, it is calculated for the last 20 Minutes?

What I like to do is: create a dataseries, add data into it at some bars (and some bars not, irregularely) and then use this datseries in SMA-function. And SMA should use last 20 entries of the dataseries and not last 20 Minutes.

How should I change the example above for that aim?

Thanks a lot.

Joerg

NinjaTrader_Bertrand
05-31-2010, 07:13 AM
Joerg, yes, the Period would refer to bars index on the chart where you've run this indicator on and the dataseries object would be synced to. I'm not sure what you like to achieve, the SMA lookback would be tied to the bars index on the chart.

Joerg
05-31-2010, 07:37 AM
I´d like to store values to the dataseries only if a condition is true. If it is false the dataseries gets no value for this bar. And then I would like to calc the SMA of the last 20 values regardeless of the lookback time needed.

It´s a little bit like using RangeBars in a TimeBased Chart like it is possible in NT7.

NinjaTrader_Bertrand
05-31-2010, 07:56 AM
You would need to custom code this fully unfortunately, a custom dataSeries would always need a value set even it's a dummy you would filter then in your code, otherwise you could run into exceptions accessing the set values.