Data and requests
Read another timeframe and the previous day's figures with a request, in programs that are compiled and run.
A request evaluates an expression on another timeframe and gives its value on the bars of this chart. The documentation's synthetic data builds the higher timeframes from the lower one.
Higher timeframe average#
A request for another timeframe with data.series, drawn beside the same average on this chart.
Cuprel
// A request for another timeframe: the 4-hour EMA of the close, drawn on whatever chart the script is on.
// `data.series` evaluates the expression on the other timeframe and gives back its last closed value.
indicator "Higher timeframe average"
edition = 1
display = price
input tf: tf = "240", name = "Timeframe"
input length: int = 20, name = "Length", min = 2
let other = data.series(tf, tech.ema(close, length), symbol = symbol.id)
plot(other, name = "EMA on the other timeframe", color = color.orange, width = 2)
plot(tech.ema(close, length), name = "EMA on this chart", color = color.gray)Daily pivot levels#
Classic floor pivots from the previous day read with prior(day, 1).
Cuprel
// Classic floor pivots from the previous day: P = (H + L + C) / 3, R1 = 2P - L, S1 = 2P - H.
// `prior(day, 1)` reads the last finished day, so the levels are known from the first bar of the new day.
indicator "Daily pivot levels"
edition = 1
display = price
let prior_high = prior(day, 1).high
let prior_low = prior(day, 1).low
let prior_close = prior(day, 1).close
let pivot = (prior_high + prior_low + prior_close) / 3
plot(pivot, name = "Pivot", color = color.gray)
plot(2 * pivot - prior_low, name = "R1", color = color.red)
plot(2 * pivot - prior_high, name = "S1", color = color.green)