fix(ClusterSearch): keep realtime results consistent with a full bar recalculation - #180
Open
AlbertoAmadorBelchistim wants to merge 1 commit into
Conversation
…recalculation The incremental OnNewTrades path only re-evaluates the windows that contain the new trades. Several settings make a window's result depend on other data, so the forming bar showed different clusters than a recalculation until the bar closed: - MinPercent/MaxPercent: every level's percentage changes with the bar's total volume. - OnlyOneSelectionPerBar: when the selected level stops passing the filters, or another level becomes larger, the selection has to move to another level. - Body and wick locations: the ranges depend on Open/Close, which move without a new High or Low. These cases now use the existing full-bar update. In addition, the incremental loop used High - (PriceRange - 1) as its upper bound while the full calculation evaluates window starts up to the top of the price ranges (the High for location Any), so windows starting near the High were not updated live. The loop now uses the same upper bound as the ranges.
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.
ClusterSearch: keep realtime results consistent with a full bar recalculation
Problem
In realtime,
OnNewTradesonly re-evaluates the price windows that contain the new trades. With some settings, a window's result depends on other data as well, so the forming bar shows different clusters than a recalculation of the same bar. The difference disappears when the bar closes (OnCalculaterecalculates the closed bar in full), but until then clusters are missing or stale and alerts fire late or not at all.Affected cases:
Example: MinPercent = 10, total 1000, level A = 120 (12%) is shown. After 300 more contracts at another level the total is 1300 and A is at 9.2%, but it stays on the chart until the bar closes.
High - (PriceRange - 1), while the full calculation evaluates window starts up to the top of the price ranges (the High for locationAny). Windows starting near the High are not updated live.Changes
RequiresFullBarUpdateOnNewTrades()now also returnstruewhen MinPercent/MaxPercent is set, when OnlyOneSelectionPerBar is enabled, and for the Body / UpperWick / LowerWick / AtUpperLowerWick locations. These cases use the existing full-bar update, the same path already used for MaxVolume and the exact-zero Ask/Bid search.OnNewTradesuses the same upper bound as the price ranges of the full calculation.No behaviour changes for historical bars or for settings not listed above; those keep the incremental path.
Testing
Built against the current Alpha and ATAS X Alpha SDKs.
Manual check on a live chart: