将标签放在正确的位置

Put label in the right place

我正在编写一个脚本来放置不同的烛台图案,但是当放置标签时,它们被放置在零附近,而不是蜡烛附近,如何解决这个问题?

if (Body_Size < Line_Size*0.03) and ((Body_Low - low) < Line_Size*0.2) and ((Body_Hig - low) < Line_Size*0.2) and (Hig_Line > Line_Size*0.7) and Long_Line

label.new(bar_index, high + (atr(30) * 1), "Gravestone Doji", style=label.style_label_down)

您通过 y = high + (atr(30) * 1) 将标签放置在 label.new 函数中。

预期使用 label.new

label.new(bar_index, high, "Gravestone Doji", style=label.style_label_down)

atr 距离放在 if 语句之外。

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

ema1 = ema(close, 13)
ema2 = ema(close, 50)

condition = crossover(ema1, ema2)

plot(ema1)
plot(ema2)

// 
dist = atr(30) //leave atr outside
if condition
    label.new(bar_index, high + dist, "Gravestone Doji", style=label.style_label_down)
    // label.new(bar_index, high * 1.02, "Gravestone Doji", style=label.style_label_down) //or use % as distance