Skip to content

Match TradingView rolling sums and same-pass percentage closes - #195

Merged
luisleo526 merged 3 commits into
mainfrom
round12/candidate-w
Sep 6, 2026
Merged

luisleo526 merged 3 commits into
mainfrom
round12/candidate-w

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Align rolling sums and biased ta.stdev with pinned TradingView arithmetic. Preserve the script-pass position basis for ordinary process_orders_on_close percentage closes: two 30% closes of 800,000 each close 240,000, while closes on different bars use the remaining position.

Validation on engine ff4a6b897b66a97d78a7c5aa8ca4b02b6804bd94 with codegen 3fd97fe28abd7b191cb376d9f5db4e056fcfae4b:

  • Cloud Run: 72/72 cases, all 4,190 probes measured; 11 strong-to-excellent conversions, zero tier drops and no new moderate. Result: 4,145 excellent / 44 strong / 1 moderate.
  • Gate pineforge-pr-gate-n95c8: PASS, zero regressions or tolerances across 704 hard probes, target two-band score +10.
  • 201 C++ unit tests passed; C ABI check passed; independent Grok review of the exact combined commit: GREEN, P0/P1/P2 = 0.

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 engine c86c082c811fbfe476e307a005722ccef982e0e8.

luisleo526 and others added 3 commits September 6, 2026 10:34
… 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]>
@luisleo526
luisleo526 merged commit ff4a6b8 into main Sep 6, 2026
8 checks passed
@luisleo526
luisleo526 deleted the round12/candidate-w branch October 5, 2026 02:44
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