Repository navigation
Automatically deregister indicators and consolidators when a security is removed - #9673
Open
jhonabreul wants to merge 3 commits into
Open
jhonabreul wants to merge 3 commits into
jhonabreul wants to merge 3 commits into
Conversation
…removal - QCAlgorithm.DeregisterAll(symbol) disposes every indicator and consolidator created for the symbol through the algorithm helper methods in one call - Settings.AutomaticIndicatorDeregistration (default false) runs the same cleanup automatically when a security is completely removed from the algorithm, e.g. when it leaves the universe - Fix SubscriptionManager.RemoveConsolidator leaking the consolidator scan wrapper when the symbol's subscription configs were already removed: the wrapper stayed in the scan queue being re-enqueued forever
…lection - make the per-symbol cleanup private as DeregisterIndicatorsAndConsolidators, the setting is the only public surface - default Settings.AutomaticIndicatorDeregistration to true: kept indicators never update again after their security is removed, even when it's added back - add AutomaticIndicatorDeregistrationOnUniverseSelectionRegressionAlgorithm covering universe deselection and reselection - fold the DeregisterAll algorithms and tests into the automatic ones
jhonabreul
force-pushed
the
feature-deregister-all-security-cleanup
branch
from
October 13, 2026 22:26
421b654 to
1b3e9cd
Compare
jhonabreul
marked this pull request as ready for review
October 13, 2026 22:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a security leaves the algorithm, the indicators and consolidators created for it through the helper methods (
SMA,RSI,Consolidate,RegisterIndicator, ...) are never cleaned up. Their scan wrappers stay in the consolidator scan queue forever, so algorithms with per-symbol indicators and universe churn leak until anOutOfMemoryException.The change:
QCAlgorithm.RegisterConsolidator, the choke point every helper funnels through, now tracks the indicators and consolidators it registers per symbol.Securities.CollectionChangedremovals, the new privateQCAlgorithm.DeregisterIndicatorsAndConsolidators(symbol)disposes everything tracked for that symbol through the existing paths.B(target, reference), are fully deregistered when any of their symbols is removed.SubscriptionManager.AddConsolidatorare not tracked and are kept.IAlgorithmSettings.AutomaticIndicatorDeregistration,trueby default, turns the cleanup off.SubscriptionManager.RemoveConsolidatornow disposes the scan wrapper even when the symbol has no subscription configs left.Related Issue
N/A
Motivation and Context
Keeping the removed security's indicators buys nothing: they never update again, even when the security is added back. Cleaning them up by default removes a leak that is invisible until the algorithm runs out of memory.
Requires Documentation Change
Yes:
Settings.AutomaticIndicatorDeregistration, next toDeregisterIndicatorand the universe selection examples.How Has This Been Tested?
AutomaticIndicatorDeregistrationTests(7 tests): removal disposes the symbol's helper indicators and consolidators, keeps raw ones, honors the setting.SubscriptionManagerTests.RemoveConsolidatorDisposesScanWrapperEvenWithoutSubscriptions: red before the wrapper fix, green after.AutomaticIndicatorDeregistrationRegressionAlgorithm(C# + Python): manual remove and re-add, indicators and consolidator stop updating on removal, fresh ones work after re-adding.AutomaticIndicatorDeregistrationOnUniverseSelectionRegressionAlgorithm: universe deselection and reselection, deregistered on removal, new ones get data after reselection.Tests.Algorithmnamespace with CI filters: 13232 passed, 0 failed.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>