如何在 Pine Script 中绘制 MA 水平线

发布于 2025-01-19 11:42:11 字数 579 浏览 1 评论 0原文

dma120=request.security(syminfo.tickerid, "D",ta.sma(close,120))
plot(dma120, color= color.blue, title = "D MA120" )

h4ma30=request.security(syminfo.tickerid, "240",ta.sma(close,30))
plot(h4ma30, color= color.red, title = "4H MA30" )

hline(3.14, title='Pi', color=color.blue, linestyle=hline.style_dotted, linewidth=2)

这样就只能绘制线条,无法将MA的值用到HLINE函数中。

它通过使用 Hline 功能以整个布局显示,但我不希望以这种方式显示。我希望它达到我在底部附加的结果。

输入图片此处描述

dma120=request.security(syminfo.tickerid, "D",ta.sma(close,120))
plot(dma120, color= color.blue, title = "D MA120" )

h4ma30=request.security(syminfo.tickerid, "240",ta.sma(close,30))
plot(h4ma30, color= color.red, title = "4H MA30" )

hline(3.14, title='Pi', color=color.blue, linestyle=hline.style_dotted, linewidth=2)

In this way, it can only plot the lines, and it is impossible to use the value of the MA to the HLINE function.

It is displayed in whole layout by using Hline function, but I don't want it in that way. I want it achieved the result that I attached on the bottom.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2025-01-26 11:42:11

您可以通过line图纸

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator("My script", max_lines_count=1, overlay=true)

dma120=request.security(syminfo.tickerid, "D", ta.sma(close,120))
plot(dma120, color= color.blue, title = "D MA120" )

var line l_dma120 = line.new(bar_index, dma120, bar_index+1, dma120, extend=extend.right, color=color.yellow)

if barstate.islast
    line.set_xy1(l_dma120, bar_index, dma120)
    line.set_xy2(l_dma120, bar_index+1, dma120)

蓝线是绘图,黄线是line

You can do that by using line from drawings.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator("My script", max_lines_count=1, overlay=true)

dma120=request.security(syminfo.tickerid, "D", ta.sma(close,120))
plot(dma120, color= color.blue, title = "D MA120" )

var line l_dma120 = line.new(bar_index, dma120, bar_index+1, dma120, extend=extend.right, color=color.yellow)

if barstate.islast
    line.set_xy1(l_dma120, bar_index, dma120)
    line.set_xy2(l_dma120, bar_index+1, dma120)

Blue line is the plot, and yellow line is the line.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文