{"record":{"id":"b02ee90c54076770","repo":"QuantConnect/Lean","slug":"duplicatesma-indicator-was-expected-to-be-ready","errorCode":null,"errorMessage":"_duplicateSMA indicator was expected to be ready","messagePattern":"_duplicateSMA indicator was expected to be ready","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomWarmUpPeriodIndicatorAlgorithm.cs","lineNumber":94,"sourceCode":"                throw new RegressionTestException(\"_customNotWarmUp indicator wasn't expected to be warmed up\");\n            }\n\n            WarmUpIndicator(\"SPY\", _customNotInherit, Resolution.Minute);\n            // Check _customWarmUp indicator has already been warmed up with the requested data\n            if (!_customNotInherit.IsReady)\n            {\n                throw new RegressionTestException(\"_customNotInherit indicator was expected to be ready\");\n            }\n            if (_customNotInherit.Samples != 60)\n            {\n                throw new RegressionTestException(\"_customNotInherit indicator was expected to have processed 60 datapoints already\");\n            }\n\n            WarmUpIndicator(\"SPY\", _duplicateSMA, Resolution.Minute);\n            // Check _customWarmUp indicator has already been warmed up with the requested data\n            if (!_duplicateSMA.IsReady)\n            {\n                throw new RegressionTestException(\"_duplicateSMA indicator was expected to be ready\");\n            }\n            if (_duplicateSMA.Samples != 60)\n            {\n                throw new RegressionTestException(\"_duplicateSMA indicator was expected to have processed 60 datapoints already\");\n            }\n        }\n\n        public override void OnData(Slice slice)\n        {\n            if (!Portfolio.Invested)\n            {\n                SetHoldings(\"SPY\", 1);\n            }\n\n            if (Time.Second == 0)\n            {\n                // Compute the difference between the indicators values\n                var diff = Math.Abs(_customNotWarmUp.Current.Value - _customWarmUp.Current.Value);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomWarmUpPeriodIndicatorAlgorithm.cs#L76-L112","documentation":"This RegressionTestException is thrown in Initialize after WarmUpIndicator(\"SPY\", _duplicateSMA, Resolution.Minute). _duplicateSMA is a second SimpleMovingAverage(60) added to match a Python counterpart algorithm. It asserts _duplicateSMA.IsReady == true, verifying that multiple built-in indicators can be warmed up independently in the same Initialize call.","triggerScenarios":"_duplicateSMA.IsReady is false after WarmUpIndicator. This means the second SMA's warm-up failed even though the first SMA (_customNotInherit) succeeded. Causes: WarmUpIndicator has a per-symbol caching issue that prevents warming up a second indicator on the same symbol, or the second indicator's WarmUpPeriod is not detected.","commonSituations":"A LEAN version change to WarmUpIndicator added caching that prevents re-warming a second indicator on the same symbol within one Initialize, the history data was consumed/cached and not re-delivered, or the warm-up loop only processes the first registered indicator per symbol.","solutions":["Verify _duplicateSMA is a distinct instance (not a reference to _customNotInherit).","Trace WarmUpIndicator to confirm it doesn't skip subsequent indicators on the same symbol due to a cache hit.","Check that _duplicateSMA.WarmUpPeriod is correctly set (60) and the interface is detected.","If testing engine changes, ensure warm-up history is re-fetched or re-delivered for each indicator, not cached per symbol."],"exampleFix":"// before — warm-up caches history per symbol, second indicator misses out\nprivate readonly Dictionary<Symbol, List<IBaseData>> _warmupCache = new();\npublic void WarmUpIndicator(Symbol symbol, IndicatorBase indicator, Resolution res)\n{\n    if (_warmupCache.ContainsKey(symbol)) return; // BUG: skips second indicator\n    // ...\n}\n\n// after — warm up each indicator independently\npublic void WarmUpIndicator(Symbol symbol, IndicatorBase indicator, Resolution res)\n{\n    if (indicator is not IIndicatorWarmUpPeriodProvider provider) return;\n    var history = History<IBaseData>(symbol, provider.WarmUpPeriod, res);\n    foreach (var bar in history) indicator.Update(bar);\n}","handlingStrategy":"validation","validationCode":"// Validate each indicator independently after warm-up\nWarmUpIndicator(\"SPY\", _duplicateSMA, Resolution.Minute);\nif (!_duplicateSMA.IsReady)\n{\n    Log($\"_duplicateSMA not ready. Samples: {_duplicateSMA.Samples}\");\n    // Check if warm-up history was cached and not re-delivered\n    var history = History<IBaseData>(\"SPY\", 60, Resolution.Minute);\n    Log($\"History available: {history.Count()} bars\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure WarmUpIndicator does not cache history per symbol in a way that skips subsequent indicators.","Verify each indicator instance is distinct (not accidentally aliased to the same reference).","Warm up each indicator in sequence and check IsReady immediately after each call."],"tags":["quantconnect","lean","indicator","warmup","multiple-indicators","sma","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}