tip
Tooltip cards. A tooltip is a string; the tip.* functions write a structured card into it: a title, badges, rows of label and value, checks, pages, a reward-to-risk bar, a mini line, a stat grid and an icon. Start with tip.card and add the parts with +. The chart draws the card in its own theme; a script never supplies markup, colours or pictures.
#Functions
#tip.badgefunction
A small pill beside the title (4 at most), in a tone when one is given.
tip.badge(text: string, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
text | string | The badge text, 20 characters at most. |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.badge("1.4R", tip.up)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.barfunction
A progress bar: value between min and max (4 bars at most per page, tip.rr included).
tip.bar(value: float, min: float, max: float, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
value | float | The value to show between min and max. |
min | float | The value at the empty end of the bar. |
max | float | The value at the full end of the bar (above min). |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.bar(ta.rsi(close, 14), 0, 100, tip.accent)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.bulletfunction
One bullet point.
tip.bullet(text: string): string| Parameter | Type | Description |
|---|---|---|
text | string | The text. Markup characters in it are escaped, so it is shown exactly as given. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.bullet("Trend up") + tip.bullet("Volume rising")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.cardfunction
Starts a tooltip card and returns its first lines; add the other tip.* parts with + and pass the result as a tooltip (label.new, table.cell, tag.new, drawing.position). A tooltip that does not start with tip.card is shown as plain text.
tip.card(title: string, { sub?: string = "", rotate?: int = 0 }): string| Parameter | Type | Description |
|---|---|---|
title | string | The card title: one line, 80 characters at most ("" = a card without a header). |
sub | stringdefault "" | A subtitle under the title ("" = none), 80 characters at most. |
rotate | intdefault 0 | Milliseconds per page for a card with pages; 0 (the default) = the pages change only by hand. 2500 at least, 20000 at most. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup", { sub: "Demand zone held twice" }) + tip.row("Stop", str.tostring(low, "#.##"))
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.checkfunction
One line of a checklist: passed (true), failed (false) or, with no state, neutral.
tip.check(text: string): stringtip.check(text: string, state: bool): string| Parameter | Type | Description |
|---|---|---|
text | string | The text. Markup characters in it are escaped, so it is shown exactly as given. |
state | bool | true = passed, false = failed; left out = neutral (shown, not counted). |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.check("Above the 200 EMA", close > ta.ema(close, 200)) + tip.check("Open interest: not on this market")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.dividerfunction
A thin line between parts.
tip.divider(): stringReturns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.text("Entry on the close") + tip.divider() + tip.note("Example only")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.iconfunction
A built-in icon beside the title. Pictures from the internet are not possible in a tooltip.
tip.icon(name: string, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
name | string | An icon of the built-in set: target, stop, flag, bolt, clock, warning, check, cross, up, down, flat, volume, liquidity, news, calendar, star, info, shield, rocket, fire, eye, lock, chart, coin. Another name draws nothing. |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.icon("target")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.notefunction
A muted note.
tip.note(text: string): string| Parameter | Type | Description |
|---|---|---|
text | string | The text. Markup characters in it are escaped, so it is shown exactly as given. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.note("Shown only, not counted.")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.pagefunction
Starts a page: the parts that follow belong to it until the next tip.page. A card holds 6 pages at most; the reader changes pages with the tabs, the arrow keys, the mouse wheel or a swipe.
tip.page(title: string): string| Parameter | Type | Description |
|---|---|---|
title | string | The page title shown on its tab, 24 characters at most. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.page("Signal") + tip.text("Why it fired") + tip.page("Risk") + tip.rr(close - low, high - close)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.rotatefunction
Lets the pages change by themselves every ms milliseconds while the pointer rests on the label. It stops when the pointer is on the card, when the card is pinned, after a step by hand, and always when the reader asked for reduced motion.
tip.rotate(ms: int): string| Parameter | Type | Description |
|---|---|---|
ms | int | Milliseconds per page: 2500 at least, 20000 at most; 0 or na = no rotation. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.page("Signal") + tip.text("Why") + tip.page("Risk") + tip.text("How much") + tip.rotate(4000)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.rowfunction
A row with a muted label on the left and a right-aligned value, in a tone when one is given.
tip.row(label: string, value: string, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
label | string | The label on the left, 40 characters at most. |
value | string | The value, right-aligned (60 characters at most): format numbers with str.tostring. |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.row("Stop", str.tostring(low, "#.##")) + tip.row("Target", str.tostring(high, "#.##"), tip.up)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.rrfunction
A reward-to-risk bar drawn from two positive numbers, with the ratio in the middle.
tip.rr(risk: float, reward: float): string| Parameter | Type | Description |
|---|---|---|
risk | float | The risk as a positive number (the distance from the entry to the stop). |
reward | float | The reward as a positive number (the distance from the entry to the target). |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.rr(close - low, 2 * (close - low))
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.sectionfunction
A small uppercase heading above the parts that follow.
tip.section(title: string): string| Parameter | Type | Description |
|---|---|---|
title | string | The section heading, 80 characters at most. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.section("Checks") + tip.check("Volume above average", true)
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.sparkfunction
A mini line of the last numbers of an array (2 per card at most).
tip.spark(values: array<num>, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
values | array<num> | An array of numbers, oldest first; the last 60 are drawn (na values are skipped; fewer than 2 draws nothing). |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
state last: array<float> = array.new_float()
last.push(close)
if (last.size() > 30) {
last.shift()
}
if (barstate.islast) {
const t = tip.card("Last 30 closes") + tip.spark(last, tip.accent)
label.new(bar_index, high, "S", { tooltip: t })
}Since ChartScript 1
#tip.statfunction
One cell of a stat grid: a big value over a small label. Cells written one after another form one grid, three to a row (9 at most per page).
tip.stat(value: string, label: string, { tone?: string = "" }): string| Parameter | Type | Description |
|---|---|---|
value | string | The big text of the cell (16 characters at most): format numbers with str.tostring. |
label | string | The small text under the value, 24 characters at most. |
tone | stringdefault "" | A tone: tip.up, tip.down, tip.warn, tip.muted or tip.accent ("" = none). The theme gives the colour. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.stat("58%", "Won") + tip.stat("0.4R", "Per trade", tip.up) + tip.stat("22", "Days")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#tip.textfunction
A paragraph. Line breaks in the text are kept; each line holds 400 characters at most.
tip.text(text: string): string| Parameter | Type | Description |
|---|---|---|
text | string | The text. Markup characters in it are escaped, so it is shown exactly as given. |
Returns string.
Example
if (barstate.islast) {
const t = tip.card("Long setup") + tip.text("The zone held twice in the last hour.")
label.new(bar_index, high, "L", { tooltip: t })
}Since ChartScript 1
#Constants
| Name | Type | Description |
|---|---|---|
tip.accent | string | The accent tone. |
tip.down | string | The tone of a loss (the theme's down colour). |
tip.muted | string | The muted tone. |
tip.up | string | The tone of a gain (the theme's up colour). |
tip.warn | string | The tone of a warning. |