Documentation/AlgoCode/Function reference

when

A rule: if the condition is true on the closed bar, run the body. if is the same word.

Reference/Language/Language

when condition
  actions

The body is indented, or use then for a one-liner, or { } braces. Put buy, sell, exit, alert, or note inside. buy / sell / exit already draw an arrow and the fill price — skip arrow, label, and paint unless you want a custom caption or bar tint. 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

See also