Skip to content

Add label.set_text_font_family, label.set_text_formatting and label.new text_formatting - #306

Merged
alexgrover merged 1 commit into
LuxAlgo:devfrom
lenstrats:fix/label-text-formatting
Sep 15, 2026
Merged

alexgrover merged 1 commit into
LuxAlgo:devfrom
lenstrats:fix/label-text-formatting

Conversation

@lenstrats

Copy link
Copy Markdown

Problem

label.set_text_font_family() and label.set_text_formatting() cannot be called from scripts. LabelHelper has no namespace-level setters for them, and Context does not bind them. (LabelObject did have set_text_font_family, but only as a method.) label.new() also ignores the v6 text_formatting argument.

//@version=6
indicator("repro", overlay = true)
if barstate.islast
    l = label.new(bar_index, high, "x", text_formatting = text.format_bold)
    label.set_text_font_family(l, font.family_monospace)
plot(close)

TypeError: label.set_text_font_family is not a function

This script compiles on TradingView. 7 of 729 popular open-source indicators failed on this.

Fix

This mirrors the existing box implementation:

  • Add set_text_font_family and set_text_formatting to LabelHelper, and bind them in Context.
  • Store text_formatting on LabelObject (constructor, copy() and toPlotData()). The default is "none", matching text.format_none.
  • Accept text_formatting in label.new(), both positionally (after force_overlay) and as a named argument.
  • Route the LabelObject method delegates through the helper, like the other setters.
  • Update the API coverage docs (label.md, pinescript-v6/label.json).

Tests

  • tests/namespaces/label/label.test.ts: the two setters, plus a native Pine script covering text_formatting in label.new(), method-call syntax and label.copy(). The Pine script compiles on TradingView.
  • The new tests fail on dev (label.set_text_font_family is not a function) and pass with this change. Full suite: 1840 passed, 5 skipped, 16 todo.
  • Real indicators: 5 of the 7 affected indicators now run without errors. The other 2 stop at unrelated issues.
  • Differential check: all 729 indicators were run on identical cached market data within the same clock hour, once against dev and once against this branch. 5 now run without errors. 2 get past the missing setter and then stop at other unsupported features. No regressions. The only changed output values are in 6 scripts that use timenow or math.random; their output also differs between two identical dev runs. Output was compared with the text_formatting key left out, because this change adds that key to every label.

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

🤖 Generated with Claude Code

…ew text_formatting

label.set_text_font_family() and label.set_text_formatting() could not be
called from scripts: LabelHelper had no namespace-level setters and Context
did not bind them, so scripts threw "label.set_text_font_family is not a
function". label.new() also ignored the v6 `text_formatting` argument.

Mirrors the existing box implementation: setters on LabelHelper bound in
Context, `text_formatting` stored on LabelObject (constructor, copy() and plot
data), and the LabelObject method-call delegates now route through the helper.
API coverage docs updated.

Found in 7 of 729 popular open-source TradingView indicators; 5 of them run
without errors with this change.

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.

@lenstrats

Copy link
Copy Markdown
Author

recheck

@alexgrover
alexgrover merged commit 331e49b into LuxAlgo:dev Sep 15, 2026
1 of 2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 15, 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