【问题标题】:How do I detect if a candle closes above/below a pivot point?如何检测蜡烛是否在枢轴点上方/下方收盘?
【发布时间】:2021-08-27 18:15:22
【问题描述】:

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

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

问题在于检查蜡烛的收盘价是否高于/低于枢轴高点/低点不起作用。突破枢轴点的蜡烛标签没有显示,即使它们应该显示。

我正在使用一个简单的 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")

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    固定的,

    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)
    
    
    

    【讨论】:

    • 谢谢,但显示的标签只是枢轴点。我的意思是交叉和交叉标签不起作用。应该有这些“Breakout Candle Pivot High”标签显示交叉。但他们没有出现。对不起,如果我不够清楚。
    • 对不起,我看错了。您的代码缺少枢轴的存储值。标签现在正在工作。更好地绘制所有内容以对其进行调试,如果您查看数据窗口,您可以看到 phigh 和 plow 大部分时间都没有,因此需要存储一个值。如果这对您有帮助,请按添加声誉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多