QuantConnect / QuantConnect/Lean

Interim Updates of Indicators

Open
#8,620 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
21.7k
Forks
5.3k
Avg merge
2d 22h
Merged PRs (30d)
34

Description

Expected Behavior

We are able to get an intraday preview of an indicator without distorting its internal state.

Actual Behavior

This is currently not possible. Calling the Update method of an indicator does impact its internal state. For instance, the RollingSum for SMA or AverageGain and AverageLoss for RSI are also updated.

Motivation and Context

Currently, daily indicators are only updated at market close, i.e. once the daily bar has completed.
However, in many strategies, there is a need to obtain an interim indicator value (e.g. 5 minutes before market close) by using the current intraday price. This would enable making trading decisions within the ongoing trading session rather than waiting until the next day's market open.

Potential Solution

I see 2 possible approaches to handle this:

1.) Equip IndicatorBase with a Copy or Clone method.
We could then use the cloned instance for our interim (manual) updates and discard it afterwards, thereby avoiding changes to the state of our actual indicator. It's important that this is a deep copy.
I tested deepcopy in Python, but it doesn't work because the C# objects are not pickleable.

2.) Equip IndicatorBase with a Revert or Rollback method.
Essentially, it would be the inverse of Update, returning the indicator to its previous state.

I assume approach 1.) might be the easiest for you to implement. What do you think?

By the way, this is a feature that has been requested quite frequently by my clients as most other platforms also display interim updates of indicator values.

Checklist
  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues

Contributor guide

Open the contributing guide

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.

Research direction

Start by locating IndicatorBase and its Update implementations, then inspect how state is maintained for RollingSum in SMA and AverageGain/AverageLoss in RSI. Compare the proposed copy/clone and revert/rollback approaches; done means an interim update produces a value without changing the original indicator's state.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.