Repository navigation
Match TradingView rolling sums and same-pass percentage closes - #195
Merged
Merged
Conversation
… compensation is under-applied to the incoming source, and ta.stdev is sqrt(Sxx/n - m*m) over the same sliding sums (round 9, family W, jayentriken stochRSI/BBWP on six lanes) KahanWindowSum (ta.sma / math.sum): the round-7 trigger "the incoming source swallows the carried compensation" (c != 0 and fl(x - c) == x) is the special case of the rule TradingView actually applies: with y0 = fl(x - c_pre), the window is re-summed newest-first (c reset, the bar's ring addend stored as the raw source) whenever |y0 - x| < |c_pre| -- the compensation was under-applied (fully swallowed, or rounded toward x: 1.25 ulp applied as 1 ulp, a 1.5-ulp tie resolved toward x). An exact subtraction or one rounded away from x continues. Pinned on a full-precision NYSE:F@15 oracle (pineforge-workflow tapes famw-f15-kdhi-0..7000, every value exported as its exact double): math.sum(stoch, 3) 7,018/7,018 and k = sum/3 7,018/7,018 bit-exact (round 7: 6,849), every k vs d sign and ta.crossover/crossunder event on the lane identical to TradingView (round 7: 24 signs, 12 events wrong -- the family-W divergences). Open pin: on residue-only inputs (|x| ~ 1e-15 comparable to |c|) TradingView's decision is a signed comparison (it flips under negation of the series); the magnitude form reproduces 6,991/7,016 math.sum(k, 3) bars there and no k vs d decision on the lane depends on those bits. StdDev (ta.stdev, biased): sqrt(Sxx / n - m * m) with m = Sx / n, where Sx = math.sum(src, n) and Sxx = math.sum(src * src, n) are the same KahanWindowSum sliding sums -- 7,029/7,029 bars bit-exact on the famw-f15-sd-* oracle (the documented two-pass form is exact on none). This is why two identical 7-close windows rank differently in the strategy's BBW percentile on TradingView. BB / BBW inherit it; the unbiased variant keeps the two-pass arithmetic (unpinned). recompute() replays the bar through KahanWindowSum::repush. tests: test_ta_window_underapplied (10 cold-start-synced segments through the pinned re-sum bars + the range-start stdev segment, bit-for-bit); the round-7 residual pins (test_ta_sma_window_residual, 12,905 checks) still pass, and test_ta_sma_stochrsi_ties' open 2025-06-03 01:15 case now fires like TradingView.
…n's magnitude, added to the source, is under-applied (round 10, family W stage 2: onuriano/jayentriken stochRSI residue plateaus) The re-sum trigger of KahanWindowSum (ta.sma, math.sum) reads |fl(x + |c|) - x| < |c| instead of round 9's |fl(x - c) - x| < |c|: the quantity TradingView tests is the compensation's MAGNITUDE added to the incoming source. On ordinary sources (|c| << |x|) both forms round alike; on residue-only plateaus (|x| ~ 1e-15 ~ |c|), on sources within |c| of a power of two, and on negative sources they differ and TradingView follows x + |c| (its decision flips under negation of the series). Eviction, add and the post-re-sum state are unchanged. Pinned by pineforge-workflow r9-famW-5 on 21,509 labelled decisions: the onuriano and jayentriken NYSE:F@15 oracles (math.sum(stoch, 3) 7,018/7,018, math.sum(k, 3) 7,016/7,016 each, bit-exact; round 9: 6,920 and 6,991), the stdev sums 7,029/7,029 x2, and 1,003 lab tv literal replays (dense +-40 ulp neighbourhoods, sign mirrors, binade straddles, window lengths 3 and 5). test_ta_window_round10 carries 15 oracle segments and 57 literal replays (24 decide differently under the round-9 form); test_ta_window_underapplied is unchanged and still bit-exact. Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.
Align rolling sums and biased
ta.stdevwith pinned TradingView arithmetic. Preserve the script-pass position basis for ordinaryprocess_orders_on_closepercentage closes: two 30% closes of 800,000 each close 240,000, while closes on different bars use the remaining position.Validation on engine
ff4a6b897b66a97d78a7c5aa8ca4b02b6804bd94with codegen3fd97fe28abd7b191cb376d9f5db4e056fcfae4b:pineforge-pr-gate-n95c8: PASS, zero regressions or tolerances across 704 hard probes, target two-band score +10.The p181342x EURUSD target remains strong and unresolved: canonical match rate changes from 97.4% to 97.0%, while the trade-count gap improves from 2 to 1 and PnL P90 decreases from 0.0012 to 0.0008. This candidate does not claim that residual is closed.
Candidate snapshot:
59de2165cd564ce998f48dee1d9588fd440c8e8cd4973da499a111dd7bd31c81(788,865 bytes), compared with baseline enginec86c082c811fbfe476e307a005722ccef982e0e8.