这是对this FAQ answer 中代码的改编,带有会话约束以满足您的需要。它仅适用于图表分辨率 设置/输入中设置与您的市场相对应的适当时间:
//@version=4
//@author=LucF, for PineCoders
study("Periodic hi/lo", "", true)
showHi = input(true, "Show highs")
showLo = input(true, "Show lows")
srcHi = input(high, "Source for Highs")
srcLo = input(low, "Source for Lows")
period = input("D", "Period after which hi/lo is reset", input.resolution)
timeAllowed = input("0930-1555", "Allowed hours", input.session)
timeIsAllowed = time(timeframe.period, timeAllowed)
var hi = 10e-10
var lo = 10e10
// When a new period begins, reset hi/lo. Only update hi/lo when time is allowed.
hi := change(time(period)) ? srcHi : timeIsAllowed ? max(srcHi, hi) : hi
lo := change(time(period)) ? srcLo : timeIsAllowed ? min(srcLo, lo) : lo
plot(showHi ? hi : na, "Highs", color.blue, 3, plot.style_circles)
plot(showLo ? lo : na, "Lows", color.fuchsia, 3, plot.style_circles)
您可以在这里看到在计算高点时如何不考虑最后的 15:55 柱:
关于security() 的gaps= 和lookahead= 参数,您可能会发现探索我们的How to avoid repainting when using security() - PineCoders FAQ 指标很有用。它显示了使用两个参数的所有设置组合绘制的值,并且最好避免重新绘制: