All functions
Every function, value and color in Vex, by section. Each entry has its signature, arguments, what it returns and an example.
For AI tools: this page as Markdown · the whole language in one file
170 functions
Settings
int
1int(14, "Label", min =, max =, step =)A whole-number setting with its own label and limits (at the top of the script).
In Pine Script: input.int(defval, title, minval, maxval, step)
Example
1length = int(14, "RSI length", min = 2, max = 200)2plot(rsi(close, length))float
1float(2, "Label", min =, max =, step =)A decimal setting with its own label and limits.
In Pine Script: input.float(defval, title, minval, maxval, step)
Example
1mult = float(2, "Width", min = 0.5, step = 0.25)2b = bands(close, 20, mult)3plot(b.upper)4plot(b.lower)bool
1bool(true, "Label")A checkbox setting.
In Pine Script: input.bool(defval, title)
Example
1smooth = bool(true, "Smooth it")2plot(smooth ? ema(close, 9) : close)string
1string("a" or "b", "Label")A dropdown of choices; the first is the default.
In Pine Script: input.string(defval, title, options)
Example
1average = string("ema" or "sma", "Average")2plot(average == "ema" ? ema(close, 20) : sma(close, 20))source
1source(close, "Label")A price setting (close, open, high, low, hl2, hlc3, ohlc4).
In Pine Script: input.source(defval, title)
Example
1src = source(close, "Price")2plot(ema(src, 20))color
1color(blue, "Label")A color setting.
In Pine Script: input.color(defval, title)
Example
1col = color(blue, "Line color")2plot(ema(close, 20), color = col)Drawing
name
1name("title", where = chart|pane)Names the script (the legend and menus show it). where = chooses the price chart or its own pane; without it, Vex decides.
In Pine Script: indicator(title, overlay = true)
Example
1name("EMA 21", where = chart)2plot(ema(close, 21))plot
1plot(value, "title", color = c, width = 1-4, style = line|bars|dots|steps, offset = n)Draws a value. The color may be a formula, picking one per bar. offset = n draws it n bars ahead (past the newest bar) or back (negative).
In Pine Script: plot(series, title, color, linewidth, style, offset)
Example
1plot(rsi(close, 14), "RSI", color = blue, width = 2)2plot(volume, "Volume", style = bars, color = close > open ? up : down)level
1level(a, b, ...)Grey dashed horizontal lines at fixed values (numbers or settings).
In Pine Script: hline(price)
Example
1plot(rsi(close, 14))2level(70, 50, 30)fill
1fill(a, b, color = c, opacity = 0-100, offset = n)Fills between two lines: up color where a is above b, down below, unless a color is given. The color may be a formula, one per bar (a ribbon). opacity is how solid it is (default 12); a #rrggbbaa color keeps its own.
With a color formula the fill is a ribbon: each stretch takes the color of the bar it starts from, as the lines do.
opacity sets how solid it is, 0 to 100 (default 12); it is also a setting on the Style tab. A #rrggbbaa color keeps its own transparency.
In Pine Script: fill(plot1, plot2, color)
Example
1name("Ribbon", where = chart)2 3fast = ema(close, 9)4slow = ema(close, 21)5plot(fast)6plot(slow)7fill(fast, slow, color = fast > slow ? green : red, opacity = 35)See also: Colors
mark
1mark(condition, "text {name}", where = above|below, shape = arrow|dot, color = c, at = price, offset = -n)Marks the bars where a yes/no is true. Add "and closed" to mark finished bars only. at = price puts it at a price (a label); {name} in the text shows a value; offset = -n draws it n bars back.
at = price puts the mark at that price: a label. {name} in its text shows the value on that bar, as alert messages do (up to 40 characters). offset = -n draws it n bars back, so a pivot found right bars later is labelled on its own bar.
In Pine Script: plotshape(condition, text, location, style, color); label.new(x, y, text)
Example
1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_above(fast, slow) and closed, "B", where = below)6mark(crosses_below(fast, slow) and closed, "S", where = above, shape = dot, color = orange)See also: Marks, finished bars and alerts
alert
1alert(condition, "message {name}")Alerts when a bar closes with the condition true, while a chart running the script is open (your alert settings decide sound and notifications). {name} puts a value in the message.
In Pine Script: alertcondition(condition, title, message)
Example
1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5alert(crosses_above(fast, slow), "Fast crossed above slow at {close}")See also: Marks, finished bars and alerts
bar_color
1bar_color(color)Colors the chart's candles per bar (none leaves a bar as it is).
In Pine Script: barcolor(color)
Example
1bar_color(close > ema(close, 50) ? up : down)background
1background(color)Colors behind each bar; use a see-through color (#rrggbbaa).
In Pine Script: bgcolor(color)
Example
1background(rsi(close, 14) > 70 ? #ef444420 : none)Formulas
if
1if condition then a else bPicks a value per bar. condition ? a : b is the same.
In Pine Script: condition ? a : b
Example
1plot(close > open ? high : low)2plot(if close > open then 1 else -1, "Up or down", style = steps)See also: Picking a value: if and ? :
starts
1name starts valueWhat prev(name) reads before there is an earlier bar.
In Pine Script: var x = value
Example
1n starts 02n = new_day ? 0 : prev(n) + 13plot(n, "Bars into the day", style = steps)See also: Values that carry over: starts
none
No value (an empty bar, no color).
In Pine Script: na
Example
1plot(close > open ? close : none, style = dots)See also: Empty values
and
1a and bBoth are true.
Example
1plot(close)2mark(close > open and volume > sma(volume, 20), where = below, shape = dot)or
1a or bEither is true. Between texts at the top level, a list of choices for a setting.
Example
1plot(close)2mark(new_day or crosses_above(close, ema(close, 50)), where = below, shape = dot)not
1not aThe opposite yes/no.
Example
1plot(close)2mark(not (close > open), where = above, shape = dot)Bar values
open
The bar's open.
Returns: a number per bar
Example
1plot(open)high
The bar's high.
Returns: a number per bar
Example
1plot(high)low
The bar's low.
Returns: a number per bar
Example
1plot(low)close
The bar's close (the latest price on the forming bar).
Returns: a number per bar
Example
1plot(close)volume
The bar's volume (empty where the chart has none).
Returns: a number per bar
Example
1plot(volume)time
When the bar opened, in seconds since 1970 (UTC).
Pine's time is in milliseconds; Vex's is in seconds.
Returns: a number per bar
In Pine Script: time / 1000
Example
1plot(time)bar
The bar number: 0 for the first bar loaded, then 1, 2, ...
Returns: a number per bar
In Pine Script: bar_index
Example
1plot(bar)hl2
(high + low) / 2
Returns: a number per bar
Example
1plot(hl2)hlc3
(high + low + close) / 3
Returns: a number per bar
Example
1plot(hlc3)ohlc4
(open + high + low + close) / 4
Returns: a number per bar
Example
1plot(ohlc4)tr
True range: the bar's range including any gap from the previous close.
Returns: a number per bar
In Pine Script: ta.tr
Example
1plot(tr)buy_volume
Volume bought by takers in the bar (crypto; empty where the chart has none).
Returns: a number per bar
Example
1plot(buy_volume)sell_volume
Volume sold by takers in the bar (crypto; empty where the chart has none).
Returns: a number per bar
Example
1plot(sell_volume)delta
buy_volume - sell_volume: the bar's taker delta.
Returns: a number per bar
Example
1plot(delta)cvd
Cumulative volume delta: total(delta) from the first bar loaded.
Returns: a number per bar
Example
1plot(cvd)obv
On-balance volume: running volume, added on up closes and taken off on down closes.
Returns: a number per bar
In Pine Script: ta.obv
Example
1plot(obv)vwap
Volume-weighted average price of the session (resets each UTC day), on hlc3.
Returns: a number per bar
In Pine Script: ta.vwap
Example
1plot(vwap)hour
Hour of the bar's open, 0 to 23 (UTC).
Returns: a number per bar
In Pine Script: hour(time, "UTC")
Example
1background(hour >= 13 and hour < 21 ? #3b82f615 : none)minute
Minute of the bar's open, 0 to 59.
Returns: a number per bar
In Pine Script: minute(time, "UTC")
Example
1plot(minute)weekday
Day of the week of the bar's open: 1 Monday to 7 Sunday (UTC).
Pine counts Sunday as 1; Vex counts Monday as 1 and Sunday as 7.
Returns: a number per bar
In Pine Script: dayofweek
Example
1plot(weekday)new_day
True on the first bar of each UTC day (and the first bar loaded).
Returns: a yes/no per bar
In Pine Script: ta.change(time("D")) != 0
Example
1background(new_day ? #3b82f630 : none)closed
True once the bar is final; false on the bar still forming. Use "and closed" so a mark or alert only fires on finished bars (no repainting).
Returns: a yes/no per bar
In Pine Script: barstate.isconfirmed
Example
1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_above(fast, slow) and closed, "B", where = below)See also: Marks, finished bars and alerts
BackQuant data
gex
Net dealer gamma exposure (flow-signed, all expiries), in $ per 1% move. Crypto only.
Returns: a number per bar
Example
1g = gex / 1e92plot(g, "Net GEX ($bn)", style = bars, color = g > 0 ? up : down)3level(0)oi
Open interest, all venues, in $ (BTC, ETH, SOL, HYPE).
Returns: a number per bar
Example
1plot(oi / 1e9, "OI ($bn)")funding
Funding rate across venues, in basis points per 8 hours (BTC, ETH, SOL, HYPE).
Returns: a number per bar
Example
1plot(funding, "Funding (bp / 8h)", style = bars, color = funding > 0 ? up : down)2level(0)liq_long
Long positions liquidated in the bar, in $ (BTC, ETH, SOL, HYPE).
Returns: a number per bar
Example
1plot(liq_long / 1e6, "Longs liquidated ($m)", style = bars, color = down)2plot(-liq_short / 1e6, "Shorts liquidated ($m)", style = bars, color = up)liq_short
Short positions liquidated in the bar, in $ (BTC, ETH, SOL, HYPE).
Returns: a number per bar
Example
1plot(liq_short / 1e6, "Shorts liquidated ($m)", style = bars, color = up)iv
Implied volatility: DVOL, in percent (BTC and ETH).
Returns: a number per bar
Example
1plot(iv, "IV")2plot(sma(iv, 30), "30-bar average")prem_calls
Net call premium in the bar (bought minus sold), in $ (BTC and ETH).
Returns: a number per bar
Example
1plot((prem_calls - prem_puts) / 1e6, "Net premium ($m)", style = bars, color = prem_calls > prem_puts ? up : down)prem_puts
Net put premium in the bar (bought minus sold), in $ (BTC and ETH).
Returns: a number per bar
Example
1plot(prem_puts)gamma_flip
The gamma flip (HVL): the price nearest spot where cumulative dealer gamma changes sign, from the same dealer book as gex (Flow, all expiries; empty with no crossing within 25%). Crypto only.
Each bar has the flip of the dealer book in force at its close, from the same history as the chart's gamma levels: never a level from the future. Further back the history is coarser (the server spaces snapshots to fit the window).
Returns: a number per bar
Example
1name("Gamma flip", where = chart)2 3plot(gamma_flip, "Gamma flip", color = orange, style = steps)4background(close > gamma_flip ? #22c55e0d : #ef44440d)call_wall
The call wall: the strike above the price with the largest positive dealer gamma (Flow, all expiries). Crypto only.
Returns: a number per bar
Example
1name("Call wall", where = chart)2 3plot(call_wall, "Call wall", color = green, style = steps)4mark(crosses_above(close, call_wall) and closed, "C", where = below)See also: put_wall, gamma_flip
put_wall
The put wall: the strike below the price with the largest positive dealer gamma (Flow, all expiries). Crypto only.
Returns: a number per bar
Example
1name("Put wall", where = chart)2 3plot(put_wall, "Put wall", color = red, style = steps)4mark(crosses_below(close, put_wall) and closed, "P", where = above)See also: call_wall, gamma_flip
etf_flow
Net creations into the US spot ETFs, in $ per day (BTC, ETH, SOL, XRP; daily, lined up with the bars).
Returns: a number per bar
Example
1plot(etf_flow / 1e6, "ETF flow ($m)", style = bars, color = etf_flow > 0 ? up : down)2plot(sum(etf_flow, 5) / 1e6, "5-day total ($m)", color = orange)rv
Realised volatility, in percent: what price has done, to set against iv (BTC and ETH, daily).
Returns: a number per bar
Example
1plot(iv - rv, "Vol premium (IV - RV)", style = bars, color = iv > rv ? up : down)2level(0)See also: iv
fly25
30-day 25-delta butterfly: how much the wings cost over ATM, in vol points. Crypto only.
Returns: a number per bar
Example
1plot(fly25, "25d butterfly (30d)")See also: rr25
basis
The perp aggregate over the spot aggregate, in basis points (above 0, perps trade rich). Crypto.
Returns: a number per bar
Example
1plot(basis, "Basis (bps)", style = bars, color = basis > 0 ? up : down)2level(0)cb_premium
Coinbase's USD price over Binance's USDT price, in percent (above 0, US buyers pay up). BTC, ETH, SOL.
Returns: a number per bar
Example
1plot(cb_premium, "Coinbase premium (%)", style = bars, color = cb_premium > 0 ? up : down)2level(0)put_call
Puts' open interest over calls' (above 1, more puts open). BTC and ETH, daily.
Returns: a number per bar
Example
1plot(put_call, "Put/call OI")2level(1)short_share
The share of the day's volume reported as short sales on FINRA venues, in percent. US equities, daily.
Returns: a number per bar
Example
1plot(short_share, "Short % of volume")2plot(sma(short_share, 20), "20-day average", color = orange)3level(50)gex_0dte
Net dealer gamma exposure, in $ per 1% move (flow-signed, the front expiry while it expires within a day (0DTE), else empty). Crypto only.
Returns: a number per bar
Example
1plot(gex_0dte)gex_front
Net dealer gamma exposure, in $ per 1% move (flow-signed, the front (nearest) expiry). Crypto only.
Returns: a number per bar
Example
1plot(gex_front)gex_week
Net dealer gamma exposure, in $ per 1% move (flow-signed, expiries within 7 days). Crypto only.
Returns: a number per bar
Example
1plot(gex_week)gex_month
Net dealer gamma exposure, in $ per 1% move (flow-signed, expiries within 31 days). Crypto only.
Returns: a number per bar
Example
1plot(gex_month)dex
Net dealer delta, in $ (flow-signed, all expiries). Crypto only.
Returns: a number per bar
Example
1plot(dex)dex_0dte
Net dealer delta, in $ (flow-signed, the front expiry while it expires within a day (0DTE), else empty). Crypto only.
Returns: a number per bar
Example
1plot(dex_0dte)dex_front
Net dealer delta, in $ (flow-signed, the front (nearest) expiry). Crypto only.
Returns: a number per bar
Example
1plot(dex_front)dex_week
Net dealer delta, in $ (flow-signed, expiries within 7 days). Crypto only.
Returns: a number per bar
Example
1plot(dex_week)dex_month
Net dealer delta, in $ (flow-signed, expiries within 31 days). Crypto only.
Returns: a number per bar
Example
1plot(dex_month)vanna
Net dealer vanna (VEX): how dealer delta moves when implied vol moves, in $ of delta per vol point (flow-signed, all expiries). Crypto only.
Returns: a number per bar
Example
1plot(vanna)vanna_0dte
Net dealer vanna (VEX): how dealer delta moves when implied vol moves, in $ of delta per vol point (flow-signed, the front expiry while it expires within a day (0DTE), else empty). Crypto only.
Returns: a number per bar
Example
1plot(vanna_0dte)vanna_front
Net dealer vanna (VEX): how dealer delta moves when implied vol moves, in $ of delta per vol point (flow-signed, the front (nearest) expiry). Crypto only.
Returns: a number per bar
Example
1plot(vanna_front)vanna_week
Net dealer vanna (VEX): how dealer delta moves when implied vol moves, in $ of delta per vol point (flow-signed, expiries within 7 days). Crypto only.
Returns: a number per bar
Example
1plot(vanna_week)vanna_month
Net dealer vanna (VEX): how dealer delta moves when implied vol moves, in $ of delta per vol point (flow-signed, expiries within 31 days). Crypto only.
Returns: a number per bar
Example
1plot(vanna_month)charm
Net dealer charm (CEX): how dealer delta drifts as time passes, in $ of delta per day (flow-signed, all expiries). Crypto only.
Returns: a number per bar
Example
1plot(charm)charm_0dte
Net dealer charm (CEX): how dealer delta drifts as time passes, in $ of delta per day (flow-signed, the front expiry while it expires within a day (0DTE), else empty). Crypto only.
Returns: a number per bar
Example
1plot(charm_0dte)charm_front
Net dealer charm (CEX): how dealer delta drifts as time passes, in $ of delta per day (flow-signed, the front (nearest) expiry). Crypto only.
Returns: a number per bar
Example
1plot(charm_front)charm_week
Net dealer charm (CEX): how dealer delta drifts as time passes, in $ of delta per day (flow-signed, expiries within 7 days). Crypto only.
Returns: a number per bar
Example
1plot(charm_week)charm_month
Net dealer charm (CEX): how dealer delta drifts as time passes, in $ of delta per day (flow-signed, expiries within 31 days). Crypto only.
Returns: a number per bar
Example
1plot(charm_month)vega
Net dealer vega, in $ per vol point (flow-signed, all expiries). Crypto only.
Returns: a number per bar
Example
1plot(vega)vega_0dte
Net dealer vega, in $ per vol point (flow-signed, the front expiry while it expires within a day (0DTE), else empty). Crypto only.
Returns: a number per bar
Example
1plot(vega_0dte)vega_front
Net dealer vega, in $ per vol point (flow-signed, the front (nearest) expiry). Crypto only.
Returns: a number per bar
Example
1plot(vega_front)vega_week
Net dealer vega, in $ per vol point (flow-signed, expiries within 7 days). Crypto only.
Returns: a number per bar
Example
1plot(vega_week)vega_month
Net dealer vega, in $ per vol point (flow-signed, expiries within 31 days). Crypto only.
Returns: a number per bar
Example
1plot(vega_month)Averages
rma
1rma(x, n)Wilder's moving average (the one RSI and ATR use).
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.rma(source, length)
Example
1gain = max(close - prev(close), 0)2plot(rma(gain, 14), "Average gain")wma
1wma(x, n)Weighted moving average: the newest bar weighs n, the oldest 1.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.wma(source, length)
Example
1plot(wma(close, 9))dema
1dema(x, n)Double EMA: 2 x ema(x, n) - ema(ema(x, n), n), quicker to turn than an EMA.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.dema(source, length) (ta library)
Example
1plot(dema(close, 20))tema
1tema(x, n)Triple EMA: 3 x e1 - 3 x e2 + e3 for an EMA taken one, two and three times.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.tema(source, length) (ta library)
Example
1plot(tema(close, 20))t3
1t3(x, n, vf = 0.7)Tillson T3: six EMAs blended by the volume factor vf (0.7 as usual), smooth with little lag.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a settingvf: a number fixed when the script runs: a number or a setting; 0.7 when left out
Returns: a number per bar
In Pine Script: ta.t3(source, length, volumeFactor) (ta library)
Example
1plot(t3(close, 5, 0.7), "T3")2plot(ema(close, 5), "EMA", color = grey)alma
1alma(x, n, offset = 0.85, sigma = 6)Arnaud Legoux moving average: Gaussian weights centred offset of the way from the oldest bar (0.85 leans to the newest), as wide as n / sigma.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a settingoffset: a number fixed when the script runs: a number or a setting; 0.85 when left outsigma: a number fixed when the script runs: a number or a setting; 6 when left out
Returns: a number per bar
In Pine Script: ta.alma(source, length, offset, sigma)
Example
1plot(alma(close, 9, 0.85, 6))hma
1hma(x, n)Hull moving average: smooth and quick to turn.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.hma(source, length)
Example
1name("Hull", where = chart)2 3f = hma(close, 55)4s = prev(f, 2)5plot(f, "Hull", color = f > s ? #00ff00 : #ff0000)6plot(s, "Hull 2", color = f > s ? #00ff00 : #ff0000)7fill(f, s, color = f > s ? #00ff00 : #ff0000, opacity = 40)vwma
1vwma(x, n)Volume-weighted moving average.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.vwma(source, length)
Example
1plot(vwma(close, 20))Windows
stdev
1stdev(x, n)Standard deviation of x over the last n bars (population).
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.stdev(source, length)
Example
1plot(stdev(close, 20))change
1change(x, n = 1)How much x moved over n bars: x - prev(x, n).
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting; 1 when left out
Returns: a number per bar
In Pine Script: ta.change(source, length)
Example
1plot(change(close))roc
1roc(x, n)Rate of change: percent move of x over n bars.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.roc(source, length)
Example
1plot(roc(close, 10))total
1total(x)Running total of x from the first bar (empty values add nothing).
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: ta.cum(source)
Example
1plot(total(volume))median
1median(x, n)The middle value of x over the last n bars.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.median(source, length)
Example
1plot(median(close, 20))dev
1dev(x, n)Mean absolute deviation of x from its n-bar average.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.dev(source, length)
Example
1plot(dev(close, 20))percentrank
1percentrank(x, n)Percent of the previous n values of x at or below this one (0 to 100).
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.percentrank(source, length)
Example
1plot(percentrank(volume, 100))linreg
1linreg(x, n)Linear regression: the least-squares line through the last n values of x, at this bar.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.linreg(source, length, 0)
Example
1plot(linreg(close, 50))correlation
1correlation(a, b, n)Correlation of a and b over the last n bars (-1 to 1).
Arguments
a: a number per barb: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.correlation(source1, source2, length)
Example
1plot(correlation(close, volume, 50))loop_score
1loop_score(x, from, to)The for-loop score: for each bar back from from to to, +1 if x is above it now, -1 if not (or if either is empty).
For each bar back from from to to: +1 when x is above that bar's value now, -1 when it isn't (or either is empty). It is the for-loop many Pine trend scores use, done without a loop.
Arguments
x: a number per barfrom: a whole number, 0 to 5000, fixed: a number or a settingto: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: for i = from to to: score += x > x[i] ? 1 : -1
Example
1plot(loop_score(rsi(close, 14), 1, 45))See also: Your own functions
prev
1prev(x, n = 1)x as it was n bars ago (empty before the first bar, unless x has a starts line).
Arguments
x: a number per barn: a whole number, 0 to 5000, fixed: a number or a setting; 1 when left out
Returns: a number per bar
In Pine Script: source[n]
Example
1plot(close - prev(close), "Change")2plot(close - prev(close, 10), "10-bar change")See also: Looking back: prev, Values that carry over: starts
Indicators
rsi
1rsi(x, n)Wilder's relative strength index, 0 to 100.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.rsi(source, length)
Example
1r = rsi(close, 14)2plot(r, "RSI")3level(70, 30)cci
1cci(n)Commodity channel index on hlc3.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.cci(hlc3, length)
Example
1plot(cci(20))mfi
1mfi(n)Money flow index on hlc3 and volume, 0 to 100.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: ta.mfi(hlc3, length)
Example
1plot(mfi(14))bands
1bands(x, n, mult = 2)Bollinger bands: the SMA, and mult standard deviations above and below.
Pine's ta.bb gives [middle, upper, lower]; here they are .mid, .upper and .lower.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a settingmult: a number per bar; 2 when left out
Returns: several parts: .upper .mid .lower
In Pine Script: ta.bb(source, length, mult)
Example
1name("Bollinger", where = chart)2 3b = bands(close, 20, 2)4plot(b.upper, "Upper")5plot(b.mid, "Middle")6plot(b.lower, "Lower")7fill(b.upper, b.lower)macd
1macd(x, fast = 12, slow = 26, signal = 9)MACD: fast EMA minus slow EMA, its EMA signal, and the gap between them.
Arguments
x: a number per barfast: a whole number of bars, 1 to 5000, fixed: a number or a setting; 12 when left outslow: a whole number of bars, 1 to 5000, fixed: a number or a setting; 26 when left outsignal: a whole number of bars, 1 to 5000, fixed: a number or a setting; 9 when left out
Returns: several parts: .line .signal .hist
In Pine Script: ta.macd(source, fast, slow, signal)
Example
1m = macd(close, 12, 26, 9)2plot(m.hist, "Histogram", style = bars, color = m.hist > 0 ? up : down)3plot(m.line, "MACD", color = blue)4plot(m.signal, "Signal", color = orange)5level(0)stoch
1stoch(n = 14, ksmooth = 1, dsmooth = 3)Stochastic: where the close sits in the n-bar range (0 to 100), smoothed, and its average.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left outksmooth: a whole number of bars, 1 to 5000, fixed: a number or a setting; 1 when left outdsmooth: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left out
Returns: several parts: .k .d
In Pine Script: ta.sma(ta.stoch(close, high, low, n), ksmooth)
Example
1s = stoch(14, 1, 3)2plot(s.k, "%K")3plot(s.d, "%D")4level(80, 20)donchian
1donchian(n = 20)Donchian channel: the highest high and lowest low of the last n bars, and their middle.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 20 when left out
Returns: several parts: .upper .mid .lower
Example
1d = donchian(20)2plot(d.upper, "upper")3plot(d.mid, "mid")4plot(d.lower, "lower")pivot_high
1pivot_high(x, left = 5, right = 5)A pivot high: x of the bar right bars back when it is higher than the left bars before it and the right bars after it; empty elsewhere. It is given on the bar that confirms it (right bars later); plot it with offset = -right to draw it on the pivot bar.
Like Pine's, the value comes on the bar that confirms the pivot, right bars after it, so it never repaints. offset = -right draws it on the pivot bar itself.
Arguments
x: a number per barleft: a whole number of bars, 1 to 5000, fixed: a number or a setting; 5 when left outright: a whole number of bars, 1 to 5000, fixed: a number or a setting; 5 when left out
Returns: a number per bar
In Pine Script: ta.pivothigh(source, leftbars, rightbars)
Example
1name("Pivots", where = chart)2 3ph = pivot_high(high, 5, 5)4pl = pivot_low(low, 5, 5)5plot(ph, "Pivot high", style = dots, width = 3, color = red, offset = -5)6plot(pl, "Pivot low", style = dots, width = 3, color = green, offset = -5)pivot_low
1pivot_low(x, left = 5, right = 5)A pivot low: x of the bar right bars back when it is lower than the left bars before it and the right bars after it; empty elsewhere. Given on the bar that confirms it.
Arguments
x: a number per barleft: a whole number of bars, 1 to 5000, fixed: a number or a setting; 5 when left outright: a whole number of bars, 1 to 5000, fixed: a number or a setting; 5 when left out
Returns: a number per bar
In Pine Script: ta.pivotlow(source, leftbars, rightbars)
Example
1name("Pivot lows", where = chart)2 3pl = pivot_low(low, 5, 5)4plot(pl, "Pivot low", style = dots, width = 3, color = green, offset = -5)5plot(when(not empty(pl), pl), "Last pivot low", style = steps, color = grey)See also: pivot_high, when
ichimoku
1ichimoku(conversion = 9, base = 26, span_b = 52)Ichimoku: the conversion and base lines (the middle of the n-bar high-low range) and the leading spans as worked out on each bar. Draw the spans 25 bars ahead with offset = 25, and the lagging line as plot(close, offset = -25).
The spans are worked out on each bar and drawn 25 bars ahead with offset = 25 (a displacement of 26 less one); the lagging line is the close drawn 25 bars back.
Arguments
conversion: a whole number of bars, 1 to 5000, fixed: a number or a setting; 9 when left outbase: a whole number of bars, 1 to 5000, fixed: a number or a setting; 26 when left outspan_b: a whole number of bars, 1 to 5000, fixed: a number or a setting; 52 when left out
Returns: several parts: .conversion .base .span_a .span_b
Example
1name("Ichimoku", where = chart)2 3ich = ichimoku(9, 26, 52)4plot(ich.conversion, "Conversion", color = blue)5plot(ich.base, "Base", color = maroon)6plot(ich.span_a, "Span A", color = green, offset = 25)7plot(ich.span_b, "Span B", color = red, offset = 25)8fill(ich.span_a, ich.span_b, opacity = 15)9plot(close, "Lagging", color = teal, offset = -25)keltner
1keltner(x, n = 20, atr_n = 10, mult = 2)Keltner channel: an EMA, and mult ATRs above and below it.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting; 20 when left outatr_n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 10 when left outmult: a number per bar; 2 when left out
Returns: several parts: .upper .mid .lower
Example
1k = keltner(close, 20, 10, 2)2plot(k.upper, "upper")3plot(k.mid, "mid")4plot(k.lower, "lower")williams_r
1williams_r(n = 14)Williams %R: where the close sits in the n-bar range, -100 at the low to 0 at the high.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left out
Returns: a number per bar
In Pine Script: ta.wpr(length)
Example
1plot(williams_r(14))stochrsi
1stochrsi(x, rsi_n = 14, stoch_n = 14, ksmooth = 3, dsmooth = 3)Stochastic RSI: the stochastic of the RSI, smoothed, and its average.
Arguments
x: a number per barrsi_n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left outstoch_n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left outksmooth: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left outdsmooth: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left out
Returns: several parts: .k .d
Example
1s = stochrsi(close, 14, 14, 3, 3)2plot(s.k, "k")3plot(s.d, "d")cmf
1cmf(n = 20)Chaikin money flow: where closes sit in their bars, weighted by volume, over n bars (-1 to 1).
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 20 when left out
Returns: a number per bar
Example
1plot(cmf(20))dmi
1dmi(n = 14, smooth = 14)Directional movement: +DI, -DI and the ADX trend strength.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left outsmooth: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left out
Returns: several parts: .plus .minus .adx
In Pine Script: ta.dmi(diLength, adxSmoothing)
Example
1m = dmi(14, 14)2plot(m.plus, "+DI", color = green)3plot(m.minus, "-DI", color = red)4plot(m.adx, "ADX", color = blue)supertrend
1supertrend(n = 10, factor = 3)Supertrend on hl2: a trailing line under the price in an up trend (dir 1), over it in a down trend (dir -1).
Pine's arguments are the other way round (factor first), and its direction is -1 in an up trend; here .dir is 1 up and -1 down.
Arguments
n: a whole number of bars, 1 to 5000, fixed: a number or a setting; 10 when left outfactor: a number fixed when the script runs: a number or a setting; 3 when left out
Returns: several parts: .line .dir
In Pine Script: ta.supertrend(factor, atrPeriod)
Example
1name("Supertrend", where = chart)2 3st = supertrend(10, 3)4plot(st.line, "Supertrend", color = st.dir > 0 ? up : down)psar
1psar(start = 0.02, inc = 0.02, max = 0.2)Parabolic SAR: a stop that accelerates with the trend; dir 1 when it sits under the price.
Arguments
start: a number fixed when the script runs: a number or a setting; 0.02 when left outinc: a number fixed when the script runs: a number or a setting; 0.02 when left outmax: a number fixed when the script runs: a number or a setting; 0.2 when left out
Returns: several parts: .value .dir
In Pine Script: ta.sar(start, inc, max)
Example
1name("SAR", where = chart)2 3sar = psar(0.02, 0.02, 0.2)4plot(sar.value, "SAR", style = dots, color = sar.dir > 0 ? up : down)Events
crosses_above
1crosses_above(a, b)True on the bar a goes from at or below b to above it.
Arguments
a: a number per barb: a number per bar
Returns: a yes/no per bar
In Pine Script: ta.crossover(a, b)
Example
1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_above(fast, slow), "B", where = below)See also: crosses_below, Marks, finished bars and alerts
crosses_below
1crosses_below(a, b)True on the bar a goes from at or above b to below it.
Arguments
a: a number per barb: a number per bar
Returns: a yes/no per bar
In Pine Script: ta.crossunder(a, b)
Example
1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_below(fast, slow), "S", where = above)See also: crosses_above, Marks, finished bars and alerts
rising
1rising(x, n)True when x is above every value of the last n bars before it.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a yes/no per bar
In Pine Script: ta.rising(source, length)
Example
1plot(close)2mark(rising(close, 3), where = below, shape = dot)falling
1falling(x, n)True when x is below every value of the last n bars before it.
Arguments
x: a number per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a yes/no per bar
In Pine Script: ta.falling(source, length)
Example
1plot(close)2mark(falling(close, 3), where = above, shape = dot)count
1count(cond, n)How many of the last n bars cond was true on.
Arguments
cond: a yes/no per barn: a whole number of bars, 1 to 5000, fixed: a number or a setting
Returns: a number per bar
In Pine Script: math.sum(cond ? 1 : 0, length)
Example
1plot(count(close > open, 10), "Up bars of the last 10")bars_since
1bars_since(cond)Bars since cond was last true (0 on a bar where it is true; empty before it ever was).
Arguments
cond: a yes/no per bar
Returns: a number per bar
In Pine Script: ta.barssince(condition)
Example
1plot(bars_since(crosses_above(close, ema(close, 20))), "Bars since the cross")when
1when(cond, x, k = 0)x on the most recent bar where cond was true (k = 1 for the one before that, ...).
Arguments
cond: a yes/no per barx: a number per bark: a whole number, 0 to 5000, fixed: a number or a setting; 0 when left out
Returns: a number per bar
In Pine Script: ta.valuewhen(condition, source, occurrence)
Example
1name("Last cross price", where = chart)2 3plot(when(crosses_above(close, ema(close, 20)), close), "Price at the last cross", style = steps)Other bars
timeframe
1timeframe("4h", x)x worked out on another timeframe of this chart's market (1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, 1D, 1W). Each bar reads the value of the last bar of that timeframe that had closed by its own close, so history never repaints; the newest bar follows the one still forming.
Returns: a number per bar
In Pine Script: request.security(syminfo.tickerid, "240", x)
Example
1name("4h EMA", where = chart)2 3plot(ema(close, 20), "EMA 20")4plot(timeframe("4h", ema(close, 20)), "EMA 20 on 4h", color = orange, style = steps)See also: Other timeframes and markets, symbol
symbol
1symbol("ETHUSDT", x, timeframe = "4h")x worked out on another market's bars (its own timeframe with timeframe =), lined up with this chart's bars the same way: no lookahead. Another market is drawn in its own pane.
Returns: a number per bar
In Pine Script: request.security("ETHUSDT", timeframe.period, x)
Example
1name("BTC in ETH")2 3eth = symbol("ETHUSDT", close)4plot(close / eth, "BTC / ETH")See also: Other timeframes and markets, timeframe
Maths
max
1max(a, b, ...)The largest of the values (empty values are skipped).
Arguments
a: a number per barb: a number per bar
Returns: a number per bar
In Pine Script: math.max(a, b)
Example
1plot(max(close - open, 0))min
1min(a, b, ...)The smallest of the values (empty values are skipped).
Arguments
a: a number per barb: a number per bar
Returns: a number per bar
In Pine Script: math.min(a, b)
Example
1plot(min(open, close))abs
1abs(x)x without its sign.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.abs(x)
Example
1plot(abs(close - open))sqrt
1sqrt(x)Square root (empty below 0).
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.sqrt(x)
Example
1plot(stdev(close, 20) * sqrt(365), "Scaled deviation")log
1log(x)Natural logarithm (empty at 0 and below).
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.log(x)
Example
1plot(log(close))exp
1exp(x)e to the power x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.exp(x)
Example
1plot(exp(roc(close, 1) / 100))round
1round(x)Nearest whole number.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.round(x)
Example
1plot(round(rsi(close, 14)), "RSI, whole")floor
1floor(x)Whole number at or below x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.floor(x)
Example
1plot(floor(close / 100) * 100, "Round hundred below", style = steps)ceil
1ceil(x)Whole number at or above x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.ceil(x)
Example
1plot(ceil(close / 100) * 100, "Round hundred above", style = steps)sign
1sign(x)1 if x is above 0, -1 below, 0 at 0.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.sign(x)
Example
1plot(sign(change(close)))pow
1pow(x, p)x to the power p.
Arguments
x: a number per barp: a number per bar
Returns: a number per bar
In Pine Script: math.pow(x, p)
Example
1plot(pow(change(close), 2), "Squared change")clamp
1clamp(x, lo, hi)x kept between lo and hi.
Arguments
x: a number per barlo: a number per barhi: a number per bar
Returns: a number per bar
Example
1plot(clamp(rsi(close, 14), 30, 70), "RSI held to 30-70")fallback
1fallback(x, y)x, or y where x is empty.
Arguments
x: a number per bary: a number per bar
Returns: a number per bar
In Pine Script: nz(x, y)
Example
1plot(fallback(prev(close), close), "Previous close")See also: Empty values, empty
empty
1empty(x)True where x has no value (not enough history yet, or a division by zero).
Arguments
x: a number per bar
Returns: a yes/no per bar
In Pine Script: na(x)
Example
1r = rsi(close, 14)2plot(empty(r) ? 50 : r, "RSI, 50 until ready")See also: Empty values, fallback
Colors
green
green (#22c55e)
Returns: a color
Example
1plot(close, color = green, width = 2)red
red (#ef4444)
Returns: a color
Example
1plot(close, color = red, width = 2)blue
blue (#3b82f6)
Returns: a color
Example
1plot(close, color = blue, width = 2)orange
orange (#f97316)
Returns: a color
Example
1plot(close, color = orange, width = 2)purple
purple (#a855f7)
Returns: a color
Example
1plot(close, color = purple, width = 2)yellow
yellow (#eab308)
Returns: a color
Example
1plot(close, color = yellow, width = 2)teal
teal (#14b8a6)
Returns: a color
Example
1plot(close, color = teal, width = 2)pink
pink (#ec4899)
Returns: a color
Example
1plot(close, color = pink, width = 2)grey
grey (#9ca3af)
Returns: a color
Example
1plot(close, color = grey, width = 2)white
white (#e5e7eb)
Returns: a color
Example
1plot(close, color = white, width = 2)aqua
aqua (#06b6d4)
Returns: a color
Example
1plot(close, color = aqua, width = 2)lime
lime (#84cc16)
Returns: a color
Example
1plot(close, color = lime, width = 2)fuchsia
fuchsia (#d946ef)
Returns: a color
Example
1plot(close, color = fuchsia, width = 2)maroon
maroon (#991b1b)
Returns: a color
Example
1plot(close, color = maroon, width = 2)navy
navy (#1e3a8a)
Returns: a color
Example
1plot(close, color = navy, width = 2)olive
olive (#808000)
Returns: a color
Example
1plot(close, color = olive, width = 2)silver
silver (#cbd5e1)
Returns: a color
Example
1plot(close, color = silver, width = 2)black
black (#0a0a0a)
Returns: a color
Example
1plot(close, color = black, width = 2)up
Your candle color for up bars.
Returns: a color
Example
1plot(close, color = up, width = 2)down
Your candle color for down bars.
Returns: a color
Example
1plot(close, color = down, width = 2)

