如何在 Pine Script 中绘制 MA 水平线
How to draw MA horizontal lines in Pine Script
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函数显示在整个布局中,但我不希望那样显示。我想让它达到我贴在底部的结果。
您可以使用 drawings 中的 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)
蓝线是 plot
,黄线是 line
。
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函数显示在整个布局中,但我不希望那样显示。我想让它达到我贴在底部的结果。
您可以使用 drawings 中的 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)
蓝线是 plot
,黄线是 line
。