Draws a text label at a bar and price, with a chosen shape, colors and size, and returns a handle to it.
label.new(bar_index, high, "Peak") places the text at the current bar's high. x is a bar index by default, or a timestamp when xloc is xloc.bar_time. With yloc.abovebar or yloc.belowbar the y value is ignored and the label sits just off the bar.
style does three jobs at once. label_down puts the bubble above the anchor with its tip on it, label_up puts it below, and label_left and label_right set it beside the anchor. The shape styles (circle, square, diamond, triangleup, triangledown, arrowup, arrowdown, flag, cross, xcross) mark the anchor and print the text next to the marker. label.style_none prints bare text.
A label created on every bar leaves a trail of them. Create one with var and move it with label.set_xy(), or delete the old one with label.delete().
Syntax
label.new(point: chart.point, text: series string (optional), xloc: series string (optional), yloc: series string (optional), color: series color (optional), style: series string (optional), textcolor: series color (optional), size: series int/string (optional), textalign: series string (optional), tooltip: series string (optional), text_font_family: series string (optional), force_overlay: const bool (optional), text_formatting: series text_format (optional)) -> series label
label.new(x: series int, y: series int/float, text: series string (optional), xloc: series string (optional), yloc: series string (optional), color: series color (optional), style: series string (optional), textcolor: series color (optional), size: series int/string (optional), textalign: series string (optional), tooltip: series string (optional), text_font_family: series string (optional), force_overlay: const bool (optional), text_formatting: series text_format (optional)) -> series labelArguments
| Name | Type | Default | Description |
|---|---|---|---|
| point | chart. | required | A chart.point that supplies both the bar and the price of the anchor in one value. The index is used with xloc.bar_index and the time with xloc.bar_time. |
| text | series string | "" | The words inside the label; \n starts a new line. The default is an empty string, which draws the shape with no text. na is read as empty. |
| xloc | series string | xloc. | xloc.bar_index (default) reads x as a bar index. xloc.bar_time reads it as a Unix timestamp in milliseconds, the unit of time. |
| yloc | series string | yloc. | yloc.price (default) places the label at y. yloc.abovebar and yloc.belowbar pin it just off the bar's high or low and ignore y. |
| color | series color | color. | Fill of the bubble or shape. The default is blue. na removes the fill, so only the text is left on the chart. |
| style | series string | label. | A label.style_* constant, label.style_label_down by default. It picks the shape, the side the pointer is on and where the box sits against the anchor. |
| textcolor | series color | color. | Color of the text, white by default. Pick one that contrasts with color; na is drawn white on Sidechair. |
| size | series int/ | size. | size.tiny, size.small, size.normal (default), size.large, size.huge or size.auto. A bigger size grows the text and, for shape styles, the marker. |
| textalign | series string | text. | text.align_left, text.align_center (default) or text.align_right: how the lines of a multi-line text line up. It has no visible effect on one line. |
| tooltip | series string | "" | Hover text for the label, empty by default so none shows. It is the place for detail that would crowd the bubble. |
| text_font_family | series string | font. | font.family_default (default) or font.family_monospace, which keeps digits in columns when the text has several lines. |
| force_overlay | const bool | false | true draws the label on the main chart pane even when the script runs in its own pane. The default, false, keeps it in the script's own pane. |
| text_formatting | series text_format | text. | text.format_none (default), text.format_bold, text.format_italic, or two of them joined with +, for example text.format_bold + text.format_italic. |
| x | series int | required | Bar index when xloc is xloc.bar_index, or a timestamp in milliseconds when it is xloc.bar_time. A value past bar_index puts the label to the right of the last bar. |
| y | series int/ | required | Price the label points at. Ignored when yloc is yloc.abovebar or yloc.belowbar, so na is fine there. |
Returns
series label: The new label, which later calls can edit or delete.
Remarks
- The default limit is 50 labels. When a script draws more than max_labels_count, the oldest labels disappear first.
- On Sidechair: max_labels_count is clamped to 500, and the limit is counted per script, with labels removed oldest first.
- On Sidechair: text_font_family and text_formatting are accepted but not drawn, textalign is stored but every line is drawn centered, and tooltip is stored but no hover text appears.
- On Sidechair: on the forming bar every tick re-runs the script, and labels created or edited by the previous tick are rolled back first, so a label made under
barstate.islastdoes not pile up.
Examples
//@version=6
indicator("label.new: new highs", overlay = true)
hh = ta.highest(high, 20)
if high == hh and high > hh[1]
label.new(bar_index, high, str.tostring(high, "#.##"), style = label.style_label_down, color = color.green, textcolor = color.white)//@version=6
indicator("label.new: above bar", overlay = true)
if close > open and volume > ta.sma(volume, 20) * 2
label.new(bar_index, na, "Vol", yloc = yloc.abovebar, style = label.style_label_down, color = color.orange)See also
Runs on Sidechair