Skip to main content

The Security Function & Multi-Timeframe Data

request.security() deep dive, security tuples, higher-timeframe EMA, HTF high/low indicators, and time settings guide.

From Thrive on YouTube

Watch the matching Thrive video

Watch the series
Multi-Timeframe Analysis for Crypto Futures

Multi-Timeframe Analysis for Crypto Futures

Part of Start Here: Crypto Futures Basics. Education only. Not financial advice.

request.security() Deep Dive

request.security() is PineScript's gateway to multi-timeframe (MTF) analysis. It lets you fetch data from any symbol and any timeframe, regardless of your current chart. You can pull the daily EMA while viewing a 5-minute chart of BTCUSDT, or grab the weekly RSI of ETHUSDT while charting SOL. Mastering this function is the single biggest unlock for building professional-grade indicators.

The function signature is request.security(symbol, timeframe, expression, gaps, lookahead). Every parameter matters. Getting even one wrong can produce repainting data, gaps in your plots, or values that appear correct on historical bars but diverge wildly in real time.

symbolThe ticker to fetch. Use syminfo.tickerid for the current chart's symbol, or a string like "BINANCE:BTCUSDT" for a specific exchange pair.
timeframeThe timeframe string: "1" (1m), "5" (5m), "15" (15m), "60" (1H), "240" (4H), "D" (daily), "W" (weekly), "M" (monthly). Empty string "" means the chart's current timeframe.
expressionAny PineScript expression: a built-in variable like close, a function call like ta.ema(close, 21), or a tuple of multiple values.
gapsbarmerge.gaps_off (default) fills gaps with the last value. barmerge.gaps_on leaves na between higher-timeframe updates.
lookaheadbarmerge.lookahead_off (default) uses the current HTF bar. barmerge.lookahead_on peeks ahead: combine with [1] to avoid repainting.
pine-request.security(): all parameter combinations
1//@version=5
2indicator("Security Deep Dive", overlay=true)
3
4// Basic: get daily close on any intraday chart
5dailyClose = request.security(syminfo.tickerid, "D", close)
6
7// Non-repainting: use previous completed bar with lookahead
8dailyCloseConfirmed = request.security(syminfo.tickerid, "D",
9 close[1], lookahead=barmerge.lookahead_on)
10
11// With gaps: only show values when HTF bar updates
12dailyCloseGaps = request.security(syminfo.tickerid, "D",
13 close, gaps=barmerge.gaps_on)
14
15// Cross-symbol: fetch ETH price while on BTC chart
16ethPrice = request.security("BINANCE:ETHUSDT", "D",
17 close[1], lookahead=barmerge.lookahead_on)
18
19plot(dailyCloseConfirmed, "Daily Close", color.orange, 2, plot.style_stepline)
20plot(ethPrice, "ETH Daily", color.blue, 1, display=display.status_line)

Security Tuples: Fetching Multiple Values in One Call

PineScript limits you to 40 request.security() calls per script. If you need the daily open, high, low, close, and volume, that would use 5 calls. Tuples solve this: you can return multiple values from a single call by wrapping them in square brackets. This is essential for building data-rich multi-timeframe dashboards without hitting limits.

pine-Security tuples: 5 values in 1 call
1//@version=5
2indicator("Security Tuples", overlay=true)
3
4// Fetch 5 daily values in ONE request.security() call
5[dOpen, dHigh, dLow, dClose, dVol] = request.security(
6 syminfo.tickerid, "D",
7 [open[1], high[1], low[1], close[1], volume[1]],
8 lookahead=barmerge.lookahead_on)
9
10// Fetch daily EMA + RSI in one call
11[dEma21, dRsi] = request.security(
12 syminfo.tickerid, "D",
13 [ta.ema(close, 21)[1], ta.rsi(close, 14)[1]],
14 lookahead=barmerge.lookahead_on)
15
16// Draw yesterday's high/low range
17plot(dHigh, "Prev Day High", color.new(color.red, 30), 1, plot.style_stepline)
18plot(dLow, "Prev Day Low", color.new(color.green, 30), 1, plot.style_stepline)
19bgcolor(close > dEma21 ? color.new(color.green, 93) : color.new(color.red, 93))

Tuple limit

Each tuple can return up to 9 values. If you need more than 9 values from a single timeframe, split them across two request.security() calls. This still uses only 2 of your 40 allowed calls instead of 10+.

Higher-Timeframe EMA Indicator

One of the most requested indicators in crypto trading: plotting a higher-timeframe EMA on your execution chart. If you trade on the 15-minute chart, you still need to see the daily 21 EMA: the level that institutional traders and algorithms respect on BTCUSDT. This indicator draws it correctly without repainting.

