获得历史最高的 EMA 值 Pine Editor

Getting highest all-time ema value Pine Editor

我试图在 Pine Editor 中获得历史最高的 200 ema 收盘价,但我一直获得 N/A 的价值。我的代码是:

f_highest_since(_highseries,_sinceevent) =>
    var float _peak = na
    _peak := _highseries>_peak or _sinceevent ? _highseries : _peak

f_lowest_since(_lowseries,_sinceevent) =>
    var float _bottom = na
    _bottom := _lowseries<_bottom or _sinceevent ? _lowseries : _bottom

maxema = f_highest_since(ema(close,200), bar_index[0]==0)

有趣的是,如果我将 ema(close, 200) 替换为更简单的东西(例如 close),它就会起作用。有谁知道为什么会这样?

条件 bar_index[0]==0 仅对第一个柱有效,其余时间 return 为假,考虑到函数 ema 产生的第一个值是na 结果 na 合乎逻辑。

您可能想改用:

ema = ema(close,200)
max = 0.
max := max(ema,nz(max[1]))