when
A rule: if the condition is true on the closed bar, run the body. if is the same word.
when condition actions
The body is indented, or use then for a one-liner, or { } braces. Put buy, sell, exit, arrow, label, paint, alert, or note inside. Alias: if rsi(14) is below 30 then buy. Prefer when in new scripts (if still works).
Return value
—
Also accepted: if.
Note
- Evaluation is on bar close, not tick-by-tick.
Example
when ema(9) crosses above ema(21) and bullish buy arrow up "Buy" paint green