IDataSeries Interface
Previous Topic  Next Topic 

The IDataSeries Interface is implemented by several different indicator based classes. This means that any data class that implements this interface can be used as input data for an indicator. What exactly does this mean? Think of the IDataSeries interface like your standard three prong North American electrical outlet. Any appliance (toaster, lamp, TV) that implements a three prong North American plug can interface to this outlet and receive electricity.



Price Series

Open, High, Low, Close, Volume all implement the IDataSeries interface and therefore can be used as input for indicators


// Passing in the a price series of High prices and printing out the current value of the
// 14 period simple moving average
double value = SMA(High, 14)[0];
Print("The current SMA value is " + value.ToString());


Indicator
Indicators implement the IDataSeries interface and therefore can be used as input for indicators

// Printing the current value of the 20 period simple moving average of a 14 period RSI
// using a data series of closing prices
double value = SMA(RSI(Close, 14), 20)[0];
Print("The current SMA value is " + value.ToString());


Indicator Data Series
The class IndicatorSeries implements the IDataSeries interface and therefore can be used as input for indicators

// Instantiating a new DataSeries object and passing it in as input to calculate
// a simple moving average
IndicatorSeries myIndicatorSeries = new IndicatorSeries(this);
double value = SMA(myIndicatorSeries, 20)[0];


Data Layer Separated from Drawing Layer

Within NinjaScript, you control how values are calculated and NinjaTrader takes care of plotting of these values. Since collection of data values are stored in objects derrived from any of the above classes there needs to be methods to set or reset values of these data collections.

Syntax

dataSeries.Set(double value)
dataSeries.Reset()

//Sets the indicators caclulate value
IndicatorSeries myIndicatorSeries = new IndicatorSeries(this);
myIndicatorSeries.Set(Close[0] - Close[1]);

// Reset the indicator value (removes the value, will skip plotting as well)
myIndicatorSeries.Reset();