Pine Script - 如何获得当天的最高点,直到当前柱

Pine Script - How to get the high of current day, till current bar

我想获取当天的最高值。最高值应取自当天的前几根柱线。

我试过这个代码

security(syminfo.ticker, "D", high, lookahead=barmerge.lookahead_on)

但问题是它在当天的所有蜡烛之后取当天的最高值。

谢谢。

newDay = change(time("D")) != 0

float todaysHigh = na

if newDay
    todaysHigh := high
else if high > todaysHigh[1]
    todaysHigh := high
else
    todaysHigh := todaysHigh[1]

if块也可以写成三元:

todaysHigh := newDay ? high : high > todaysHigh[1] ? high : todaysHigh[1]