QuantConnect/Lean · error · RegressionTestException

Indicators are not ready!

Error message

Indicators are not ready!

What it means

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.

Source

Thrown at Algorithm.CSharp/BasicTemplateIndexAlgorithm.cs:104

            if (_emaFast > _emaSlow)
            {
                SetHoldings(SpxOption, 1);
            }
            else
            {
                Liquidate();
            }
        }

        /// <summary>
        /// Asserts indicators are ready
        /// </summary>
        /// <exception cref="RegressionTestException"></exception>
        protected void AssertIndicators()
        {
            if (!_emaSlow.IsReady || !_emaFast.IsReady)
            {
                throw new RegressionTestException("Indicators are not ready!");
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if (Portfolio[Spx].TotalSaleVolume > 0)
            {
                throw new RegressionTestException("Index is not tradable.");
            }
            AssertIndicators();
        }

        /// <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 virtual bool CanRunLocally { get; } = true;

        /// <summary>

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Extend SetStartDate earlier so the backtest window contains at least max(80, 200) minute bars before any trading logic runs.
  2. Call SetWarmUp(period) in Initialize where period matches the longest indicator period to ensure indicators warm up before OnData trades.
  3. Verify SPX index data files exist and are not corrupt in the regression data directory for the configured date range.
  4. Check that slice.ContainsKey(Spx) and slice.Bars.ContainsKey(SpxOption) gates are not filtering out all data points.
  5. Log _emaSlow.Samples and _emaFast.Samples in OnEndOfAlgorithm to see exactly how many data points each received.

Example fix

// before
_emaSlow = EMA(Spx, 200);
_emaFast = EMA(Spx, 80);
// no warmup set

// after
_emaSlow = EMA(Spx, 200);
_emaFast = EMA(Spx, 80);
SetWarmUp(Math.Max(200, 80), Resolution.Minute);
Defensive patterns

Strategy: validation

Validate before calling

// Before calling AssertIndicators, check indicator sample counts
if (_emaSlow.Samples < _emaSlow.Period || _emaFast.Samples < _emaFast.Period)
{
    Log($"Insufficient samples: slow={_emaSlow.Samples}/{_emaSlow.Period}, fast={_emaFast.Samples}/{_emaFast.Period}");
    return;
}

Type guard

// No type guard — IsReady is a runtime property on IndicatorBase
bool AreIndicatorsReady() => _emaSlow.IsReady && _emaFast.IsReady;

Try / catch

try
{
    AssertIndicators();
}
catch (RegressionTestException ex) when (ex.Message.Contains("not ready"))
{
    Log($"Indicator warmup incomplete: slow samples={_emaSlow.Samples}, fast samples={_emaFast.Samples}");
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/35fea981816d5847. Report an issue: GitHub.