Globals
These variables and functions are available in every script without imports.
Price Series
| Name | Type | Description |
|---|---|---|
open | Series | Open price |
high | Series | High price |
low | Series | Low price |
close | Series | Close price |
volume | Series | Volume |
Bar Info
| Name | Type | Description |
|---|---|---|
bar_index | number | Current bar index (0-based, oldest = 0) |
time | number | Current bar timestamp (Unix seconds) |
Math
The standard Math object is available:
ts
Math.abs(-5) // 5
Math.max(10, 20) // 20
Math.min(10, 20) // 10
Math.sqrt(16) // 4
Math.round(3.7) // 4
Math.floor(3.7) // 3
Math.ceil(3.2) // 4
Math.pow(2, 10) // 1024
Math.log(100) // 4.605
Math.PI // 3.14159...Number Utilities
| Function | Description |
|---|---|
isNaN(value) | Check if a value is NaN |
isFinite(value) | Check if a value is finite |
parseFloat(string) | Parse a string to float |
parseInt(string, radix?) | Parse a string to integer |
NaN | Not-a-Number constant |
Infinity | Infinity constant |
Console
ts
console.log('RSI:', rsi[0], 'Bar:', bar_index)Output goes to the browser developer console (F12).
Multi-Timeframe Data
The request namespace provides access to higher-timeframe OHLCV data:
ts
const daily = request.timeframe('D')
const dailySMA = ta.sma(daily.close, 50)See Multi-Timeframe (request) for full documentation.
Script Declaration
| Function | Description |
|---|---|
indicator(name, opts?) | Declare script as an indicator |
strategy(name, opts?) | Declare script as a strategy |
Options: { overlay?: boolean } — true draws on price chart, false in a sub-pane.