{"record":{"id":"35fea981816d5847","repo":"QuantConnect/Lean","slug":"indicators-are-not-ready","errorCode":null,"errorMessage":"Indicators are not ready!","messagePattern":"Indicators are not ready!","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateIndexAlgorithm.cs","lineNumber":104,"sourceCode":"            if (_emaFast > _emaSlow)\n            {\n                SetHoldings(SpxOption, 1);\n            }\n            else\n            {\n                Liquidate();\n            }\n        }\n\n        /// <summary>\n        /// Asserts indicators are ready\n        /// </summary>\n        /// <exception cref=\"RegressionTestException\"></exception>\n        protected void AssertIndicators()\n        {\n            if (!_emaSlow.IsReady || !_emaFast.IsReady)\n            {\n                throw new RegressionTestException(\"Indicators are not ready!\");\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (Portfolio[Spx].TotalSaleVolume > 0)\n            {\n                throw new RegressionTestException(\"Index is not tradable.\");\n            }\n            AssertIndicators();\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 virtual bool CanRunLocally { get; } = true;\n\n        /// <summary>","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateIndexAlgorithm.cs#L86-L122","documentation":"Thrown by AssertIndicators() in OnEndOfAlgorithm() when either _emaSlow or _emaFast ExponentialMovingAverage has not reached its IsReady state. An EMA becomes ready only after receiving at least its configured period count of data samples. This assertion guarantees that indicators used for trade signals accumulated sufficient warmup data before the algorithm finished.","triggerScenarios":"The algorithm date range (SetStartDate/SetEndDate) is too short to supply 80 (fast) or 200 (slow) minute-resolution bars, the data feed is missing SPX bars so OnData returns early before EMA updates, or the algorithm never calls OnData enough times because slice.Bars lacks the expected SPX/SPXOption keys.","commonSituations":"Shortening the algorithm's backtest window below the indicator period, using Minute resolution with a start date too close to end date, missing or corrupt index data files in the regression data folder, or changing the EMA period constants without adjusting the date range.","solutions":["Extend SetStartDate earlier so the backtest window contains at least max(80, 200) minute bars before any trading logic runs.","Call SetWarmUp(period) in Initialize where period matches the longest indicator period to ensure indicators warm up before OnData trades.","Verify SPX index data files exist and are not corrupt in the regression data directory for the configured date range.","Check that slice.ContainsKey(Spx) and slice.Bars.ContainsKey(SpxOption) gates are not filtering out all data points.","Log _emaSlow.Samples and _emaFast.Samples in OnEndOfAlgorithm to see exactly how many data points each received."],"exampleFix":"// before\n_emaSlow = EMA(Spx, 200);\n_emaFast = EMA(Spx, 80);\n// no warmup set\n\n// after\n_emaSlow = EMA(Spx, 200);\n_emaFast = EMA(Spx, 80);\nSetWarmUp(Math.Max(200, 80), Resolution.Minute);","handlingStrategy":"validation","validationCode":"// Before calling AssertIndicators, check indicator sample counts\nif (_emaSlow.Samples < _emaSlow.Period || _emaFast.Samples < _emaFast.Period)\n{\n    Log($\"Insufficient samples: slow={_emaSlow.Samples}/{_emaSlow.Period}, fast={_emaFast.Samples}/{_emaFast.Period}\");\n    return;\n}","typeGuard":"// No type guard — IsReady is a runtime property on IndicatorBase\nbool AreIndicatorsReady() => _emaSlow.IsReady && _emaFast.IsReady;","tryCatchPattern":"try\n{\n    AssertIndicators();\n}\ncatch (RegressionTestException ex) when (ex.Message.Contains(\"not ready\"))\n{\n    Log($\"Indicator warmup incomplete: slow samples={_emaSlow.Samples}, fast samples={_emaFast.Samples}\");\n    throw;\n}","preventionTips":["Always call SetWarmUp() with the longest indicator period in Initialize.","Gate trading logic behind if (!IsWarmingUp && _emaSlow.IsReady) checks.","Use IndicatorBase.IsReady before reading indicator values.","Ensure the backtest date range spans at least max(period) bars."],"tags":["quantconnect","indicators","ema","warmup","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}