QuantConnect/Lean · error · RegressionTestException

History request returned different data than expected

Error message

History request returned different data than expected

What it means

OnEndOfAlgorithm requests History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Hour) and asserts history.Count equals _receivedData.Count (the number of points delivered live in OnData). A mismatch means the history API returns a different dataset than the live subscription for the same symbol and range.

Source

Thrown at Algorithm.CSharp/DescendingCustomDataObjectStoreRegressionAlgorithm.cs:103

                    throw new RegressionTestException("One or more custom data fields (Open, High, Low, Close, Price) are zero.");
                }

                _receivedData.Add(sortCustomData);
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if (_receivedData.Count == 0)
            {
                throw new RegressionTestException("Custom data was not fetched");
            }

            var history = History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Hour).ToList();

            if (history.Count != _receivedData.Count)
            {
                throw new RegressionTestException("History request returned different data than expected");
            }

            // Iterate through the history collection, checking if the EndTime is in ascending order.
            for (int i = 0; i < history.Count - 1; i++)
            {
                if (history[i].EndTime > history[i + 1].EndTime)
                {
                    throw new RegressionTestException($"Order failure: {history[i].EndTime} > {history[i + 1].EndTime} at index {i}.");
                }
            }
        }

        /// <summary>
        /// Final status of the algorithm
        /// </summary>
        public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;

        /// <summary>

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Align the History call resolution with the subscription: use Resolution.Daily to match AddData<SortCustomData>(..., Resolution.Daily).
  2. Log both counts and a few sample timestamps from each to identify which points are excluded.
  3. If the discrepancy is a Lean bug in history for sorted custom data, fix the history reader to apply the same Sort logic as the subscription.
  4. Verify StartDate/EndDate boundaries are inclusive on both paths.

Example fix

// before
var history = History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Hour).ToList();

// after — match the subscription resolution
var history = History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Daily).ToList();
Defensive patterns

Strategy: validation

Validate before calling

// Use the same resolution as the subscription
var history = History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Daily).ToList();
if (history.Count != _receivedData.Count)
{
    Debug($"History={history.Count} vs Received={_receivedData.Count}");
}

Prevention

When it happens

Trigger: The history request uses Resolution.Hour while the live subscription used Daily (Resolution.Daily in AddData), causing a different aggregation/count. Also fires if history filters out data that OnData included, or if the Sort flag behaves differently between live and history paths.

Common situations: Resolution mismatch between AddData (Daily) and the History call (Hour), a Lean history-vs-subscription inconsistency for custom data with Sort=true, or timezone/boundary differences excluding edge points.

Related errors


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