QuantScript indicator example: SMA Trend + RSI Oscillator for BTCUSD. Overlays fast and slow SMA on price chart with RSI in a separate oscillator pane.
// SMA Trend + RSI Oscillator — BTCUSD 15m Indicator
//
// A simple indicator-mode script that overlays a fast and slow SMA on the
// price chart and renders an RSI oscillator in a separate pane below.
// No trading logic — purely visual / analytical.
mode("indicator");
indicator("SMA Trend + RSI");
candles("BTCUSD", timeframe: "1m", bars: 100, provider: "demotrader");
broker("mybrokeraccount1");
// ── Inputs ───────────────────────────────────────────────────────────────────
const fastLen = input.int(10, "Fast SMA", minval: 3, maxval: 50, group: "Trend");
const slowLen = input.int(30, "Slow SMA", minval: 10, maxval: 200, group: "Trend");
const rsiLen = input.int(14, "RSI Length", minval: 5, maxval: 50, group: "Oscillator");
const rsiOB = input.float(70.0, "Overbought", minval: 50.0, maxval: 95.0, step: 1.0, group: "Oscillator");
const rsiOS = input.float(30.0, "Oversold", minval: 5.0, maxval: 50.0, step: 1.0, group: "Oscillator");
// ── Computation & Plotting ───────────────────────────────────────────────────
event.onCandle((candle) => {
if (candleIndex < Math.max(slowLen, rsiLen)) return;
let close = candle.close;
let smaFast = ta.sma(close, fastLen);
let smaSlow = ta.sma(close, slowLen);
let rsiVal = ta.rsi(close, rsiLen);
// Overlay: SMA lines on the price chart
chart.plot(smaFast, "Fast SMA", "#2196F3");
chart.plot(smaSlow, "Slow SMA", "#FF9800");
// Oscillator pane: RSI with reference lines
chart.pane("oscillator");
chart.plot(rsiVal, "RSI", "#9C27B0");
chart.hline(rsiOB, "Overbought", "#f85149");
chart.hline(rsiOS, "Oversold", "#3fb950");
});