QuantConnect/Lean · error · RegressionTestException

One or more custom data fields (Open, High, Low, Close, Pric

Error message

One or more custom data fields (Open, High, Low, Close, Price) are zero.

What it means

OnData checks that every SortCustomData point received from the object store has non-zero Open, High, Low, Close, and Price. If any field is zero, the custom data Reader() parsed a malformed line or returned a default-valued object. This guards the descending-sort custom-data pipeline.

Source

Thrown at Algorithm.CSharp/DescendingCustomDataObjectStoreRegressionAlgorithm.cs:85

            SetBenchmark(x => 0);

            SortCustomData.CustomDataKey = CustomDataKey;

            _customSymbol = AddData<SortCustomData>("SortCustomData", Resolution.Daily).Symbol;

            // Saving data here for demonstration and regression testing purposes.
            // In real scenarios, data has to be saved to the object store before the algorithm starts.
            ObjectStore.Save(CustomDataKey, string.Join("\n", descendingCustomData));
        }

        public override void OnData(Slice slice)
        {
            if (slice.ContainsKey(_customSymbol))
            {
                var sortCustomData = slice.Get<SortCustomData>(_customSymbol);
                if (sortCustomData.Open == 0 || sortCustomData.High == 0 || sortCustomData.Low == 0 || sortCustomData.Close == 0 || sortCustomData.Price == 0)
                {
                    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");

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify ObjectStore.Save runs in Initialize before any OnData and the payload matches the expected CSV schema (date,open,high,low,close,...).
  2. Check SortCustomData.Reader column indices: csv[1]=Open, csv[2]=High, csv[3]=Low, csv[4]=Close — confirm the source data follows this order.
  3. Log the raw line in Reader before parsing to catch empty or misaligned fields.
  4. Return null from Reader for malformed lines instead of a zero-filled object so they are skipped, not asserted on.

Example fix

// before
var data = new SortCustomData() { Open = csv[1].ToDecimal(), ... };
return data;

// after — validate before returning
if (csv.Length < 5) return null;
var open = csv[1].ToDecimal();
if (open == 0) return null;
return new SortCustomData() { Open = open, High = csv[2].ToDecimal(), Low = csv[3].ToDecimal(), Close = csv[4].ToDecimal() };
Defensive patterns

Strategy: validation

Validate before calling

public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
    var csv = line.Split(",");
    if (csv.Length < 5) return null;
    var open = csv[1].ToDecimal();
    var high = csv[2].ToDecimal();
    var low = csv[3].ToDecimal();
    var close = csv[4].ToDecimal();
    if (open == 0 || high == 0 || low == 0 || close == 0) return null;
    return new SortCustomData { Open = open, High = high, Low = low, Close = close, Value = close };
}

Prevention

When it happens

Trigger: A CSV line in the object-store payload has a missing/empty OHLC column, the Reader parses the wrong column index, or DateTime.ParseExact / ToDecimal fails silently and leaves a field at its default 0m.

Common situations: The object-store string was not saved before OnData runs, a column delimiter mismatch, the Reader's csv index offsets are wrong, or the data format changed (extra/fewer columns).

Related errors


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