0

我想构建一个 pine 脚本,它可以在不使用安全功能的情况下从 09:30 到 16:00 给我 10 天的平均交易量。我想使用 15 分钟图表计算 10 天的平均交易量。帮我编写这个松树脚本。我是松树脚本的新手。

4

1 回答 1

0
//@version=5
indicator("10 Day volume average", overlay = false)

len = input(10)

var float todays_volume = na
var float[] daily_volume_array = array.new_float()

within_time_range = time >= timestamp(year, month, dayofmonth, 9, 30) and time < timestamp(year, month, dayofmonth, 16, 0)

// Or if you need to account for timezone
//within_time_range = time >= timestamp("GMT+3", year, month, dayofmonth, 9, 30) and time < timestamp("GMT+3", year, month, dayofmonth, 16, 0)

if within_time_range and not within_time_range[1]
    array.unshift(daily_volume_array, todays_volume)
    if array.size(daily_volume_array) > len
        array.pop(daily_volume_array)
    todays_volume := volume
else if within_time_range
    todays_volume += volume

avg_vol = array.avg(daily_volume_array)

plot(avg_vol)
    
于 2022-01-05T22:09:19.443 回答