Home / Learn / FlowScript reference

FlowScript language reference

FlowScript is FlowSense’s own small, safe language for chart indicators and signals: the grammar, every built-in with its cost, the three-valued rule for missing data, the limits and eight example scripts. FlowScript is part of Pro Max (in the app: the Strategies tab → FlowScript); this page is open to everyone.

What a script can do. Read the bars of the chart (open, high, low, close, volume, time) and draw: lines on the price or in a pane under it, levels, background shading, and ▲ / ▼ signals. What it cannot do. There is no JavaScript and no eval: the site reads your text into its own parse tree, checks every name and limit before anything runs, and runs it in a separate browser worker that is stopped after half a second. A script has no network, no storage, no access to your account or the page, no loops and no functions of its own — it is a list of named series, each computed once over the bars.

A first script

indicator("Two averages", overlay=true)
fast = input.int(10, "Fast", min=2, max=200)
slow = input.int(50, "Slow", min=2, max=500)
plot(ema(close, fast), "Fast", color=color.green)
plot(ema(close, slow), "Slow", color=color.red)
signal(crossover(ema(close, fast), ema(close, slow)), "long", "Fast crosses above slow")

Each line is one statement. A name is set once (fast = …) and is a whole series (one value a bar) or a single number. Operators work bar by bar. A window length or a lookback (close[3]) must be a fixed whole number, or an input.int with min= and max= inside 1..500 (0..500 for a lookback), so the cost of a script is known before it runs.

Missing data: the three-valued rule

Grammar

program      = { line } ;
line         = [ stmt ] [ comment ] NEWLINE ;
stmt         = header | assign | tuple_assign | out_call ;
header       = "indicator" "(" STRING { "," named } ")" ;     (* optional; the first line; overlay=true|false *)
assign       = IDENT "=" expr ;                                (* each name is assigned once *)
tuple_assign = "[" IDENT { "," IDENT } "]" "=" call ;          (* macd and bb give three series *)
out_call     = call ;                                          (* plot, hline, bgcolor and signal stand alone *)
expr         = ternary ;
ternary      = binary [ "?" expr ":" expr ] ;
binary       = unary { BINOP unary } ;
unary        = ( "-" | "+" | "not" ) unary | postfix ;
postfix      = primary { "[" expr "]" } ;                      (* lookback: a whole number 0..500 *)
primary      = NUMBER | STRING | COLOR | "true" | "false" | "na" | call | name | "(" expr ")" ;
call         = name "(" [ arg { "," arg } ] ")" ;              (* at most 8 values *)
arg          = [ IDENT "=" ] expr ;
name         = IDENT [ "." IDENT ] ;                           (* a dot only after input. and color. *)

BINOP, low to high:  or   and   == !=   < <= > >=   + -   * / %
IDENT   = letter or _ then letters, digits, _ (ASCII, at most 32; a leading __ is refused)
NUMBER  = digits [ . digits ] [ e [+|-] digits ]               (at most 24 characters)
STRING  = "…" on one line, \" and \\ only                    (at most 120 characters)
COLOR   = #rrggbb or #rrggbbaa
comment = // to the end of the line

Keywords: indicator and or not true false na. Every keyword, built-in, series name and the names of JavaScript’s object internals (constructor, __proto__, toString, …) are reserved and cannot be assigned.

Built-ins

Cost is counted in steps a bar (the site refuses a script whose cost on 5,000 bars passes 5,000,000 steps) and slots a bar (at most 3,000,000 in all).

