QuantConnect/Lean · error · RegressionTestException

Empty history at {Time}

Error message

Empty history at {Time}

What it means

A scheduled history probe calls History(10, Resolution.Minute) and asserts at least 10 minute bars return. Fewer than 10 means the history request yielded insufficient data for the period — the futures universe lacked 10 minutes of lookback at that call time, so the data window was empty or short.

Source

Thrown at Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs:72

            SetCash(1000000);

            foreach (var root in roots)
            {
                // set our expiry filter for this futures chain
                AddFuture(root, Resolution.Minute, extendedMarketHours: ExtendedMarketHours).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
            }

            SetBenchmark(d => 1000000);

            Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);
        }

        private void MakeHistoryCall()
        {
            var history = History(10, Resolution.Minute);
            if (history.Count() < 10)
            {
                throw new RegressionTestException($"Empty history at {Time}");
            }
            _successCount++;
        }

        public override void OnEndOfAlgorithm()
        {
            if (_successCount < ExpectedHistoryCallCount)
            {
                throw new RegressionTestException($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
            }
        }

        /// <summary>
        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
        /// </summary>
        /// <param name="slice">The current slice of data keyed by symbol string</param>
        public override void OnData(Slice slice)
        {

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Ensure the algorithm is warmed up (SetWarmup) so 10 minute bars exist before the scheduled call fires.
  2. Confirm the futures subscription resolution is Minute (or finer) so minute history is available.
  3. Start the scheduled history probe only after enough bars have accumulated (guard on algorithm time / bar count).
  4. Verify no data gaps in the backtest window; if gaps exist, lower the requested bar count or tolerate short windows.

Example fix

// before
var history = History(10, Resolution.Minute);
if (history.Count() < 10) { throw ...; }

// after: skip the check while warming up
if (IsWarmingUp) return;
var history = History(10, Resolution.Minute);
if (history.Count() < 10) { Log($"Short history at {Time}: {history.Count()}"); return; }
Defensive patterns

Strategy: validation

Validate before calling

private void MakeHistoryCall()
{
    if (IsWarmingUp) return;
    var history = History(10, Resolution.Minute);
    if (history.Count() < 10)
    {
        Log($"Short history at {Time}: {history.Count()} bars.");
        return;
    }
    _successCount++;
}

Prevention

When it happens

Trigger: MakeHistoryCall() (scheduled every hour) runs History(10, Resolution.Minute) and the returned enumerable has Count() < 10 — not enough minute-bar history exists for the subscribed futures at that wall-clock point (e.g. near warm-up, market open, or a data gap).

Common situations: Called during warm-up before 10 bars accumulated; near the algorithm start date where lookback underflows; a data gap/hole in the minute feed; the futures subscription hadn't received enough bars yet; resolution mismatch (subscribed daily but requesting minute).

Related errors


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