Write
Multiple timeframes
Read another timeframe with request.security. Which timeframes the feed serves directly, which are built from others, and what is refused.
request.security evaluates an expression on another timeframe and brings the result back to your chart. The classic use is a higher-timeframe trend filter on a lower-timeframe chart.
//@version=6indicator("1h trend on any chart", overlay = true)tf = input.timeframe("60", "Trend timeframe")htfEma = request.security(syminfo.tickerid, tf, ta.ema(close, 50))plot(htfEma, "HTF EMA 50", color = color.orange, linewidth = 2)bgcolor(close > htfEma ? color.new(color.teal, 92) : color.new(color.red, 92))This example has no Run button: other timeframes are fetched from the live feed, which the docs' generated series cannot provide. Open the terminal to try it.
Timeframes the feed serves#
These fourteen come straight from the feed, with the string Pine uses for each:
| Timeframe | Pine string | Timeframe | Pine string |
|---|---|---|---|
| 5 seconds | "5S" | 5 minutes | "5" |
| 10 seconds | "10S" | 10 minutes | "10" |
| 15 seconds | "15S" | 15 minutes | "15" |
| 30 seconds | "30S" | 30 minutes | "30" |
| 1 minute | "1" | 1 hour | "60" (or "1H") |
| 2 minutes | "2" | 4 hours | "240" (or "4H") |
| 3 minutes | "3" | 1 day | "D" (or "1D") |
Other timeframes#
- Higher timeframes that are not in the list (for example
"W","45"or"120") are built by combining smaller bars, the same way PineTS does for any provider. They work, with one limit: a weekly bar needs many daily bars, and history is finite, so the earliest values can bena. The editor says when this happens. - Anything under 5 seconds is refused with a clear error. The feed has nothing smaller.
Lower timeframes#
request.security_lower_tf returns an array of the lower-timeframe values inside each chart bar, for example the 1-minute closes inside a 1-hour bar.
Rules that keep results honest#
request.securityuses the chart's own symbol throughsyminfo.tickerid. Asking for a modified ticker (Heikin Ashi, Renko and similar) fails explicitly instead of quietly serving ordinary candles.- Data a candle feed does not carry (
request.financial,request.earnings,request.dividends,request.economic,request.footprint, and similar) returnsnawith a warning in the console. - Fetches for other timeframes respect the chart's date range and are limited per run, so a script cannot pull unlimited history.