如何在Pine脚本(Tradingview)中绘制线条?
问题描述:
松编辑器仍然没有内置函数来绘制线(如支持线,趋势线)。 我找不到任何直接或间接的方法来绘制线条。 我想建立功能看起来像下面(例如只)如何在Pine脚本(Tradingview)中绘制线条?
draw_line(price1, time1,price2, time2)
任何意见或建议?
答
不幸的是,我不认为这是他们想提供的东西。注意到4年前的几个有前途的帖子,从来没有出现过。唯一的另一种方式,似乎涉及到一些计算,通过用一些线图来近似你的线,在那里隐藏不相关的部分。
对于example:
...
c = close >= open ? lime : red
plot(close, color = c)
会产生这样的:
然后,你可以尝试用na
更换red
只拿到绿色部分。
例2
我做了一些更多的实验。显然,松是这样残废,你甚至不能把一个情节功能,所以唯一的办法似乎是用点斜率公式为一条线,像这样:
//@version=3
study(title="Simple Line", shorttitle='AB', overlay=true)
P1x = input(5744)
P1y = input(1.2727)
P2x = input(5774)
P2y = input(1.2628)
plot(n, color=na, style=line) // hidden plot to show the bar number in indicator
// point slope
m = - (P2y - P1y)/(P2x - P1x)
// plot range
AB = n < P1x or n > P2x ? na : P1y - m*(n - P1x)
LA = (n == P1x) ? P1y : na
LB = (n == P2x) ? P2y : na
plot(AB, title="AB", color=#ff00ff, linewidth=1, style=line, transp=0)
plotshape(LA, title='A', location=location.absolute, color=silver, transp=0, text='A', textcolor=black, style=shape.labeldown)
plotshape(LB, title='B', location=location.absolute, color=silver, transp=0, text='B', textcolor=black, style=shape.labelup)