NameUseReturnsWhat it doesCost
smasma(src, len)seriesSimple moving average over len bars; na while any bar in the window is na.4 steps/bar, 1 slot/bar
emaema(src, len)seriesExponential moving average, seeded with the simple average of the first len bars (as the site chart).4 steps/bar, 1 slot/bar
rmarma(src, len)seriesWilder moving average (alpha 1/len), seeded with the simple average.4 steps/bar, 1 slot/bar
wmawma(src, len)seriesLinearly weighted moving average (newest bar weight len).4 steps/bar, 1 slot/bar
sumsum(src, len)seriesRolling sum over len bars.4 steps/bar, 1 slot/bar
rsirsi(src, len)seriesRelative strength index, Wilder smoothing (as the site chart).6 steps/bar, 3 slots/bar
atratr(len)seriesAverage true range: true range smoothed with rma(len).6 steps/bar, 2 slots/bar
macdmacd(src, fast=12, slow=26, sig=9)[series, series, series]Returns [macd, signal, histogram]; the signal line is seeded like the site chart MACD.14 steps/bar, 5 slots/bar
bbbb(src, len=20, mult=2)[series, series, series]Bollinger bands: returns [middle, upper, lower]; population standard deviation.len+6 steps/bar, 4 slots/bar
stdevstdev(src, len)seriesPopulation standard deviation over len bars (two-pass per window).len+2 steps/bar, 2 slots/bar
highesthighest(src, len)seriesHighest value over len bars.4 steps/bar, 2 slots/bar
lowestlowest(src, len)seriesLowest value over len bars.4 steps/bar, 2 slots/bar
changechange(src, len=1)seriessrc minus src len bars ago.1 steps/bar, 1 slot/bar
refref(src, n)same shape as the inputThe value n bars ago (same as src[n]).1 steps/bar, 1 slot/bar (0 on single numbers)
crossovercrossover(a, b)series<bool>True on the bar a moves above b; na unless a, b and both previous values exist.2 steps/bar, 1 slot/bar
crossundercrossunder(a, b)series<bool>True on the bar a moves below b; na unless a, b and both previous values exist.2 steps/bar, 1 slot/bar
barssincebarssince(cond)seriesBars since cond was last strictly true; na before the first time.2 steps/bar, 1 slot/bar
nana(x)bool (series if x is)True where x has no value. Never na itself.1 steps/bar, 1 slot/bar (0 on single numbers)
nznz(x, v=0)same shape as the inputx, with na replaced by v (default 0; use nz(c, false) on a condition).1 steps/bar, 1 slot/bar (0 on single numbers)
absabs(x)same shape as the inputAbsolute value.1 steps/bar, 1 slot/bar (0 on single numbers)
roundround(x, digits=0)same shape as the inputRounded to digits decimals (half away from zero).1 steps/bar, 1 slot/bar (0 on single numbers)
maxmax(a, b)same shape as the inputThe larger of a and b (na if either is na).1 steps/bar, 1 slot/bar (0 on single numbers)
minmin(a, b)same shape as the inputThe smaller of a and b (na if either is na).1 steps/bar, 1 slot/bar (0 on single numbers)
avgavg(a, b, … up to 8)same shape as the inputAverage of 2 to 8 values (na if any is na).1 step/bar per value, 1 slot/bar (0 on single numbers)
plotplot(series, title, color=, style="line"|"dashed"|"dotted"|"histogram", width=1..4)outputDraws a line (or histogram). At most 12.1 step/bar (2 with a changing colour)
hlinehline(value, title, color=, style=)outputA horizontal level. At most 8.0
bgcolorbgcolor(cond, color)outputShades bars where cond is strictly true (alpha at most 25%). At most 2.1 step/bar
signalsignal(cond, "long"|"short", note)outputMarks the bar where cond turns strictly true after a strictly false bar. At most 8.1 step/bar
indicatorindicator(title, overlay=true)headerOptional first line: the title and whether plots sit on the price chart (overlay=true) or in a pane.0
input.intinput.int(default, title, min=, max=, step=)intA whole-number setting. Used as a length it needs min= and max= within 1..500.0
input.floatinput.float(default, title, min=, max=, step=)floatA number setting.0
input.boolinput.bool(default, title)boolAn on/off setting.0
input.sourceinput.source(close, title)seriesA choice of price series.1 step/bar
openopenseriesThe bar open.0
highhighseriesThe bar high.0
lowlowseriesThe bar low.0
closecloseseriesThe bar close.0
volumevolumeseriesThe bar volume.0
timetimeseriesBar open time (unix seconds).0
hl2hl2seriesThe bar hl2.1 step/bar once
hlc3hlc3seriesThe bar hlc3.1 step/bar once
ohlc4ohlc4seriesThe bar ohlc4.1 step/bar once
bar_indexbar_indexseriesBar number, 0 = first bar.1 step/bar once
color.greencolor.greencolor#00e5a00
color.redcolor.redcolor#ff45670
color.orangecolor.orangecolor#ff9f430
color.yellowcolor.yellowcolor#ffcc440
color.bluecolor.bluecolor#5b9fff0
color.purplecolor.purplecolor#c084ff0
color.tealcolor.tealcolor#2dd4bf0
color.graycolor.graycolor#9aa3b20
color.whitecolor.whitecolor#ffffff0
color.blackcolor.blackcolor#0000000

Limits

LimitValue
Script size20,480 bytes · 1,000 lines · 8,000 tokens · 4,000 parse nodes
Nesting32 levels · tree height 64
Statements · names · inputs · values per call300 · 64 · 16 · 8
Outputs12 plots · 8 levels · 2 shadings · 8 signals (the latest 500 marks each)
Textname 32 · number 24 · text 120 · note 80 · title 60 characters
Windows and lookbacks1..500 · 0..500
A run5,000 bars · 5,000,000 steps · 3,000,000 slots · 250 ms in your browser
Values drawn|value| up to 1e12 (beyond: left out and flagged)
Your scripts25 kept · 1.5 MB in all · up to 6 on one chart
FlowGo alerts on a signaldaily or 15-minute bar · cooldown at least 1 hour · 10 FlowScript alerts

The eight FlowSense scripts

1. EMA ribbon INDICATOR

Three EMAs on the price. The trend is cleanest when they stack in order: fast over mid over slow (up) or the reverse (down).

indicator("EMA ribbon", overlay=true)
f = input.int(8, "Fast", min=2, max=200)
m = input.int(21, "Mid", min=2, max=300)
s = input.int(50, "Slow", min=2, max=500)
plot(ema(close, f), "Fast", color=color.green)
plot(ema(close, m), "Mid", color=color.yellow)
plot(ema(close, s), "Slow", color=color.red, width=2)

Checks out · 21 steps a bar · 3 settings

2. RSI bands INDICATOR

RSI in its own pane with 70 / 30 lines; the background shades while it is stretched past either line.

indicator("RSI bands", overlay=false)
len = input.int(14, "Length", min=2, max=100)
r = rsi(close, len)
plot(r, "RSI", color=color.purple)
hline(70, "Overbought", color=color.red, style="dashed")
hline(30, "Oversold", color=color.green, style="dashed")
bgcolor(r > 70 or r < 30, color.gray)

Checks out · 17 steps a bar · 1 settings

3. BB squeeze SIGNAL

Bollinger band width within 5% of its 120-bar low on the bar before, then a close outside the band. A signal fires on the bar that breaks out.

indicator("BB squeeze", overlay=true)
[mid, up, lo] = bb(close, 20, 2)
w = (up - lo) / mid
tight = w <= lowest(w, 120) * 1.05
plot(up, "Upper", color=color.gray)
plot(lo, "Lower", color=color.gray)
signal(tight[1] and close > up, "long", "Squeeze breaks up")
signal(tight[1] and close < lo, "short", "Squeeze breaks down")

Checks out · 50 steps a bar · 0 settings

4. Chandelier stop SIGNAL

The highest high minus a multiple of ATR, as a trailing stop for a long. A signal fires on the close under the stop.

indicator("Chandelier stop", overlay=true)
n = input.int(22, "Lookback", min=5, max=200)
k = input.float(3.0, "ATR multiple", min=0.5, max=10)
stop = highest(high, n) - k * atr(n)
plot(stop, "Long stop", color=color.orange, style="dotted")
signal(crossunder(close, stop), "short", "Closed under the stop")

Checks out · 22 steps a bar · 2 settings

5. MACD turn SIGNAL

The MACD histogram coloured by its sign; a signal fires when MACD crosses up through its signal line below zero.

indicator("MACD turn", overlay=false)
[m, s, h] = macd(close, 12, 26, 9)
plot(h, "Histogram", color=h >= 0 ? color.green : color.red, style="histogram")
plot(m, "MACD", color=color.blue)
plot(s, "Signal", color=color.orange)
hline(0, "Zero", color=color.gray)
signal(crossover(m, s) and m < 0, "long", "MACD turns up below zero")

Checks out · 31 steps a bar · 0 settings

6. Volume surge SIGNAL

An up bar on at least twice the 20-bar average volume (the multiple is a setting).

indicator("Volume surge", overlay=true)
mult = input.float(2.0, "Times average", min=1.2, max=10)
surge = volume > mult * sma(volume, 20) and close > open
signal(surge, "long", "Volume surge on an up bar")

Checks out · 15 steps a bar · 1 settings

7. Donchian breakout SIGNAL

The prior high and low over the Channel setting (20 bars by default); a signal fires on a close above the channel high or below the channel low.

indicator("Donchian breakout", overlay=true)
len = input.int(20, "Channel", min=5, max=250)
hi = highest(high, len)[1]
lo = lowest(low, len)[1]
plot(hi, "Upper", color=color.teal)
plot(lo, "Lower", color=color.teal)
signal(close > hi, "long", "Close above the prior channel high")
signal(close < lo, "short", "Close below the prior channel low")

Checks out · 22 steps a bar · 1 settings

8. Trend pullback SIGNAL

Above a rising 200 EMA, the price dips to the 21 EMA and closes back above it, with no such dip in the 3 bars before.

indicator("Trend pullback", overlay=true)
src = input.source(close, "Source")
fast = ema(src, 21)
slow = ema(src, 200)
up = src > slow and slow > slow[5]
touch = low <= fast and close > fast
plot(fast, "EMA 21", color=color.yellow)
plot(slow, "EMA 200", color=color.gray, width=2)
signal(up and touch and barssince(touch[1]) > 3, "long", "Pullback to the 21 in an uptrend")

Checks out · 31 steps a bar · 1 settings

FlowScript 1.0.0 · educational — not financial advice. The bars are the market data feed’s regular-session bars. © FlowSense.

One ecosystem. Every market lens.

The economy, the company, the chart and the flow, read together and turned into a plan you can rehearse on paper. Free to start, no credit card.