pine-Non-repainting HTF EMA overlay
1//@version=5
2indicator("HTF EMA Overlay", overlay=true)
3
4htf = input.timeframe("D", "Higher Timeframe")
5emaLen = input.int(21, "EMA Length", minval=1)
6src = input.source(close, "Source")
7
8// Non-repainting: confirmed HTF EMA
9htfEma = request.security(syminfo.tickerid, htf,
10 ta.ema(src, emaLen)[1],
11 lookahead=barmerge.lookahead_on)
12
13// Trend detection
14aboveEma = close > htfEma
15trendCol = aboveEma ? color.new(color.green, 0) : color.new(color.red, 0)
16
17plot(htfEma, "HTF EMA", trendCol, 3, plot.style_stepline)
18bgcolor(aboveEma ? color.new(color.green, 94) : color.new(color.red, 94))

HTF High/Low Indicator: Daily Levels on Intraday Charts

Drawing the previous day's high and low on an intraday chart is foundational for session trading. These levels act as natural support and resistance because they represent the extremes where buyers and sellers previously exhausted themselves. On BTC and ETH, the previous daily high/low are among the most-watched levels by active traders.

pine-Previous daily high/low with midline
1//@version=5
2indicator("Daily H/L on Intraday", overlay=true)
3
4htf = input.timeframe("D", "Reference Timeframe")
5
6[prevHigh, prevLow, prevClose] = request.security(
7 syminfo.tickerid, htf,
8 [high[1], low[1], close[1]],
9 lookahead=barmerge.lookahead_on)
10
11midpoint = (prevHigh + prevLow) / 2.0
12
13plot(prevHigh, "Prev High", color.new(color.red, 20), 2, plot.style_stepline)
14plot(prevLow, "Prev Low", color.new(color.green, 20), 2, plot.style_stepline)
15plot(midpoint, "Midpoint", color.new(color.gray, 40), 1, plot.style_stepline)
16
17// Color fill between high and low
18h = plot(prevHigh, display=display.none)
19l = plot(prevLow, display=display.none)
20fill(h, l, color.new(color.gray, 95), title="Range Fill")

Timeframe Strings and Timezone Settings

Timeframe strings in PineScript follow a specific format. Getting these wrong is a common source of errors, especially for minute-based timeframes. The timezone parameter in request.security() controls when daily bars reset: critical for crypto, which trades 24/7 and has no natural "session close."

"1", "3", "5", "15", "30", "45"Minute-based timeframes. Just the number as a string: no suffix needed.
"60", "120", "240", "480", "720"Hourly timeframes expressed in minutes. "60" = 1H, "240" = 4H, "720" = 12H.
"D", "W", "M"Daily, Weekly, Monthly. Capital letters, no numbers needed for single-unit timeframes.
"2D", "3W", "2M"Multi-day/week/month: "2D" = 2-day bars, "3W" = 3-week bars. Useful for swing analysis.
timeframe.periodReturns the current chart's timeframe string. Use to compare or prevent running on wrong TFs.
"America/New_York"TradingView uses exchange timezone by default. Override with specific timezone for session calculations.

Higher vs Lower Timeframe Requests

Requesting higher timeframes (e.g., daily data on a 15m chart) is straightforward. Each higher-timeframe bar maps to many lower-timeframe bars. The value simply stays constant until the next HTF bar completes. Requesting lower timeframes (e.g., 1m data on a daily chart) is fundamentally different and has major caveats.

1

Higher timeframe → safe and common

When you fetch "D" on a 15m chart, PineScript takes the last completed daily value and holds it constant across all 15m bars within that day. There is one daily close per 96 intraday bars (for 15m). This is the bread and butter of MTF analysis.
2

Lower timeframe → use with caution

When you fetch "1" (1-minute) on a daily chart, PineScript only sees the last 1-minute bar within each daily bar. You do not get access to all 1,440 one-minute bars, only the final one. This makes lower-timeframe requests misleading for most use cases. If you need granular data, chart the lower timeframe directly.
3

Same timeframe → valid but redundant

Requesting your own chart's timeframe returns the same data you already have. The only reason to do this is to fetch a different symbol at the same timeframe: for example, pulling ETH data while charting BTC.

Lower timeframe intrabars

PineScript v5 introduced request.security_lower_tf() for accessing intrabar data as an array. However, this function has strict limitations: maximum 100,000 intrabars across all calls, and it returns arrays that require special handling. For most crypto trading use cases, sticking to higher-timeframe requests is more reliable and performant.

