Skip to content

fix(chart): hide-candles zone snaps the first trade to its bucket open - #551

Merged
guyverino merged 1 commit into
mainfrom
fix/chart-hide-candles-first-trade-bucket
Sep 13, 2026
Merged

fix(chart): hide-candles zone snaps the first trade to its bucket open#551
guyverino merged 1 commit into
mainfrom
fix/chart-hide-candles-first-trade-bucket

Conversation

@guyverino

Copy link
Copy Markdown
Collaborator

What & why

"Hide the last N candles" (the candle popup, «Скрыть последних свечей») hid fewer candles than asked — on a thinly traded market a 5/3 setting hid a single candle, and with trade_candles no wider than hide_candles it hid N−1 permanently.

The zone's shader boundary is clamped so it never reaches left of the first resident trade cross (a bucket with no ticks to show keeps its candle). The clamp used the raw tick timestamp, while the shader omits candles by bucket t_open >= boundary — and a tick is always later than the open of its own bucket, so the bucket holding the first trade was never hidden. Measured on 2026-09-13 (Main pane, 5m, hide=3): boundary -52298 (the first tick, 23 s into the bucket) instead of -75546 (that bucket's open).

The computation moves into hide_start_rel (chartdx/data_state/market.rs), which floors the first trade to its bucket open before the max; the measured case is a unit test that fails on the old formula.

Notable decisions

  • The stamps of combo_left_rel (full read, live drain) stay raw; the snap lives at the one consumer.
  • combo_left_rel is relative f32, so at a 26 h offset it carries an ~8 ms ULP: a tick within 8 ms of a bucket edge can floor into the neighbouring bucket. Accepted: one candle, self-healing on the next bucket roll, and candle t_open_rel already carries the same ULP; removing it means widening ChartHistoryRead.combo_left_rel_ms to f64 in moon-core — out of scope.

Known limitations

The boundary still moves once per bucket (unchanged); a market that has not streamed any trade yet still draws all candles (unchanged, by design).

Issues

none of the 16 open issues is touched by this change (#534/#535 are about bottom-volume depth, not the hide zone)

How to verify

cargo fmt --all -- --check
cargo build -p moon-ui-gpui --bin moonterminal --target x86_64-pc-windows-msvc --all-targets
cargo clippy -p moon-ui-gpui --bin moonterminal --target x86_64-pc-windows-msvc --all-targets -- -D warnings
cargo test -p moon-core -p moon-ui-gpui --target x86_64-pc-windows-msvc

fmt check exit 0 · build all-targets Finished · clippy: pre-existing 81 errors in moon-core (identical on origin/main, checked), nothing new in the touched files · tests: moon-core 1961 passed, moon-ui-gpui 1819 + theme_contract 333 passed, 0 failed · FireTest не запускался · live: with channels.markets + log.filter = "moonterminal::chartdx=info", the xgeom line reports hide_rel == bucket_open − 2·TF (Main/BERAUSDT, 5/3, 32 samples) — before the fix the same line showed a raw tick timestamp.

The "hide the last N candles" boundary is clamped so the zone never
reaches left of the first resident trade cross. The clamp used the raw
tick timestamp, while the shader compares candle bucket OPENS against
it, so the bucket holding the first trade always kept its candle: with
trade_candles no wider than hide_candles the setting hid one candle
fewer than asked, and on a thinly traded market a 5/3 setting hid a
single candle until trades reached the older buckets of the zone.

Measured on 2026-09-13 (Main pane, 5m, hide=3): boundary -52298 (the
first tick, 23 s into the bucket) instead of -75546 (that bucket's open).

The computation moves into `hide_start_rel`, which floors the first
trade to its bucket open before the max, with the measured case as a
unit test.
@guyverino
guyverino merged commit d3165c1 into main Sep 13, 2026
6 checks passed
@guyverino
guyverino deleted the fix/chart-hide-candles-first-trade-bucket branch September 13, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant