View Full Version : Using a formula or variable as an input to an Indicator
nolantx
05-24-2007, 11:41 AM
I cannot seem to pass a variable as an input to an indicator. Can "IDataSeries" only be Open, High, Low or close ?
NinjaTrader_Dierk
05-24-2007, 12:03 PM
Please be specific. What do you want to code?
nolantx
05-24-2007, 12:09 PM
I want an an EMA of the average of O+H+L+C multiplied by a variable.
NinjaTrader_Dierk
05-24-2007, 12:20 PM
I see. You would need to code your own indicator to achieve that. This indicator would stuff <variable> *(O+H+L+C) into a DataSeries which you then could stuff into EMA. Something like (in pseudo code):
Intilialize()
{
bufferSeries = new DataSeries(this);
}
OnBarUpdate()
{
bufferSeries.Set(variable* (Open[0]+High[0]...));
Value.Set(EMA(bufferSeries, 14)); // 14 period EMA on your series
}
Please check out e.g. ADX implementation for details (e.g. dmPlus series).
nolantx
05-24-2007, 02:15 PM
protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "Plot0"));
TInput = new DataSeries(this);
}
protected override void OnBarUpdate()
{
TInput.Set((Open[0]+High[0]+Low[0]+Close[0]) *.25) ;
Plot0.Set(EMA(TInput,3));
}
The above is still giving the Errors:
The best overloaded method match for 'NinjaTrader.Data.DataSeries.Set(double)' has some invalid arguments
Argument '1': cannot convert from 'NinjaTrader.Indicator.EMA' to 'double'
NinjaTrader_Ray
05-24-2007, 03:58 PM
Should be:
Plot0.Set(EMA(TInput,3)[0]);