Complete Build: 5-Timeframe Confluence Dashboard

This is the flagship indicator of multi-timeframe analysis: a dashboard that shows trend alignment across five timeframes simultaneously. When all five align bullish on BTCUSDT, you have maximum confluence: the highest-probability setup for trend-following entries. The table updates in real time and uses only 5 of your 40 security calls.

pine-5-TF Confluence Dashboard (complete)
1//@version=5
2indicator("5-TF Confluence", overlay=true)
3
4emaLen = input.int(21, "EMA Length", minval=1)
5
6// Helper: non-repainting trend detection
7getTrend(tf) =>
8 [emaVal, clVal] = request.security(syminfo.tickerid, tf,
9 [ta.ema(close, emaLen)[1], close[1]],
10 lookahead=barmerge.lookahead_on)
11 clVal > emaVal ? 1 : -1
12
13// 5 timeframes (5 security calls via tuples)
14t15m = getTrend("15")
15t1h = getTrend("60")
16t4h = getTrend("240")
17tD = getTrend("D")
18tW = getTrend("W")
19
20score = t15m + t1h + t4h + tD + tW
21allBull = score == 5
22allBear = score == -5
23
24// Table dashboard
25if barstate.islast
26 t = table.new(position.top_right, 3, 7,
27 bgcolor=color.new(#0d0b14, 10),
28 border_width=1, border_color=color.new(color.gray, 70))
29
30 table.cell(t, 0, 0, "TF", text_color=color.gray, text_size=size.small)
31 table.cell(t, 1, 0, "Trend", text_color=color.gray, text_size=size.small)
32 table.cell(t, 2, 0, "EMA", text_color=color.gray, text_size=size.small)
33
34 addRow(tbl, row, label, trend) =>
35 isBull = trend == 1
36 table.cell(tbl, 0, row, label,
37 text_color=color.white, text_size=size.small)
38 table.cell(tbl, 1, row, isBull ? "▲" : "▼",
39 text_color=isBull ? color.green : color.red,
40 text_size=size.small)
41 table.cell(tbl, 2, row, isBull ? "Above" : "Below",
42 text_color=isBull ? color.green : color.red,
43 text_size=size.small)
44
45 addRow(t, 1, "15m", t15m)
46 addRow(t, 2, "1H", t1h)
47 addRow(t, 3, "4H", t4h)
48 addRow(t, 4, "1D", tD)
49 addRow(t, 5, "1W", tW)
50
51 // Score row
52 scoreCol = score >= 3 ? color.green : score <= -3 ? color.red : color.yellow
53 table.cell(t, 0, 6, "Score", text_color=color.gray, text_size=size.small)
54 table.cell(t, 1, 6, str.tostring(score) + "/5",
55 text_color=scoreCol, text_size=size.small)
56 table.cell(t, 2, 6, score >= 3 ? "Bullish" : score <= -3 ? "Bearish" : "Mixed",
57 text_color=scoreCol, text_size=size.small)
58
59// Background coloring based on confluence
60bgCol = allBull ? color.new(color.green, 90) :
61 allBear ? color.new(color.red, 90) :
62 score >= 3 ? color.new(color.green, 95) :
63 score <= -3 ? color.new(color.red, 95) : na
64bgcolor(bgCol, title="Confluence BG")
65
66// Signal on full alignment + crossover
67currentEma = ta.ema(close, emaLen)
68bullEntry = allBull and ta.crossover(close, currentEma) and barstate.isconfirmed
69bearEntry = allBear and ta.crossunder(close, currentEma) and barstate.isconfirmed
70
71plotshape(bullEntry, "Full Bull", shape.triangleup,
72 location.belowbar, color.green, size=size.small, text="5/5")
73plotshape(bearEntry, "Full Bear", shape.triangledown,
74 location.abovebar, color.red, size=size.small, text="5/5")
75
76alertcondition(bullEntry, "5-TF Bull Confluence",
77 "All 5 timeframes bullish with EMA crossover")
78alertcondition(bearEntry, "5-TF Bear Confluence",
79 "All 5 timeframes bearish with EMA crossunder")

Trading with confluence scores

A score of 5/5 or -5/5 means every timeframe agrees. This is rare and powerful. A score of 3/5 or -3/5 means the dominant trend is clear but there is some divergence on shorter timeframes: still tradeable in the direction of the majority. A score near 0 means the market is in transition. Reduce position size or stay flat until alignment improves.

Put this lesson to work

Free on Thrive, no account needed.