为当前脚本添加标签并有 8 条静态行

时间:2021-08-01 21:50:53

标签: pine-script

我正在尝试修改脚本,以便我可以在创建的每一行上方使用自定义标签。我还试图让脚本显示一个最新的静态行,而不是过去已更改的行。基本上所有 8 个级别只有一条水平线,而不是所有 8 条线都是可变的,这意味着它们是不同的。如果有人可以帮助我,这是代码,我已尽力弄清楚并且无法解决。

study("Murray Math Levels",shorttitle="MML",overlay=true)
p = input(64,title="Length")

haut = highest(close,p)
bas = lowest(close,p)

h4 = haut+(haut-bas)/8
h5 = h4+(haut-bas)/8

h3 = haut-(haut-bas)/8
h2 = h3-(haut-bas)/8
h1 = h2-(haut-bas)/8
MP = h1-(haut-bas)/8
el = MP-(haut-bas)/8
tw = el-(haut-bas)/8
th = tw-(haut-bas)/8

fo = bas-(haut-bas)/8
fi = fo-(haut-bas)/8

plot(fi,title="L5",transp=60)
plot(fo,title="L4",transp=30)
plot(bas,title="Bas")
plot(th,title="L3",color=blue)
plot(tw,title="L2",color=orange)
p1=plot(el,title="L1",color=red)
plot(MP,title="MP")
p2=plot(h1,title="H1",color=red)
plot(h2,title="H2",color=orange)
plot(h3,title="H3",color=blue)
plot(haut,title="Haut")
plot(h4,title="H4",transp=30)
plot(h5,title="H5",transp=60)
fill(p1,p2)`

1 个答案:

答案 0 :(得分:0)

首先,您必须确保使用 v4 标头来使用 line 和 label 函数。然后使用 var 声明您的线条/标签/框。然后使用 set 函数根据相应的变量(h1、el 等)定位行。

//@version=4
study("Murray Math Levels",shorttitle="MML",overlay=true)
p = input(64,title="Length")

haut = highest(close,p)
bas = lowest(close,p)

h4 = haut+(haut-bas)/8
h5 = h4+(haut-bas)/8

h3 = haut-(haut-bas)/8
h2 = h3-(haut-bas)/8
h1 = h2-(haut-bas)/8
MP = h1-(haut-bas)/8
el = MP-(haut-bas)/8
tw = el-(haut-bas)/8
th = tw-(haut-bas)/8

fo = bas-(haut-bas)/8
fi = fo-(haut-bas)/8


// TH line and label
var line th_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_index, extend = extend.none,  color = color.blue, style = line.style_solid, width = 1)
line.set_xy1(id = th_line, x = bar_index - p, y = th)
line.set_xy2(id = th_line, x = bar_index, y = th)

var label th_label = label.new(x = na, y = na, xloc = xloc.bar_index, color = color.rgb(0, 0, 0, 100), textcolor = color.blue, style = label.style_label_left, text = "TH", size = size.small)
label.set_xy(id = th_label, x = bar_index, y = th)

// EL line and label
var line el_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_index, extend = extend.none,  color = color.red, style = line.style_solid, width = 1)
line.set_xy1(id = el_line, x = bar_index - p, y = el)
line.set_xy2(id = el_line, x = bar_index, y = el)

var label el_label = label.new(x = na, y = na, xloc = xloc.bar_index, color = color.rgb(0, 0, 0, 100), textcolor = color.red, style = label.style_label_left, text = "EL", size = size.small)
label.set_xy(id = el_label, x = bar_index, y = el)

// H1 line and label
var line h1_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_index, extend = extend.none,  color = color.red, style = line.style_solid, width = 1)
line.set_xy1(id = h1_line, x = bar_index - p, y = h1)
line.set_xy2(id = h1_line, x = bar_index, y = h1)

var label h1_label = label.new(x = na, y = na, xloc = xloc.bar_index, color = color.rgb(0, 0, 0, 100), textcolor = color.red, style = label.style_label_left, text = "H1", size = size.small)
label.set_xy(id = h1_label, x = bar_index, y = h1)


// Color fill el and h1 using box()
var box el_h1_box = box.new(left = na, top = na, right = na, bottom = na, border_color = color.rgb(0, 0, 0, 100), extend = extend.none, xloc = xloc.bar_index, bgcolor = color.new(color.red, 70))
box.set_lefttop(id = el_h1_box, left = bar_index - p, top = h1)
box.set_rightbottom(id = el_h1_box, right = bar_index, bottom = el)