如何在TradingView松树脚本中绘制垂直线?

not*_*bit 3 pine-script

我正在尝试使用基于Web的TradingView平台来制作自己的自定义脚本,以显示各种金融市场属性。这可以通过其pine脚本引擎/解释器实现。

目前,我试图在主图表或指标图表上仅显示一条垂直线。但是,除非使用绘图histogramcolumn类型,否则他们的脚本引擎似乎并不支持垂直线。无论哪种方式,我都无法获得满意的评价。


一些测试

(1)bgcolor()像这样使用取得了一些次要的成功:

//@version=3
study(title="vbar1", overlay = false)
trange(res, sess) => not na(time(res, sess))
vlinecol = #000000 // black
plot(n, color = na) // check last value from plot but don't display
vline =  (n < 5710) ? na : trange("1", "0700-0701") ? vlinecol : na
bgcolor(vline, transp=0)
Run Code Online (Sandbox Code Playgroud)

结果是:

在此处输入图片说明

(2)plot()style=histogram参数一起使用时会得到更好的结果:

//@version=3
study(title="vbar2", overlay = true) // scale=scale.none only for overlay=true
vlinecol = #000000 // black
cond = barstate.islast
bh = 10*high   // Use 10 x the window max price height for top of vbar (or use 1e20)
bo = -10       // Set offset from last bar
plot(cond ? bh : na, color=vlinecol, linewidth=2, offset=bo, style = histogram, transp=0)
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此处输入图片说明

小智 5

这是一个旧帖子,但这可以帮助其他人。您可以使用它来画一条线:

testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
plot((time==testPeriodStart)?10e20:na,color=black, linewidth=1, style=line)
Run Code Online (Sandbox Code Playgroud)

但是我无法绘制虚线


And*_*dré 5

如果有人有兴趣使用新的v4 line.new()功能:

注意:LineLengthMult根据需要进行调整。

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

//@version=4
study("My Script", overlay=true)
LineLengthMult = 10
LineLength = atr(100) * LineLengthMult

drawVerticalLine(offset) =>
    line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)

if bar_index % 21 == 0
    drawVerticalLine(0)
Run Code Online (Sandbox Code Playgroud)

交易视图图表显示了 marketscripters.com 的垂直线

编辑:答案更新为自动缩放垂直线的代码。