IDataSeries
Previous Topic  Next Topic 

Definition
IDataSeries is an interface that is implemented by all NinjaScript classes that manage historical data such as DataSeries, Indicators and other classes. The relevance of this boils down to one practical use which is providing you with the means to write a method that has flexibility in the types of price data arrays it can accept. By specifying a parameter of  type IDataSeries, you can then pass in an array of closing prices, an indicator or a user defined data series.


The sample code below demonstrates a method named DoubleTheValue that accepts any object that implements the IDataSeries interface as a parameter. This method is then used twice, the first time passing in an array of closing prices and the second time passing in a 20 period simple moving average.


private double DoubleTheValue(IDataSeries priceData)
{
    return priceData[0] * 2;     
}

protected override void OnBarUpdate()
{
    Print(DoubleTheValue(Close));
    Print(DoubleTheValue(SMA(20)));
}