QuantScript — sma-trend-rsi-indicator.qs
// 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({ mode: "indicator" });
indicator(title: "SMA Trend + RSI");
candles({ symbol: "BTCUSD", resolution: "1m", bars: 100, adapter: "demotrader.net" });
broker({ adapter: "mybrokeraccount1" });

// ── Inputs ───────────────────────────────────────────────────────────────────
const fastLen = input.int(10, "Fast SMA", 3, 50, null, null, null, "Trend");
const slowLen = input.int(30, "Slow SMA", 10, 200, null, null, null, "Trend");
const rsiLen  = input.int(14, "RSI Length", 5, 50, null, null, null, "Oscillator");
const rsiOB   = input.float(70.0, "Overbought", 50.0, 95.0, 1.0, null, null, "Oscillator");
const rsiOS   = input.float(30.0, "Oversold", 5.0, 50.0, 1.0, null, null, "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");
});

← Back to all examples