首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >松树脚本:如何在水平线上添加和显示文本?

松树脚本:如何在水平线上添加和显示文本?
EN

Stack Overflow用户
提问于 2022-11-13 20:35:08
回答 1查看 82关注 0票数 0

我想包括一个文本输入功能,以添加文本到水平线/线,我正在策划的变化率指标。这些线路本质上就像70/30的RSI超买和超卖线路,但我用它们作为概率区域。我想要能够写在文字,将显示在每一行的情节。Tradingview提供了一个带有文本输入和选项的自定义水平线绘图工具,用于将文本对齐到右、中或左。我希望将这些特征包括在变化率指标中,其中包括一组标有概率区域的水平线。谢谢你的帮助

代码语言:javascript
运行
复制
//@version=5
indicator(title="Rate Of Change", shorttitle="ROC-w-prb-lne", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
length = input.int(1, minval=1)
source = input(close, "Source")
roc = 100 * (source - source[length])/source[length]
plot(roc, color=#2962FF, title="ROC-w-probty ln")
hline(0.5, color=#edde35, title="50% (+25%) prob Line")
hline(-0.5, color=#edde35, title="50% (-25%) prob line")
hline(1.0, color=#2950de, title="75% (+38%) Line")
hline(-1.0, color=#2950de, title="75% (-36%) Line")
hline(2.5, color=#787B86, title="95% (+48%) line")
hline(-2.5, color=#787B86, title="95% (-48%) line")
hline(3.5, color=#c73030, title="98% (+49%) line")
hline(-3.5, color=#c73030, title="98% (-49%) line")
EN

回答 1

Stack Overflow用户

发布于 2022-11-13 21:59:30

如果你想显示一些文字,你应该使用“标签”。将其y参数设置为您的hline值,并根据您的意愿操作x参数。

您可以使用bar_indexchart.left_visible_bar_timechart.right_visible_bar_time来操作x坐标。

以下是一些例子:

代码语言:javascript
运行
复制
//@version=5
indicator("My script")

hline_price_1 = 100
hline_price_2 = 75
hline_price_3 = 50
hline_price_4 = 25

hline(hline_price_1)
hline(hline_price_2)
hline(hline_price_3)
hline(hline_price_4)

label hline_label_1 = label.new(bar_index, hline_price_1, str.tostring(hline_price_1), style=label.style_none, textcolor=color.white)
label hline_label_2 = label.new(bar_index - 50, hline_price_2, str.tostring(hline_price_2), style=label.style_none, textcolor=color.white)
label hline_label_3 = label.new(chart.left_visible_bar_time, hline_price_3, str.tostring(hline_price_3), xloc=xloc.bar_time, style=label.style_none, textcolor=color.white)
label hline_label_4 = label.new(chart.right_visible_bar_time, hline_price_4, str.tostring(hline_price_4), xloc=xloc.bar_time, style=label.style_none, textcolor=color.white)

label.delete(hline_label_1[1])
label.delete(hline_label_2[1])
label.delete(hline_label_3[1])
label.delete(hline_label_4[1])

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74424561

复制
相关文章

相似问题

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