Ibr*_*him 4 finance line tradingview-api pine-script
Pine编辑器仍然没有内置函数来绘制线条(例如支撑线,趋势线).我找不到任何直接或间接的方法来绘制线条.我想构建如下所示的函数(仅举例)
draw_line(price1, time1,price2, time2)
Run Code Online (Sandbox Code Playgroud)
任何想法或建议?
不幸的是,我不认为这是他们想要提供的东西.注意到4年前从未发过的几个有希望的帖子.唯一的另一种方式,似乎涉及一些计算,通过用一些线图近似你的线,你隐藏不相关的部分.
对于例如:
...
c = close >= open ? lime : red
plot(close, color = c)
Run Code Online (Sandbox Code Playgroud)
会产生这样的东西:
然后,你可以尝试更换red
与na
只拿到绿色部分.
例2
我做了一些实验.显然Pine是如此残缺,你甚至无法将一个情节放在功能中,所以唯一的方法似乎是使用一条线的斜率公式,如下所示:
//@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 )
Run Code Online (Sandbox Code Playgroud)
现在可以在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])
Run Code Online (Sandbox Code Playgroud)
这是 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
Run Code Online (Sandbox Code Playgroud)
if barstate.islast
如果您只绘制一次线条而不是在每根蜡烛上绘制,您也可以使用,这样您就不需要delete
之前的线条。