In this algorithm, the trading signals depend on the EMA cross and three daily indicators (RSI, MACD and Momentum). Since the start and end date are set to have the difference of only one day, the daily indicators will not be ready (in other words, there is not sufficient data to calculate them).
There are two options to fix this:
- Set an earlier StartDate and in OnFifteenMinuteData handler, check whether all indicators are ready before use them to make trading decisions:
//In Initialize, e.g.:
SetStartDate(2016, 10, 1);
public void OnFifteenMinuteData(
object sender, TradeBar bar)
{
// update our indicators
Fast.Update(Time, bar.Open);
Slow.Update(Time, bar.Close);
var isReady = Fast.IsReady && Slow.IsReady &&
DailyMacd.IsReady && DailyRSI.IsReady &&
DailyMomentum.IsReady;
if(!isReady) return;
/* Continue with trading logic */
}
Set warmup with the number of days we need to get the indicators ready (please checkout the docs under the Warming Your Algorithm subsection:
// In Initialize
// Warm up 30 days of data.
SetWarmup(TimeSpan.FromDays(30));
We should not use the first option for live algorithms, since it would take several days for a deployed algorithm to make its first trade.