首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Pine脚本(Tradingview)中绘制线条?

如何在Pine脚本(Tradingview)中绘制线条?
EN

Stack Overflow用户
提问于 2017-09-22 13:34:52
回答 2查看 28.3K关注 0票数 7

Pine编辑器仍然没有内置的绘制线条(如支持线、趋势线)的功能。我找不到任何直接或间接的方法来画线。我想要构建如下所示的函数(仅用于示例)

代码语言:javascript
复制
draw_line(price1, time1,price2, time2)

有什么想法或建议吗?

EN

回答 2

Stack Overflow用户

发布于 2019-07-06 21:54:39

现在可以在Pine Script v4中实现这一点

代码语言:javascript
复制
//@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上的一个垂直线函数:

代码语言:javascript
复制
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之前的线。

票数 5
EN

Stack Overflow用户

发布于 2019-02-28 00:33:52

更紧凑的线条绘制代码:

代码语言:javascript
复制
//@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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46357498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档