Pine script pivothigh/pivotlow未按预期工作

Pine script pivothigh/pivotlow未按预期工作,pine-script,Pine Script,为什么这段代码向我显示了错误的数据透视高度?它是每一秒计数酒吧的左侧和右侧,而不仅仅是一个。。。如果我更改为: bar\u索引%1==0,它工作正常 这里是我的代码: //@version=4 study("fckn test", overlay=true) if bar_index % 2 == 0 ph = pivothigh(1,1) label.new(bar_index-1, low, tostring(ph)) 不太确定你想做什么。也许是这个 //@versi

为什么这段代码向我显示了错误的数据透视高度?它是每一秒计数酒吧的左侧和右侧,而不仅仅是一个。。。如果我更改为:

bar\u索引%1==0
,它工作正常

这里是我的代码:

//@version=4
study("fckn test", overlay=true) 

if bar_index % 2 == 0
    ph = pivothigh(1,1)

    label.new(bar_index-1, low, tostring(ph))

不太确定你想做什么。也许是这个

//@version=4
study("fckn test", overlay=true)
pivotLegs = 1
// Find pivot outside `if` block because needs to run on every bar.
ph = pivothigh(pivotLegs, pivotLegs)
// Detect a new pivot.
newPh = not na(ph)
// If a new pivot is found, save the bar index where it was found.
bh = newPh ? bar_index - pivotLegs : na
if bar_index % 2 == 0 and not na(ph)
    label.new(bh, high[pivotLegs], tostring(ph))

谢谢您的回答。为什么不能在IF语句下使用函数pivothigh()?因为如果我在if语句下使用它,它将产生意想不到的结果。例如,我想过滤一些图案,例如三支绿色蜡烛,如果是真的,我想找到pivothigh。不客气。许多需要在每个条上执行的函数在
if
块中无法正常工作。看见