QuantConnect/Lean · error · RegressionTestException
SMA was not updated.
Error message
SMA was not updated.
What it means
This algorithm adds a duplicate SPY security to test that a benchmark/indicator still receives data. The assertion checks _spyMovingAverage != 0: the Simple Moving Average indicator must have been updated with data during the run. A value of 0 means the indicator's Consolidator never received a single data point, so data did not flow to that security subscription.
Source
Thrown at Algorithm.CSharp/DuplicateSecurityWithBenchmarkRegressionAlgorithm.cs:74
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
Log($"{Time} - {Securities["SPY"].Price}, {_spyMovingAverage}");
}
/// <summary>
/// End of algorithm run event handler. This method is called at the end of a backtest or live trading operation. Intended for closing out logs.
/// </summary>
public override void OnEndOfAlgorithm()
{
Log($"_spy1.Subscriptions.Count(): {_spy1.Subscriptions.Count()}");
Log($"_spy2.Subscriptions.Count(): {_spy2.Subscriptions.Count()}");
Log($"_spy1.Subscriptions.First().Consolidators.Count: {_spy1.Subscriptions.First().Consolidators.Count}");
Log($"_spy2.Subscriptions.First().Consolidators.Count: {_spy2.Subscriptions.First().Consolidators.Count}");
if (_spyMovingAverage == 0)
{
throw new RegressionTestException("SMA was not updated.");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 48;
View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm RegisterIndicator(_spy, _sma, Resolution) was called and the consolidator count (logged above) is > 0.
- Verify SPY data exists for the backtest date range and the duplicate-security subscription resolves the same SID/data.
- Trace Slice delivery to the duplicate security's consolidator in AlgorithmManager.
Defensive patterns
Strategy: validation
Validate before calling
// After Initialize, confirm the indicator is wired to data
var sub = _spy1.Subscriptions.FirstOrDefault();
if (sub == null || sub.Consolidators.Count == 0)
{
Log("No consolidator attached to _spy1; SMA will not update");
} Prevention
- Always RegisterIndicator for manually-tracked indicators so the consolidator is attached.
- Verify the security's data file exists for the backtest date range.
- Log consolidator counts (as this algorithm already does) to catch missing data wiring early.
When it happens
Trigger: The SMA indicator is never fed bars: the consolidator is not wired to the subscription, the duplicate security subscription did not produce data, or the data resolution/date does not yield bars. Also if the indicator was never registered with RegisterIndicator.
Common situations: Adding the duplicate security via a path that does not attach the consolidator; data file missing for the test date; resolution mismatch; a SubscriptionManager change that drops data delivery to manually-added securities.
Related errors
- Unexpected ActiveSecurities count: {ActiveSecurities.Count}
- _customNotInherit indicator was expected to be ready
- _customNotInherit indicator was expected to have processed 6
- _duplicateSMA indicator was expected to be ready
- Expected a single subscription to exist ({spx})
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/21b2472ab7bef6e8.
Report an issue: GitHub.