Match TV's na-source output rules for ta.ema and ta.sma#93
Merged
Conversation
TradingView pins different OUTPUT rules per function over a conditionally-na source, with identical state rules (na input never updates and never resets state): ta.ema RETURNS NA on the na-input bar and resumes the recursion over valid inputs — the same pattern this engine already implements for RMA — while ta.sma returns the HELD compact-window mean on every bar once N valid values have been seen, persisting through arbitrarily long na runs. The engine had both backwards: EMA returned the held value on na bars, SMA returned na. Pinned by a clean-room probe (committed with its TV export) whose winning hypotheses scored zero mismatches on all 11,060 decision bars per leg; the four competing na rules were each refuted by thousands of mismatched bars. Return paths only — state mutation, RMA/WMA/VWMA, and seed conventions untouched. SMA's intra-bar security recompute path keeps its old na return (undiscriminated by the probe; documented asymmetry pending its own pin). One legacy assertion that pinned the old EMA held-output behavior is flipped to the TV rule. Exemplar: the na-gated cloud strategy improves canonical match 95.8→99.0, coverage 81.7→90.7, exit p90 0.0947→0.0012; the probe converges 3656/3658; corpus 240/11/1 zero movement; full private sweep 0 up / 0 down. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Over a conditionally-na source (
cond ? x : na), TV pins different output rules per function with identical state rules (na never updates, never resets):ta.emareturns na on the na-input bar, resuming the recursion over valid inputs — the engine's existing RMA pattern. The engine returned the held value.ta.smareturns the held compact-window mean once seeded, persisting through 32+-bar na runs. The engine returned na.Pinned by a committed clean-room probe: the winning hypotheses scored 0/11,060 mismatched decision bars per leg; each competing rule (hold-and-ignore, re-seed, na-propagate, count-na-in-length) was refuted by thousands of bars. Return paths only; RMA/WMA/VWMA, state mutation, and seed conventions untouched. SMA's intra-bar security recompute keeps its old na return (undiscriminated — documented asymmetry pending its own pin).
Gates (author + independent fresh-context R7, both green)
🤖 Generated with Claude Code