I tried SMA to create the average of n period bars as below:
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Spread"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "SMASpread"));
Overlay = false;
Add(FirstInstrument,PeriodType.Minute,1); // Closes[1] = BarsInProgressIndex()
Add(SecondInstrument,PeriodType.Minute,1); // Closes[2] = BarsInProgressIndex()
}
double num =0;
protected override void OnBarUpdate()
{
try
{
num += SMA(Closes[1],Period);
}
}
Causes Error :
Operator '+=' cannot be applied to operands of type 'double' and 'NinjaTrader.Indicator.SMA'
Cannot implicitly convert type 'NinjaTrader.Indicator.SMA' to 'double'
Why can't I use SMA to calculate the mean / average of serveral bars?
Afshin
Comment