tag
Level tags: a price shown as a name tag and a price tag at the right edge of the pane, with a line where chosen.
#Functions
#tag.auto_keepfunction
How many tag.place_auto tags on each side of the live price get their line (default 2, 0-6), for the whole script.
tag.auto_keep(n: int)| Parameter | Type | Description |
|---|---|---|
n | int | Auto tags per side of the live price that get the line (0-6). |
Example
tag.auto_keep(3)Since ChartScript 1
#tag.deletefunction
Removes the tag (na is ignored).
tag.delete(id: tag)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
Example
state t = tag.new(open, "Open")
if (barstate.islast) {
t.delete()
}Since ChartScript 1
#tag.get_placefunction
The placement the script set (tag.place_*).
tag.get_place(id: tag): string| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
Returns string.
Example
state t = tag.new(open, "Open")
const p = t.get_place()Since ChartScript 1
#tag.get_pricefunction
The price.
tag.get_price(id: tag): float| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
Returns float.
Example
state t = tag.new(open, "Open")
const p = t.get_price()Since ChartScript 1
#tag.get_textfunction
The name.
tag.get_text(id: tag): string| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
Returns string.
Example
state t = tag.new(open, "Open")
const s = t.get_text()Since ChartScript 1
#tag.newfunction
A level tag: the name in a filled tag inside the pane against the price axis and the price in the same colour on the axis, in one row with the other tags of the pane (pushed rows keep their price order). A tag off the visible prices is pinned at that edge. The member can change each titled tag's placement, line and colour in the Style tab, and switch all of a script's tags with "Level tags". 64 per script (32 on Beginner); the oldest is removed.
tag.new(price: float, text: string, { place?: string = tag.place_axis, color?: color = na, textcolor?: color = na, show_price?: bool = true, line_from?: int = na, line_to?: string = tag.line_to_tag, line_style?: string = line.style_solid, line_width?: int = 1, line_color?: color = na, tooltip?: string = "", title?: const string = "", size?: size = size.normal, xloc?: simple string = xloc.bar_index }): tag| Parameter | Type | Description |
|---|---|---|
price | float | The price of the level; na hides the tag. |
text | string | The name in the name tag (24 characters at most; longer is cut with "…"). The price has its own tag on the axis. |
place | stringdefault tag.place_axis | tag.place_chart (name, price and the line), tag.place_axis (name and price, no line), tag.place_off (nothing drawn, the tag is kept) or tag.place_auto (the line only while the tag is among the tag.auto_keep nearest above or below the live price). |
color | colordefault na | The fill of both tags and the line's colour (na: the chart's accent). The text is dark or white, whichever reads better. |
textcolor | colordefault na | The text colour of both tags (na: dark or white by the fill). |
show_price | booldefault true | true: the price tag on the axis in the same row; false: the name tag only. |
line_from | intdefault na | The bar the line starts at (a bar index, or a time with xloc.bar_time); na: the pane's left edge. |
line_to | stringdefault tag.line_to_tag | tag.line_to_tag: the line ends at the name tag; tag.line_to_bars: at the last bar (with line_from na: a stub from the last bar to the tag). |
line_style | stringdefault line.style_solid | line.style_solid, line.style_dashed, line.style_dotted or a dash.* pattern. |
line_width | intdefault 1 | The line width, 1-4 px. |
line_color | colordefault na | The line colour when it differs from color. |
tooltip | stringdefault "" | The hover text of both tags; the chart puts the name and the exact price first. |
title | const stringdefault "" | A name for the Style tab: a titled tag gets its own Style row (placement, line, colour, price on the axis). |
size | sizedefault size.normal | size.small (9 px) or size.normal (10 px). |
xloc | simple stringdefault xloc.bar_index | How line_from is read: xloc.bar_index or xloc.bar_time. |
Returns tag.
Example
state t = tag.new(open, "Day open", { color: color.orange, place: tag.place_chart, tooltip: "The first price of the run", title: "Day open" })Since ChartScript 1
#tag.set_colorfunction
Sets the colour of the tags and the line.
tag.set_color(id: tag, color: color)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
color | color | The fill of both tags and the line's colour (na: the chart's accent). The text is dark or white, whichever reads better. |
Example
state t = tag.new(open, "Open")
t.set_color(close > open ? color.up : color.down)Since ChartScript 1
#tag.set_line_colorfunction
Sets the line colour.
tag.set_line_color(id: tag, line_color: color)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
line_color | color | The line colour when it differs from color. |
Example
state t = tag.new(open, "Open", { place: tag.place_chart })
t.set_line_color(color.gray)Since ChartScript 1
#tag.set_line_fromfunction
Sets the bar the line starts at (na: the pane's left edge).
tag.set_line_from(id: tag, line_from: int, { xloc?: string = xloc.bar_index })| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
line_from | int | The bar the line starts at (a bar index, or a time with xloc.bar_time); na: the pane's left edge. |
xloc | stringdefault xloc.bar_index | How line_from is read: xloc.bar_index or xloc.bar_time. |
Example
state t = tag.new(open, "Open", { place: tag.place_chart })
t.set_line_from(bar_index - 20)Since ChartScript 1
#tag.set_line_stylefunction
Sets the line style (line.style_* or dash.*).
tag.set_line_style(id: tag, line_style: string)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
line_style | string | line.style_solid, line.style_dashed, line.style_dotted or a dash.* pattern. |
Example
state t = tag.new(open, "Open", { place: tag.place_chart })
t.set_line_style(line.style_dashed)Since ChartScript 1
#tag.set_line_tofunction
Sets where the line ends (tag.line_to_*).
tag.set_line_to(id: tag, line_to: string)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
line_to | string | tag.line_to_tag: the line ends at the name tag; tag.line_to_bars: at the last bar (with line_from na: a stub from the last bar to the tag). |
Example
state t = tag.new(open, "Open", { place: tag.place_chart })
t.set_line_to(tag.line_to_bars)Since ChartScript 1
#tag.set_line_widthfunction
Sets the line width (1-4 px).
tag.set_line_width(id: tag, line_width: int)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
line_width | int | The line width, 1-4 px. |
Example
state t = tag.new(open, "Open", { place: tag.place_chart })
t.set_line_width(2)Since ChartScript 1
#tag.set_placefunction
Sets the placement (tag.place_*); tag.place_off hides the tag and keeps it.
tag.set_place(id: tag, place: string)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
place | string | tag.place_chart (name, price and the line), tag.place_axis (name and price, no line), tag.place_off (nothing drawn, the tag is kept) or tag.place_auto (the line only while the tag is among the tag.auto_keep nearest above or below the live price). |
Example
state t = tag.new(open, "Open")
t.set_place(tag.place_auto)Since ChartScript 1
#tag.set_pricefunction
Sets the price (na hides the tag; the same as set_y).
tag.set_price(id: tag, price: float)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
price | float | The price of the level; na hides the tag. |
Example
state t = tag.new(open, "High")
t.set_price(math.max(t.get_price(), high))Since ChartScript 1
#tag.set_show_pricefunction
Shows or hides the price tag on the axis.
tag.set_show_price(id: tag, show_price: bool)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
show_price | bool | true: the price tag on the axis in the same row; false: the name tag only. |
Example
state t = tag.new(open, "Open")
t.set_show_price(false)Since ChartScript 1
#tag.set_textfunction
Sets the name.
tag.set_text(id: tag, text: string)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
text | string | The name in the name tag (24 characters at most; longer is cut with "…"). The price has its own tag on the axis. |
Example
state t = tag.new(open, "Open")
t.set_text("Open " + str.tostring(open))Since ChartScript 1
#tag.set_textcolorfunction
Sets the text colour.
tag.set_textcolor(id: tag, textcolor: color)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
textcolor | color | The text colour of both tags (na: dark or white by the fill). |
Example
state t = tag.new(open, "Open")
t.set_textcolor(color.white)Since ChartScript 1
#tag.set_tooltipfunction
Sets the hover text.
tag.set_tooltip(id: tag, tooltip: string)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
tooltip | string | The hover text of both tags; the chart puts the name and the exact price first. |
Example
state t = tag.new(open, "Open")
t.set_tooltip("The first price of the run")Since ChartScript 1
#tag.set_yfunction
Sets the price (na hides the tag).
tag.set_y(id: tag, price: float)| Parameter | Type | Description |
|---|---|---|
id | tag | The tag. |
price | float | The price of the level; na hides the tag. |
Example
state t = tag.new(open, "Last")
t.set_y(close)Since ChartScript 1
#Variables
#tag.allvariable
Every tag of the script that still exists, oldest first.
tag.all: array<tag>Type series array<tag>.
Example
const n = array.size(tag.all)Since ChartScript 1
#Constants
| Name | Type | Description |
|---|---|---|
tag.line_to_bars | string | The line ends at the last bar. |
tag.line_to_tag | string | The line ends at the name tag. |
tag.place_auto | string | Placement: the line only while the tag is among the tag.auto_keep nearest above or below the live price (decided by the chart as price moves). |
tag.place_axis | string | Placement: the name and price tags, no line. |
tag.place_chart | string | Placement: the name and price tags and the line. |
tag.place_off | string | Placement: nothing drawn; the tag is kept. |