IndicatorHistory can feed quote bars where the live indicator gets trade bars

Closed
#10,141 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@quantconnect-kronos is already working on this.

Since Nov 18, 2026.

  • #10205 by @quantconnect-kronos — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
data

Research direction

Start in Algorithm/QCAlgorithm.Indicators.cs at the IndicatorHistory overload that takes a dataType of null, then follow it into Common/Data/SliceExtensions.cs (PushThrough). Compare with how RegisterIndicator picks the data type it consolidates, and with Slice.CreateDynamicDataDictionary and SymbolData.GetData(). Done when the reproduction slices (trade close 100+i, quote close 200+i) feed the indicator trade bars, so the history matches the live values.

Written by the indexing model from the issue text.

Description

priority:p2
What happens

IndicatorHistory can update an indicator with quote bars where the same indicator, registered for live updates, gets trade bars. Its values then differ from the live ones for the same period.

When no data type is given (dataType == null), IndicatorHistory pushes each slice through SliceExtensions.PushThrough, which hands the indicator slice[symbol]. A slice's value for a symbol is the type of the last default-type datum added for it (Slice.CreateDynamicDataDictionary, SymbolData.GetData()). For a security with both trade and quote data, such as a future, that can be a QuoteBar. Meanwhile RegisterIndicator consolidates trade bars for the same subscription.

Reproduction

A slice holding a TradeBar (close 100) and a QuoteBar (close 200) for one future symbol, three hours in a row:

var algorithm = new AlgorithmStub();
var symbol = Symbol.CreateFuture("ES", Market.CME, new DateTime(2024, 3, 15));
var slices = Enumerable.Range(0, 3).Select(i =>
{
    var time = new DateTime(2024, 1, 2, 10 + i, 0, 0);
    var trade = new TradeBar(time, symbol, 100 + i, 100 + i, 100 + i, 100 + i, 10, TimeSpan.FromHours(1));
    var quote = new QuoteBar(time, symbol, new Bar(200 + i, 200 + i, 200 + i, 200 + i), 1,
        new Bar(200 + i, 200 + i, 200 + i, 200 + i), 1, TimeSpan.FromHours(1));
    return new Slice(time.AddHours(1), new List<BaseData> { trade, quote }, time.AddHours(1));
}).ToList();

var rows = algorithm.IndicatorHistory(new SimpleMovingAverage(1), slices).Current;
// rows: 200, 201, 202 (the quote closes); an indicator taking IBaseData receives the QuoteBar objects

With real data, the history of an indicator over hourly continuous futures (ES, GC, CL) in January 2024 had a few rows computed from quote closes. At 2024-01-02 16:00 New York, ES's 1-hour rate of change in the history was 5331.950 / 5311.905 − 1 (quote closes), while the live indicator got 5332.089 / 5311.765 − 1 (trade closes). The live values and a replay of the same history's trade bars agree with each other.

Where
  • QCAlgorithm.IndicatorHistory(IndicatorBase<T>, IEnumerable<Slice>, Action<IBaseData>, Type), Algorithm/QCAlgorithm.Indicators.cs
  • SliceExtensions.PushThrough(IEnumerable<Slice>, Action<BaseData>, Type), Common/Data/SliceExtensions.cs
What a fix must achieve

IndicatorHistory updates an indicator with the same data type that RegisterIndicator would consolidate for it, so history and live values agree. A suggestion only: resolve the data type from the subscription when the selector doesn't imply one.

Dominant language
C#
Stars
22.6k
Forks
5.4k
Avg merge
11h 39m
Merged PRs (30d)
104

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/Lean

All issues in QuantConnect/Lean

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.