Other timeframes & symbols

Other timeframes & symbols

security() pulls a Series from a higher timeframe or a different symbol and lines it up with the chart. The expression you pass runs against the other series’ own open/high/low/close/volume.

security.ts
// security() = Pine's request.security: a value from another timeframe or
// symbol, aligned to this chart's bars. Chart bars take the last COMPLETED
// higher-timeframe bar, so it never repaints.
const htf = security(null, '4h', (h) => ta.ema(h.close, 200));  // 4H EMA 200 on a lower-timeframe chart
plot(htf, { title: '4H EMA 200', width: 2 });

// { smooth: true } glides between completed values instead of stepping;
// { live: true } shows the developing bar on the live candle (Pine's default, repaints).
const smoothHtf = security(null, '4h', (h) => ta.ema(h.close, 200), { smooth: true });
plot(smoothHtf, { title: '4H EMA 200 (smooth)', color: '#ff9800' });

// Another symbol: pass its name. The data is only fetched once you use the
// result, e.g. plot(eth) in a subpane script.
const eth = security('ETHUSDT', '1D', 'close');