Stickers
🧾 Overview
This example shows how to toggle stickers on the chart and place one every 30 candles. When enabled, it draws a Bitcoin sticker at the open price of the current bar.
🔍 What this example does
Adds a Show Sticker switch in
init.On each update, if the switch is on and the bar count hits a multiple of 30, it places a sticker on the chart.
init = () => {
input.bool("Show Sticker", true, "show");
};
onTick = (length, _moment, _, ta, inputs) => {
if (inputs.show && length % 30 === 0) {
sticker(time(0), openC(0), StickersList.bitcoin);
}
};🧱 Key pieces explained
input.bool("Show Sticker", true, "show")Creates a toggle input (default on) and stores its value asinputs.show.onTick = (length, _moment, _, ta, inputs) => { ... }length: number of bars currently loaded (0‑indexed + 1 in practice).inputs: object with your user inputs (e.g.,inputs.show).Other params (
_moment,_,ta) are available utilities/placeholders in this signature.
length % 30 === 0Triggers the action every 30 bars (30, 60, 90, …). Simple throttle to avoid spamming.sticker(time(0), openC(0), StickersList.bitcoin)Draws a sticker at:time(0): the timestamp of the current bar.openC(0): the open price of the current bar.StickersList.bitcoin: a predefined icon from the stickers list.
Warning
Using index
0(current, not-yet-closed candle) may change while the bar is forming. If you want confirmed placement, usetime(1)andopenC(1)instead.Placing stickers too frequently can clutter the chart and may affect performance on long histories.
Good Practice
Expose a frequency input (e.g., “Every N bars”) and a sticker type input so users can customize behavior:
input.int("Every N bars", 30, "freq")input.str("Sticker", "bitcoin", "icon")(or an enum input if available)
Gate actions to once per bar by storing the last processed time (e.g.,
lastBarTime) to avoid duplicate placements on fast ticks.
Last updated