如何从 5m 图表中获取指标的最后一个值

时间:2021-05-21 13:36:30

标签: pine-script

嗨,我可以只获取当天的指标收盘值来计算第二天吗? (示例:标准偏差值如图所示)

谢谢

Indicator Close value

1 个答案:

答案 0 :(得分:0)

newDay = change(time("D")) != 0
sd = stdev(close, 20)
sdDailyClose = valuewhen(newDay, sd[1], 0)

这将为您提供前一天的收盘价。

如果您想要值 AT eod,您需要知道时间范围和会话的结束时间。这假设下午 3:30 关闭(15:30)

var float closingSD = na
var int minutes = timeframe.isintraday ? 30 - timeframe.multiplier : na
sd = stdev(close, 20)
closingBarTime = timestamp(year, month, dayofmonth, 15, minutes)
if time >= closingBarTime and barstate.isconfirmed
    closingSD := sd

如果你只打算在 5m 图表上使用它,你可以将它减少到这个

var float closingSD = na
sd = stdev(close, 20)
closingBarTime = timestamp(year, month, dayofmonth, 15, 25)
if time >= closingBarTime and barstate.isconfirmed
    closingSD := sd