Getting Started
Opening the Script Editor
Click the Script button in the chart toolbar. The editor panel opens at the bottom of the chart area with a Monaco-powered TypeScript editor.
Your First Script
Every script starts with a declaration — either indicator() or strategy():
indicator('My SMA', { overlay: true })
const len = input.int('length', 20, 'Length', { min: 2, max: 500 })
const src = input.source('source', 'close', 'Source')
const sma = ta.sma(src, len)
plot(sma, 'SMA', '#2962ff')indicator(name, opts)— declares an indicator. Setoverlay: trueto draw on the price chart,falsefor a sub-pane.strategy(name, opts)— declares a strategy with entry/exit signals and backtest stats.
Running Scripts
Press Ctrl+Enter (or click Run) to compile and execute. The script's name appears in the chart legend (next to the OHLC values) so you can adjust its settings or remove it.
Use console.log() for debug output — it prints to the browser console.
Saving Scripts
Press Ctrl+S (or click Save) to persist the current source to localStorage without running it. Scripts that were running when you last closed the page are automatically re-run on the next page load — no need to click Run again.
If a built-in template is selected when you Save, you'll be prompted to save it as a new user script.
Templates
Click the Templates dropdown in the editor toolbar to load pre-built examples:
- SMA Indicator — simple moving average overlay
- EMA Cross Strategy — entry/exit on EMA crossovers
- Bollinger Bands — upper/middle/lower bands with fill
- RSI Indicator — RSI in a sub-pane with overbought/oversold levels
Indicator vs Strategy
| Indicator | Strategy | |
|---|---|---|
| Declaration | indicator(name, opts) | strategy(name, opts) |
| Purpose | Visual overlays & sub-pane studies | Entry/exit signals + backtesting |
| Output | plot(), fill(), hline(), bgcolor() | strategy.entry(), strategy.close() |
| Backtest stats | No | Yes — win rate, PnL, drawdown, Sharpe |
Script Persistence
Scripts are saved to localStorage automatically. They persist across page refreshes. Use the editor's save/load controls to manage multiple scripts.