本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
//
// 5-day ADR (black, per-day segment) + cumulative range since day open (blue) + volume columns
// Right scale is in ticks (syminfo.mintick). Volume is rescaled into the ADR range so both fit one scale.
//
indicator(title="ICT 5 Days ADR & Volume", shorttitle="ADR", overlay=false, format=format.price)
showVolume = input.bool(true, title="show volume")
showADR = input.bool(true, title="show 5-day ADR")
ADR_LEN = 5
VOL_LEN = 100
MAX_DAYS = 90
inRange = time >= timenow - MAX_DAYS * 86400000
// Prior 5 completed days only: [1] + lookahead_on avoids repainting
dailyADR = request.security(syminfo.tickerid, "D", ta.sma(high - low, ADR_LEN)[1], lookahead=barmerge.lookahead_on) / syminfo.mintick
newDay = ta.change(time("D")) != 0
var float todayHigh = na
var float todayLow = na
if newDay or na(todayHigh)
todayHigh := high
todayLow := low
else
todayHigh := math.max(todayHigh, high)
todayLow := math.min(todayLow, low)
todayRange = (todayHigh - todayLow) / syminfo.mintick
// Fixed once at the start of the window so column heights stay proportional to raw volume, like the built-in indicator
maxVol = ta.highest(nz(volume), VOL_LEN)
var float volFactor = na
if inRange and na(volFactor) and maxVol > 0 and not na(dailyADR)
volFactor := dailyADR / maxVol
volScaled = nz(volume) * volFactor
volCol = close >= open ? color.new(#26a69a, 50) : color.new(#ef5350, 50)
plot(inRange and showVolume ? volScaled : na, title="Volume", style=plot.style_columns, color=volCol, display=display.pane)
plot(inRange and showVolume ? volume : na, title="Volume", color=volCol, format=format.volume, editable=false, display=display.status_line + display.data_window)
plot(inRange and showADR ? todayRange : na, title="Today Range", color=color.blue, linewidth=1)
// Break at each day start so every day gets its own segment
plot(inRange and showADR and not (newDay and timeframe.isintraday) ? dailyADR : na, title="5-Day ADR", style=plot.style_linebr, color=color.black, linewidth=2)