我试图使用基于网络的TradingView平台来制作我自己的自定义脚本,以显示各种金融市场属性。通过它的松树脚本引擎/解释器,这是可能的。
目前,我正试图简单地在主图表或指示图上显示一条垂直线。但是,他们的脚本引擎似乎并不支持垂直行,除非使用了绘图的histogram
或column
类型。无论如何,我都无法得到任何令人满意的台词。
一些测试
(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)
这导致:
(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)
其结果如下:
发布于 2020-07-07 02:13:29
如果有人对使用新的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)
编辑:使用自动缩放垂直线的代码更新答案.
发布于 2018-07-07 05:37:46
这是一个旧的职位,但这可以帮助其他人。你可以用它来画一条线:
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
plot((time==testPeriodStart)?10e20:na,color=black, linewidth=1, style=line)
但我没能画出虚线。
发布于 2019-02-01 02:16:02
丹妮的回答并没有为我在图表上显示任何东西,不过把样式设置成柱状图就成功了。
//@version=3
study("Vertical lines", overlay=true, scale=scale.none)
plot((time == timestamp(2019,01,01,0,0)) ? 10e20 : na,
color = red, linewidth = 10, title = "27", style = histogram)
plot((time == timestamp(2019,01,02,0,0)) ? 10e20 : na,
color = green, linewidth = 10, title = "28", style = histogram)
https://stackoverflow.com/questions/47610638
复制相似问题