web-dev-qa-db-ja.com

パインスクリプト(Tradingview)で線を引く方法

パインエディターには、ライン(プロットライン、トレンドラインなど)をプロットする組み込み関数がまだありません。直接または間接的に線を引く方法が見つかりませんでした。以下のような関数を作成したい(例のみ)

draw_line(price1, time1,price2, time2)

アイデアや提案はありますか?

6
Ibrahim

残念ながら私はこれが彼らが提供したいものだとは思いません。 4年前から、決して実現しなかった有望な投稿に気づきました。他の唯一の方法は、関係のない部分を非表示にするラインプロットでラインを近似することにより、いくつかの計算を含むようです。

の場合:

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

このようなものを生成します:

enter image description here

次に、rednaに置き換えて、緑色のパーツのみを取得することもできます。

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

結果はかなりいいですが、使用するには不便です。 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
_

他の「新しい」行関数については、まだテストしていません。

9
not2qubit

Pine Script v4 でこれが可能になりました:

Preview

//@version=4
study("Line", overlay=true)
l = line.new(bar_index, high, bar_index[10], low[10], width = 4)
line.delete(l[1])
4
jaggedsoft

線を引くためのよりコンパクトなコード:

//@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
Andrey