Skip to content

Fix scale and settlement_as_close namespaces not resolving in scripts - #305

Merged
alexgrover merged 1 commit into
LuxAlgo:devfrom
lenstrats:fix/scale-namespace
Sep 17, 2026
Merged

alexgrover merged 1 commit into
LuxAlgo:devfrom
lenstrats:fix/scale-namespace

Conversation

@lenstrats

Copy link
Copy Markdown

Problem

scale and settlement_as_close are defined in src/namespaces/Types.ts, spread into the context, and listed as supported in docs/api-coverage/types.md. They are missing from CONTEXT_PINE_VARS, though, so the transpiler never binds them. Any script that uses them fails:

//@version=6
indicator("repro", scale = scale.right)
plot(close)

ReferenceError: scale is not defined

This script compiles on TradingView. I ran 729 popular open-source indicators from TradingView through PineTS, and 12 of them failed on this.

Fix

  • Add scale and settlement_as_close to CONTEXT_PINE_VARS.
  • Add both to NAMESPACE_COLLISION_NAMES. Scripts often declare their own scale variable next to indicator(scale = scale.left), which TradingView allows.

Tests

  • tests/namespaces/constants.test.ts: the values of scale.* and settlement_as_close.*.
  • tests/transpiler/namespace-identifier-collision.test.ts: indicator(scale = scale.none) with overlay = true, and a user variable named scale. Both scripts compile on TradingView.
  • The 4 new tests fail on dev (scale is not defined) and pass with this change. Full suite: 1842 passed, 5 skipped, 16 todo.
  • Differential check: all 729 indicators were run on identical cached market data, once against dev and once against this branch. 8 now run without errors. 4 get past scale and then stop at other unsupported features. The other scripts show no regressions and no changed output values. 8 scripts give different output on two identical dev runs, so I left them out of the value comparison.

The repro scripts and tooling are in https://github.com/lenstrats/pinets-compat.

🤖 Generated with Claude Code

The `scale` and `settlement_as_close` enums exist in namespaces/Types.ts and
are spread into the context, but were missing from CONTEXT_PINE_VARS, so the
transpiler never bound them and any `scale.*` reference threw
"scale is not defined" (e.g. `indicator("x", scale = scale.right)`).

Also add both to NAMESPACE_COLLISION_NAMES: scripts commonly declare a
variable named `scale` next to `indicator(scale = scale.left)`, which
TradingView allows.

Found in 12 of 729 popular open-source TradingView indicators.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@baslentfert

Copy link
Copy Markdown
Contributor

I have read the CLA Document and I hereby sign the CLA

alaa-eddine added a commit to LuxAlgo/cla-signatures that referenced this pull request Sep 11, 2026
@alexgrover
alexgrover merged commit 02efd25 into LuxAlgo:dev Sep 17, 2026
1 of 2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants