首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将标签添加到当前脚本,并具有8行静态行

将标签添加到当前脚本,并具有8行静态行
EN

Stack Overflow用户
提问于 2021-08-01 21:50:54
回答 1查看 59关注 0票数 1

我正在尝试修改一个脚本,以便我可以在创建的每一行上有自定义标签。我还试图让脚本显示一个最新的静态行,而不是已经更改的过去行。本质上,所有8个级别只有一条水平线,而不是过去所有8条线都是可变的,它们是不同的。以下是代码,如果有人可以帮助我,我尽我最大的努力来解决它和不能。

代码语言:javascript
复制
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)`
EN

回答 1

Stack Overflow用户

发布于 2021-08-02 03:55:52

首先,您必须确保使用v4标头来利用行和标签函数。然后使用var声明您的行/标签/框。之后,使用集合函数根据其对应的变量(h1、el等)来定位直线。

代码语言:javascript
复制
//@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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68614619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档