Skip to content

GIST: example of "Amount Integral Considering Non‐Trading Time“

megashare edited this page Aug 31, 2023 · 2 revisions
//@version=5
indicator("Amount Integral Considering Non-Trading Time", shorttitle="AICT", overlay=true)

period = '15'

// 获取价格和交易量
price = request.security("HKEX:700", period, close)
vol = request.security("HKEX:700", period, volume)
amt = vol * price
// 获取每根K线的时间戳
current_time = request.security("HKEX:700", period, time)
// 从当前时间开始,向前遍历,直到累积时间达到hr小时
sumOverHours(hr) =>
    sumVolume = 0.0
    sumTime = 0
    sumAmount = 0.0
    i = 0
    while sumTime < hr * 3600 and i < 4320 
        sumTime := sumTime + nz(current_time[i] - current_time[i+1])
        //sumVolume := sumVolume + nz(vol[i])
        sumAmount := sumAmount + nz(amt[i])
        i := i + 1
    //sumVolume
    sumAmount
plot(sumOverHours(72)/72, color=color.blue)
Clone this wiki locally