如何检测蜡烛是否收盘 above/below 枢轴点?

How do I detect if a candle closes above/below a pivot point?

我是 Pine 脚本的新手,想编写一个简单的指标来检测蜡烛收盘价是高于枢轴高位还是低于枢轴低位。

我成功实现了枢轴点并正确标记了它们。

问题是检查蜡烛的收盘价是否 higher/lower 而不是枢轴 high/low 不起作用。突破枢轴点的蜡烛上的标签没有显示,即使它们应该显示。

我正在使用一个简单的 if 语句来检查收盘价是更高还是更低。

这是我的代码:

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


// Pivot points implementation

leftbars = input(7)
rightbars = input(7)

phigh = pivothigh(high, leftbars, rightbars)
plow = pivotlow (low , leftbars, rightbars)


// Printing a label at pivot points 

label1 = phigh ? label.new(bar_index[rightbars], high[rightbars], text=tostring(phigh), style=label.style_labeldown, color=color.white) : na
label2 = plow ? label.new(bar_index[rightbars], low[rightbars], text=tostring(plow), style=label.style_labelup, color=color.white) : na


// Checking if close is higher than the pivot high or lower than the pivot low

if (close > phigh)
    label.new(bar_index, close, text="Breakout Candle Pivot High")


if (close < plow)
    label.new(bar_index, close, text="Breakout Candle Pivot Low")

固定,

https://www.tradingview.com/x/7q60SFDV/

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



// Pivot points implementation

leftbars = input(7, "leftbars")
rightbars = input(7, "right")


phigh = pivothigh(high, leftbars, rightbars)
plow = pivotlow (low , leftbars, rightbars)


// Use valuewhen to store value of pivot point

Storedphigh = valuewhen(phigh, phigh, 0)
plot(Storedphigh, title="Phigh", offset=-leftbars)


Storedplow = valuewhen(plow, plow, 0)
plot(Storedplow, title="Plow", offset=-leftbars)


// Printing a label at pivot points 

label1 = phigh ? label.new(bar_index[rightbars], high[rightbars], text=tostring(phigh), style=label.style_labeldown, color=color.white) : na
label2 = plow ? label.new(bar_index[rightbars], low[rightbars], text=tostring(plow), style=label.style_labelup, color=color.white) : na


//Checking if close is higher than the pivot high or lower than the pivot low
//
if (crossover(close, Storedphigh))
    label.new(bar_index, high, text="Breakout Candle Pivot High", style=label.style_label_down)


if (crossunder(close, Storedplow))
    label.new(bar_index, low, text="Breakout Candle Pivot High", style=label.style_label_up)