fills: nearest-tick rounding of raw bar prices (TradingView fill rule) - #163
Merged
Conversation
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.
Fills taken at a raw bar price are rounded to the nearest tick the way TradingView does it:
floor(price / mintick + 0.5) * mintickevaluated 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_mintickis now that function; a newbar_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_directionalis kept for computed stop/limit levels only. An earlier attempt that quantized the feed with a+1e-6epsilon 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.cppembeds all 1,213 distinct midpoint-down census values; ctest 137/137.