gpt4 book ai didi

line - 如何在 Pine 脚本(Tradingview)中画线?

转载 作者:行者123 更新时间:2023-12-03 09:52:49 32 4
gpt4 key购买 nike

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

draw_line(price1, time1,price2, time2)

任何想法或建议?

最佳答案

不幸的是,我不认为这是他们想要提供的东西。注意到 4 年前的几个有前途的帖子,但从未通过。唯一的另一种方法似乎涉及一些计算,通过用一些线图近似你的线,你隐藏不相关的部分。

对于 example :

...
c = close >= open ? lime : red
plot(close, color = c)

会产生这样的东西:

enter image description here

那么,你可以尝试更换 redna只获得绿色部分。

示例 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 )

结果相当不错,但使用起来太不方便了。
enter image description here

更新: 2019-10-01

显然他们已经为 Pinescript 添加了一些新的行功能 4.0+ .
这是使用新 的示例vline() 功能:

//@version=4
study("vline() Function for Pine Script v4.0+", overlay=true)

vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line, 54 lines maximum allowable per indicator
return = line.new(BarIndex, -1000, BarIndex, 1000, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)

if(bar_index%10==0.0)
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required

至于其他的"new"线路功能,我还没有测试过。

关于line - 如何在 Pine 脚本(Tradingview)中画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46357498/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com