Pine编辑器仍然没有内置的绘制线条(如支持线、趋势线)的功能。我找不到任何直接或间接的方法来画线。我想要构建如下所示的函数(仅用于示例)
draw_line(price1, time1,price2, time2)
有什么想法或建议吗?
发布于 2019-07-06 21:54:39
现在可以在Pine Script v4中实现这一点
//@version=4
study("Line", overlay=true)
l = line.new(bar_index, high, bar_index[10], low[10], width = 4)
line.delete(l[1])
下面是midtownsk8rguy在TradingView上的一个垂直线函数:
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line Function, ≈50-54 lines maximum allowable per indicator
// return = line.new(BarIndex, 0.0, BarIndex, 100.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and RSI, Stochastic, etc...
// return = line.new(BarIndex, -1.0, BarIndex, 1.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and +/-1.0 oscillators
return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=true)
if(bar_index%10==0.0) // Generically plots a line every 10 bars
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
如果你只画一次线而不是在每根蜡烛上画一次线,你也可以使用if barstate.islast
,这样你就不需要delete
之前的线。
发布于 2019-02-28 00:33:52
更紧凑的线条绘制代码:
//@version=3
study("Draw line", overlay=true)
plot(n, color=na, style=line)
AB(x1,x2,y1,y2) => n < x1 or n > x2 ? na : y1 + (y2 - y1) / (x2 - x1) * (n - x1)
plot(AB(10065,10136,3819,3893), color=#ff00ff, linewidth=1, style=line,
transp=0)
plot(AB(10091,10136,3966.5,3931), color=#ff00ff, linewidth=1, style=line,
transp=0)
https://stackoverflow.com/questions/46357498
复制相似问题