Skip to content

fills: nearest-tick rounding of raw bar prices (TradingView fill rule) - #163

Merged
luisleo526 merged 1 commit into
mainfrom
fix/tv-fill-nearest-tick-ship
Aug 24, 2026
Merged

fills: nearest-tick rounding of raw bar prices (TradingView fill rule)#163
luisleo526 merged 1 commit into
mainfrom
fix/tv-fill-nearest-tick-ship

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Fills taken at a raw bar price are rounded to the nearest tick the way TradingView does it: floor(price / mintick + 0.5) * mintick evaluated in double (lab finding 446/449). TradingView's price series carry sub-tick prints (NASDAQ:AAPL has x.xx5 and a few 4-dp values in ~5% of cells); only the fill is on the tick, and the rounding is a pure function of the double — 24,582/24,582 half-cent dump fills reproduce, including the 2,460 that round DOWN at binary midpoints (228.765/0.01 = 22876.4999…). The feed is left untouched because indicators consume the raw values.

round_to_mintick is now that function; a new bar_fill_price() applies it at fill resolution (before slippage ticks) at every raw-bar-price site — market fills at close/open, open-gap admits, margin-call slice prices, POOC exits, stop/limit fills that execute at the open or at a path point. round_to_mintick_directional is kept for computed stop/limit levels only. An earlier attempt that quantized the feed with a +1e-6 epsilon regressed 43 exact AAPL strategies (finding 444); this one does not.

Evidence: NASDAQ:AAPL population excellent 235 → 250, e+s 307 → 318 (lab finding 450); OANDA:EURUSD byte-identical (feed on-grid); ETH scraped 396/396 and corpus 309/2/1 unchanged (promote-fill-v1). tests/test_tv_fill_rounding.cpp embeds all 1,213 distinct midpoint-down census values; ctest 137/137.

@luisleo526
luisleo526 merged commit 7fc7347 into main Aug 24, 2026
7 checks passed
@luisleo526
luisleo526 deleted the fix/tv-fill-nearest-tick-ship branch August 24, 2026 19:17
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