FlowScript: Code Your Own Indicators · Lesson 3 of 10 · 9 min

History and built-in functions

Look back with [n], and lean on 70+ built-ins instead of doing the math yourself.

Every name keeps its value for every bar. Square brackets look back: close[1] is the previous close, myValue[3] is three bars ago.

indicator("Range expansion", overlay = false)

rangeNow = high - low
expansion = rangeNow / atr(14)
gap = open - close[1]

plot(expansion, "Range ÷ ATR", style = columns, color = expansion > 1.5 ? amber : gray)
plot(gap, "Gap", color = sky)
hline(1.5, "Expansion", color = amber)

Built-ins cover moving averages (sma, ema, hma, vwma), oscillators (rsi, stoch, cci, macd), volatility (atr, stdev, bb, kc), levels (highest, lowest, pivothigh), session tools (vwap, rth, new_session) and math. The Reference panel in Flow Studio documents every one with an example you can insert.

[upper, basis, lower] = bb(close, 20, 2)
top = plot(upper, "Upper", color = sky)
bottom = plot(lower, "Lower", color = sky)
fill(top, bottom, color = fade(sky, 8))

Key takeaways

  • name[n] reads n bars back.
  • Use built-ins for indicators; the Reference panel lists them all.
  • Multi-value functions are unpacked with [a, b] = …; missing history is na.

Next: Conditions, signals and alerts