可以使用以下代码将返回时间更改为每半个小时。您需要将aggTime设置为1或2(1代表每半小时返回聚合值,2代表每小时的整点时返回聚合值)。
//@version=4
study("My Script")
aggTime = 1 //Every half hour
aggregationPeriod() =>
periodLength = time - time[1]
ms = nz(time('millisecond')) - 1
rem = ms % 60000
curSecond = rem == 0 ? sec : ((rem / 1000) + 1)
curMinute = (curSecond == 60) ? (minute + 1) % aggTime : minute % aggTime
curHour = curMinute == 0 ? hour : hour - (hour % aggTime)
curDay = dayofmonth(time[1])
[curSecond, curMinute, curHour, curDay]
adx(14)
barTime = aggregationPeriod()
barIndex = bar_index
[highest, lowest, _] = security(syminfo.tickerid, barTime, [high, low, barstate.isconfirmed])
plot(highest, "High", color.lime, 2)
plot(lowest, "Low", color.red, 2)