I am able to display a 200 day MA on a daily SP500 chart without any problems. In my strategy however, the values calculated for the 200 day MA using the SMA indicator are not correct. They are often 10+ points different than the 200 day SMA values on the daily chart.
I'm suspecting that since 200 days is a much longer lookback period than the days available in each individual historical futures contract, the SMA indicator might not be able to calculate the 200 day moving average correctly. If I use a smaller daily period MA (e.g. 10 days), the SMA indicator calculates the daily MA values properly.
There's nothing special about my strategy's implementation of the 200 day MA. I add the daily SP500 cash index in the Initialize() procedure:
protected override void Initialize()
{
Add("^SP500", PeriodType.Day, 1);
CalculateOnBarClose = true;
.....
}
And I calculate the 200 day MA when BarsInProgress == 1 in the OnBarUpdate() procedure:
protected override void OnBarUpdate()
{
if (BarsInProgress == 1)
{
daySMA200 = SMA(Close,200)[0];
....
}
}
Is there a way I can calculate a 200 day MA correctly in a multi-instrument and multi-timeframe strategy that uses 1 futures contract (i.e. 3 months) or less of tick data at a time?
Thanks,
David
dbw451
Comment