【问题标题】:price labels of the support and resistance levels are not showing in the right place支撑位和阻力位的价格标签没有显示在正确的位置
【发布时间】:2019-09-22 05:58:21
【问题描述】:

编辑以包含我想要的图片。

the long arrows show where the labels should be

我的 label.new 代码没有按照我想要的方式运行,即打印高于/低于阻力位/支撑位的标签。

我试过了

label.new(bar_index, top1, tostring(top1), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labeldown, color=color.red, size=size.small)

但是那个 xloc 是不对的,当它编译时,它会显示当前蜡烛上的所有标签。

study(title="srlabel", overlay=true)

 //code from [RS] support and resistance indicator

window1 = input(title='lookback window 1', type=input.integer, defval=8)
window2 = input(title='lookback window 2', type=input.integer, defval=21)

top1 = valuewhen(high >= highest(high, window1), high, 0)
bot1 = valuewhen(low <= lowest(low, window1), low, 0)
top2 = valuewhen(high >= highest(high, window2), high, 0)
bot2 = valuewhen(low <= lowest(low, window2), low, 0)

//this is what I've added to show the price of the s/r levels

label.new(bar_index, top1, tostring(top1), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labeldown, color=color.red, size=size.small)

label.new(bar_index, bot1, tostring(bot1), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labelup, color=color.blue, size=size.small)

//plots

t1 = plot(top1, color=top1 != top1[1] ? na : color.red, linewidth=1, title="")
b1 = plot(bot1, color=bot1 != bot1[1] ? na : color.blue, linewidth=1, title="")
t2 = plot(top2, color=top2 != top2[1] ? na : color.red, linewidth=1, title="")
b2 = plot(bot2, color=bot2 != bot2[1] ? na : color.blue, linewidth=1, title="")

fill(t1, t2, transp=80, color=color.red, title="")
fill(b1, b2, transp=80, color=color.blue, title="")

我想在各自的价格蜡烛上方和下方显示标签。我认为解决方案都取决于该 xloc 规范。

任何想法将不胜感激。

【问题讨论】:

    标签: plot pine-script


    【解决方案1】:

    这仅在级别更改时打印您的标签:

    if change(top1)
        label.new(bar_index, top1, tostring(top1), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labeldown, color=color.red, size=size.small)
    
    if change(bot1)
        label.new(bar_index, bot1, tostring(bot1), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labelup, color=color.blue, size=size.small)
    

    [编辑 2019.09.23 20:39 — LucF] 也许这更接近您正在寻找的内容:

    if change(top2)
        label.new(bar_index, top2, tostring(top2), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labeldown, color=color.red, size=size.small)
    
    if change(bot2)
        label.new(bar_index, bot2, tostring(bot2), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_labelup, color=color.blue, size=size.small)
    

    【讨论】:

    • 嘿 Luc,谢谢您的评论。但这对我不起作用,如屏幕截图所示。 imgur.com/cc1bbay 如何将 xloc 放在找到 top1 或 bot1 价格的位置?似乎我尝试过的应该这样做,但我错过了一些东西。
    • 正如我的答案随附的图表中所示,标签现在仅在 bot1top1 更改时打印,这就是我想你说你想要它们时的意思 它在哪里找到了 top1 或 bot1 价格。如果这不是您需要的,请更好地解释它,因为我看不出您还想要什么。
    • 编辑了 OP 以包含它应该是什么样子的图片。箭头显示标签应位于的位置
    • 使用模组编辑答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多