How can I sync the DataSeries fiveMinuteSMA to BarsArray[2]? This code does not work.
public class MTFIndicators : Strategy
{
#region Variables
private DataSeries fiveMinuteSMA; // Value of 5 Minute SMA
#endregion
protected override void Initialize()
{
CalculateOnBarClose = false;
BarsRequired = 0;
Add(PeriodType.Minute, 1); // BarsArray[1]
Add(PeriodType.Minute, 5); // BarsArray[2]
Add(PeriodType.Minute, 15); // BarsArray[3]
fiveMinuteSMA = new DataSeries(this); // Sync this Series to the 5 Minute Bars
}
protected void FiveMinuteIndicatorValues()
{
Print(Time[0].ToString() + "\tM5\t" + CurrentBar.ToString() );
// Calulate a 10 Period SMA
int Period = 10; //SMA Period
if (CurrentBar == 3) // Bar #3 shows as the 1st Bar when Adding 15 Min Bars to the Strategy
fiveMinuteSMA.Set(Inputs[2][0]); // First 5 Min Bar. Set SMA Value to Close.
else
{
double last = fiveMinuteSMA[1] * Math.Min(CurrentBar, Period);
if (CurrentBar >= Period)
fiveMinuteSMA.Set((last + Inputs[2][0] - Inputs[2][Period]) / Math.Min(CurrentBar, Period));
else
fiveMinuteSMA.Set((last + Inputs[2][0]) / (Math.Min(CurrentBar, Period) + 1));
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 2)
{
FiveMinuteIndicatorValues();
}
}

Comment