flag
Drops a flag marker at a specific bar and price. Use it to tag important events (news, earnings, alerts) with a clean, minimal icon. It’s lighter than notes/callouts—just a colored flag, optionally with a short label.
Syntax (one line)
flag(time, price, styles?, text?)
Parameters
time (number) · Candle time where the flag is placed (e.g., time(0)).
price (number) · Price level where the flag sits (e.g., closeC(0)).
styles (FlagMarkLineToolOverrides) · Marker appearance:
flagColor(RGBAColor | BaseColors) · Color of the flag icon.text(string) · Optional short label shown near the flag (e.g.,"News").
Return Value
(string) · The drawing ID of the created Flag.
Example
What this does: Every 48 candles, it plants a yellow flag at the current close with a tiny label. All visuals live in one const style.
//@version=1
init = () => {
indicator({ onMainPanel: true, format: 'inherit' });
};
onTick = () => {
if (index % 48 === 0) { // draw occasionally to keep charts clean
// 1) Style (FlagMarkLineToolOverrides)
const style = {
flagColor: color.rgba(255, 193, 7, 0.95) // amber flag
};
// 2) Place the flag at this bar’s close
flag(time(0), closeC(0), style, "News");
}
};Tips
Use a consistent color code (e.g., amber for info, red for risk) so flags are instantly understood.
Keep labels very short (1–2 words) to avoid covering candles.
Warning
Spamming flags on every candle will clutter the chart—mark only key events.
Good Practice
Centralize your preferred flag color in a single
const styleso you can reuse it across scripts.Pair flags with your entries/exits to quickly scan important events during backtests.
Last updated