Skip to content

How to size TradingView labels with a Pine Script input?

How to size TradingView labels with a Pine Script input?

Section titled “How to size TradingView labels with a Pine Script input?”

TL;DR
Offer a dropdown with the supported label sizes, translate the selection into a label.size_* constant, and reuse that value whenever you create or update labels.

DifficultyBeginner
Time to implement10-15 min
CategoryVisual Effects
//@version=5
indicator("Resizable labels", overlay=true, max_labels_count=500)
labelSizeInput = input.string("default", "Label size", options=["very small", "small", "default", "large", "very large"])
labelSizeFromInput(string value) =>
switch value
"very small" => label.size_tiny
"small" => label.size_small
"large" => label.size_large
"very large" => label.size_huge
=> label.size_normal
sizeSetting = labelSizeFromInput(labelSizeInput)
if barstate.islast
label.new(bar_index, high, text="Size: " + labelSizeInput, style=label.style_label_down, textcolor=color.white, bgcolor=color.new(color.blue, 65), size=sizeSetting)
Tip. Keep the dropdown values human-friendly, but always map them back to the built-in `label.size_*` constants before you pass them to `label.new()` or `label.set_size()`.

Charts rarely ship with one-size-fits-all annotations. Allowing traders to resize labels helps them fit more (or less) text, align with branding, or keep overlays readable on different monitors. Inputs provide the control; a small helper function keeps the sizing logic consistent everywhere labels are used.

  • Capture label-size preferences with input.string().
  • Translate human-readable dropdown values into Pine’s label.size_* enum.
  • Apply the selected size when creating new labels or updating existing ones.
  • Reuse the helper across multiple label types (signals, stats, tooltips).
CallPurpose
input.string(defval, title, options=[])Renders a dropdown for label size choices.
label.size_*Enum constants Pine expects when sizing labels.
label.new(x, y, text, size=...)Creates an annotation with the chosen size.
label.set_size(id, size)Updates an existing label when preferences change.
switchCleanly maps input strings to size constants.
  1. Collect the size preference
    Use a dropdown with descriptive options so users recognise each size.

    sizeChoice = input.string("default", "Label size", options=["very small", "small", "default", "large", "very large"], tooltip="Controls label.size_* constant")
  2. Map strings to label.size_* constants
    Convert the selection once and reuse the result throughout the script.

    labelSize(string value) =>
    switch value
    "very small" => label.size_tiny
    "small" => label.size_small
    "large" => label.size_large
    "very large" => label.size_huge
    => label.size_normal
  3. Apply the size to labels
    Pass the mapped constant to label.new() or label.set_size() whenever you render annotations.

    sizeSetting = labelSize(sizeChoice)
    tradeLabel = label.new(bar_index, high, text="Signal", size=sizeSetting)
//@version=5
indicator("Signal labels with sizing", overlay=true, max_labels_count=500)
sizeChoice = input.string("default", "Label size", options=["very small", "small", "default", "large", "very large"], tooltip="Pick how big signal labels should render")
textColour = input.color(color.white, "Text colour")
bgColour = input.color(color.new(color.blue, 70), "Background colour")
labelSize(string value) =>
switch value
"very small" => label.size_tiny
"small" => label.size_small
"large" => label.size_large
"very large" => label.size_huge
=> label.size_normal
sizeSetting = labelSize(sizeChoice)
fast = ta.ema(close, 12)
slow = ta.ema(close, 26)
bullish = ta.crossover(fast, slow)
bearish = ta.crossunder(fast, slow)
if bullish
label.new(bar_index, low, "Bull", style=label.style_label_up, size=sizeSetting, textcolor=textColour, bgcolor=bgColour)
if bearish
id = label.new(bar_index, high, "Bear", style=label.style_label_down, textcolor=textColour, bgcolor=bgColour)
label.set_size(id, sizeSetting)
Why this works.
  • A single helper translates user-friendly text into Pine’s enum values.
  • Both new labels and post-creation adjustments respect the same preference.
  • Separating colour inputs from size keeps the settings panel tidy but flexible.
  • label.size_auto is available if you’d rather Pine adapt the size to text, but users often prefer explicit control.
  • When you allow emojis or icons in labels, bump the default size to keep them legible.
  • Reapply label.set_size() after clearing/recreating labels so they stay in sync with updated input values.
  • If you manage dozens of labels, cache the size constant in a global variable to avoid recomputing inside loops.

The dropdown shows values I didn’t provide

Section titled “The dropdown shows values I didn’t provide”

Each option must be unique. Double-check the options array and make sure the default exists inside it.

Changing the input doesn’t resize existing labels

Section titled “Changing the input doesn’t resize existing labels”

Labels retain their original size until you call label.set_size() with the new constant. Re-run updates on the next bar or when detecting an input change (if barstate.isnew and sizeChoice != sizeChoice[1]).

Can I expose different sizes for different label types?

Section titled “Can I expose different sizes for different label types?”

Absolutely—duplicate the input (e.g., “Signal label size”, “Stats label size”) and keep separate helper calls for each context.

  • Collect label-size preferences via input.string() so users can resize annotations quickly.
  • Translate those strings to label.size_* constants with a small helper before applying them.
  • Use the mapped size for both new labels and any adjustments you make later via label.set_size().
  • Consistent sizing inputs improve readability while keeping scripts flexible for different chart setups.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.