QuantConnect/Lean · error · RegressionTestException

Scheduled Event did not assert history call as many times as

Error message

Scheduled Event did not assert history call as many times as expected: {_successCount}/49

What it means

OnEndOfAlgorithm asserts the hourly scheduled history probe succeeded at least ExpectedHistoryCallCount (49) times. _successCount < expected means the scheduled MakeHistoryCall either did not fire often enough or fired but failed the per-call bar-count check too many times, so history was unreliable across the run.

Source

Thrown at Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs:81

            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)
        {
            if (!Portfolio.Invested)
            {
                foreach (var chain in slice.FutureChains)
                {
                    foreach (var contract in chain.Value)
                    {
                        Log($"{contract.Symbol.Value}," +
                            $"Bid={contract.BidPrice.ToStringInvariant()} " +
                            $"Ask={contract.AskPrice.ToStringInvariant()} " +

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm the backtest date span yields >= 49 hourly scheduled triggers.
  2. Ensure each MakeHistoryCall returns >= 10 bars (fix error 15 root causes: warmup, resolution, gaps).
  3. Verify TimeRules.Every(TimeSpan.FromHours(1)) aligns with open market hours across the span.
  4. Adjust ExpectedHistoryCallCount if the date span legitimately changed.
Defensive patterns

Strategy: validation

Validate before calling

public override void OnEndOfAlgorithm()
{
    if (_successCount < ExpectedHistoryCallCount)
    {
        Log($"History probes succeeded {_successCount}/{ExpectedHistoryCallCount}. " +
            "Check date span, warmup, and per-call bar counts.");
    }
}

Prevention

When it happens

Trigger: OnEndOfAlgorithm runs with _successCount < ExpectedHistoryCallCount (49) — the every-hour scheduled event did not accumulate enough successful (>=10-bar) history calls over the backtest span.

Common situations: Backtest date span shortened so fewer than 49 hourly probes fit; many probes failed the >=10 bar check (data gaps/warmup); the scheduled event TimeRules.Every(TimeSpan.FromHours(1)) fired less often than expected; market hours reduced the count.

Related errors


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