Variables & Constants
Core Data Variables
Variables automatically available in your script context.| Variable | Type | Description |
|---|---|---|
currentSymbol | string | Current trading symbol (e.g., “BTCUSDT”) |
currentExchange | string | Current exchange (e.g., “BINANCE”) |
currentCoin | string | Current trading coin (e.g., “BTC”) |
barIndex | number | Current bar index in the timeseries (starts at 0) |
isLastBar | boolean | True when processing the most recent bar |
isLiveUpdate | boolean | True during live data updates |
na | number | Represents a null/missing value |
Color Constants
Pre-defined color values for plotting.| Color | Hex Value |
|---|---|
red | #FF0000 |
green | #008000 |
blue | #0000FF |
yellow | #FFFF00 |
orange | #FFA500 |
purple | #800080 |
white | #FFFFFF |
black | #000000 |
gray | #808080 |
silver | #C0C0C0 |
lime | #00FF00 |
aqua | #00FFFF |
teal | #008080 |
navy | #000080 |
maroon | #800000 |
olive | #808000 |
fuchsia | #FF00FF |
Data Types
| Type | Description |
|---|---|
timeseries | Time-aligned numerical data for plotting and calculations |
var | Regular variable for dynamic values per bar |
static | Persistent variable that maintains value across bars |
ShapeType | Shape type for plotShape() (e.g., “circle”, “triangle”) |
Function Categories
Moving Averages
Moving Averages
Trend-following indicators that smooth price data.
Full documentation →
| Function | Signature | Description |
|---|---|---|
sma | sma(source, period) | Simple Moving Average |
ema | ema(source, period) | Exponential Moving Average |
wma | wma(source, period) | Weighted Moving Average |
vwma | vwma(source, volume, period) | Volume Weighted Moving Average |
dema | dema(source, period) | Double Exponential Moving Average |
tema | tema(source, period) | Triple Exponential Moving Average |
hma | hma(source, period) | Hull Moving Average |
Oscillators
Oscillators
Momentum indicators that fluctuate between bounded values.
Full documentation →
| Function | Signature | Description |
|---|---|---|
rsi | rsi(source, period) | Relative Strength Index |
stoch | stoch(high, low, close, kPeriod, dPeriod, smooth) | Stochastic Oscillator |
cci | cci(source, period) | Commodity Channel Index |
willr | willr(high, low, close, period) | Williams %R |
mfi | mfi(high, low, close, volume, period) | Money Flow Index |
roc | roc(source, period) | Rate of Change |
Trend Indicators
Trend Indicators
Indicators that help identify trend direction and strength.
Full documentation →
| Function | Signature | Description |
|---|---|---|
macd | macd(source, fastPeriod, slowPeriod, signalPeriod) | Moving Average Convergence Divergence |
adx | adx(high, low, close, period) | Average Directional Index |
psar | psar(high, low, start, increment, max) | Parabolic SAR |
supertrend | supertrend(high, low, close, period, multiplier) | Supertrend |
aroon | aroon(high, low, period) | Aroon Indicator |
Volume Indicators
Volume Indicators
Indicators that incorporate volume data in their calculations.
Full documentation →
| Function | Signature | Description |
|---|---|---|
obv | obv(close, volume) | On-Balance Volume |
vwap | vwap(high, low, close, volume) | Volume Weighted Average Price |
ad | ad(high, low, close, volume) | Accumulation/Distribution |
cmf | cmf(high, low, close, volume, period) | Chaikin Money Flow |
cvd | cvd(buyVolume, sellVolume) | Cumulative Volume Delta |
Plotting Functions
Plotting Functions
Functions for rendering data on charts.
Full documentation →
| Function | Description |
|---|---|
plotLine(value, width, colors, colorIndex, label, desc) | Plot a line chart |
plotBar(value, width, colors, colorIndex, label, desc) | Plot a bar/histogram chart |
plotCandle(open, high, low, close, colors, label, desc) | Plot candlestick chart |
plotShape(value, shape, colors, width, filled, label, desc) | Plot shapes at specific points |
Math Functions
Math Functions
Mathematical and statistical functions.
Full documentation →
| Function | Description |
|---|---|
abs(x) | Absolute value |
round(x) | Round to nearest integer |
floor(x) | Round down |
ceil(x) | Round up |
sqrt(x) | Square root |
pow(base, exp) | Power/exponent |
log(x) | Natural logarithm |
log10(x) | Base-10 logarithm |
exp(x) | Exponential (e^x) |
min(a, b) | Minimum of two values |
max(a, b) | Maximum of two values |
Utility Functions
Utility Functions
Helper functions for data manipulation.
Full documentation →
| Function | Description |
|---|---|
highest(source, period) | Highest value over period |
lowest(source, period) | Lowest value over period |
sum(source, period) | Sum over period |
change(source, period) | Change from n bars ago |
crossover(a, b) | True when a crosses above b |
crossunder(a, b) | True when a crosses below b |
isNaN(value) | Check if value is NaN |
nz(value, replacement) | Replace NaN with value |
String Functions
String Functions
Functions for string manipulation.
Full documentation →
| Function | Description |
|---|---|
concat(str1, str2) | Concatenate two strings |
toUpper(str) | Convert to uppercase |
toLower(str) | Convert to lowercase |
toString(value) | Convert value to string |
Color Functions
Color Functions
Functions for color manipulation.
Full documentation →
| Function | Description |
|---|---|
rgb(r, g, b) | Create color from RGB values |
rgba(r, g, b, a) | Create color with alpha |
colorFromHex(hex) | Create color from hex string |
Orderbook Functions
Orderbook Functions
Functions for orderbook data analysis.
Full documentation →
| Function | Description |
|---|---|
orderbook(symbol, exchange) | Subscribe to orderbook data |
orderbookImbalance(bids, asks) | Calculate bid/ask imbalance |
Data Sources
Core Data Functions
| Function | Description |
|---|---|
ohlcv(symbol, exchange) | OHLCV price data |
trades(symbol, exchange) | Trade data stream |
orderbook(symbol, exchange) | Orderbook depth data |
Market Data Sources
| Source | Description |
|---|---|
funding_rate | Funding rate from derivatives markets |
liquidations | Liquidation data from derivatives markets |
buy_sell_volume | Buy/sell volume from trade data |
open_interest | Open interest aggregation data |
Alternative Data Sources
| Source | Description |
|---|---|
etf_flow | ETF capital flow data |
etf_holding | ETF asset holdings |
etf_premium_rate | ETF premium/discount vs NAV |
cme_oi | CME futures open interest |
deribit_volatility_index | Deribit volatility index |
deribit_implied_volatility | Deribit implied volatility |
binance_treasury_balance | Binance treasury holdings |
ethena_positions | Ethena protocol positions |
Script Definition
define() Parameters
| Parameter | Type | Description |
|---|---|---|
title | string | Script title displayed in UI |
position | string | ”onchart” or “offchart” |
axis | boolean | Show dedicated price axis |
precision | number | Decimal precision for values |
input() Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Input variable name |
type | string | ”number”, “string”, “boolean” |
defaultValue | any | Default value |
label | string | Display label in UI |
options | array | Dropdown options (optional) |
Quick Examples
- Basic Indicator
- Multi-MA Comparison
- Signal Detection
A simple RSI indicator with standard settings: