{"record":{"id":"21b2472ab7bef6e8","repo":"QuantConnect/Lean","slug":"sma-was-not-updated","errorCode":null,"errorMessage":"SMA was not updated.","messagePattern":"SMA was not updated\\.","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateSecurityWithBenchmarkRegressionAlgorithm.cs","lineNumber":74,"sourceCode":"        /// <param name=\"data\">Slice object keyed by symbol containing the stock data</param>\n        public override void OnData(Slice slice)\n        {\n            Log($\"{Time} - {Securities[\"SPY\"].Price}, {_spyMovingAverage}\");\n        }\n\n        /// <summary>\n        /// 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.\n        /// </summary>\n        public override void OnEndOfAlgorithm()\n        {\n            Log($\"_spy1.Subscriptions.Count(): {_spy1.Subscriptions.Count()}\");\n            Log($\"_spy2.Subscriptions.Count(): {_spy2.Subscriptions.Count()}\");\n            Log($\"_spy1.Subscriptions.First().Consolidators.Count: {_spy1.Subscriptions.First().Consolidators.Count}\");\n            Log($\"_spy2.Subscriptions.First().Consolidators.Count: {_spy2.Subscriptions.First().Consolidators.Count}\");\n\n            if (_spyMovingAverage == 0)\n            {\n                throw new RegressionTestException(\"SMA was not updated.\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.\n        /// </summary>\n        public List<Language> Languages { get; } = new() { Language.CSharp };\n\n        /// <summary>\n        /// Data Points count of all timeslices of algorithm\n        /// </summary>\n        public long DataPoints => 48;\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateSecurityWithBenchmarkRegressionAlgorithm.cs#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// After Initialize, confirm the indicator is wired to data\nvar sub = _spy1.Subscriptions.FirstOrDefault();\nif (sub == null || sub.Consolidators.Count == 0)\n{\n    Log(\"No consolidator attached to _spy1; SMA will not update\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","lean","regression-test","indicators","sma","subscriptions","data-flow"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}