Dollar Américain / Yen japonais
Éducation
Mis à jour

Pine講座㉓ 終値から ±2-ATR にラインを描画する

3326
label と line を応用して、
簡単なインジケーターを作成してみます。

今回つくるのは、最新の終値から
上下に2-ATRのところにラインを引くインジケーターです。

※ 以下のコードは、[]を半角の「[]」に書き換える必要があります

=====
//version=4
study( "終値から ±2-ATR にラインを描画する" ,overlay=true )

//ローソク足 1本分の時間を取得
dt = time - time[1]

//ATRを算出
atr20 = ema( tr ,20 )

//終値から±2-ATRの値を算出
c_p_2atr = close + atr20[1] * 2
c_m_2atr = close - atr20[1] * 2

// line を描画
var line upper = na
var line lower = na
line.delete( upper )
line.delete( lower )
upper := line.new( time-10*dt ,c_p_2atr ,time+30*dt ,c_p_2atr ,xloc.bar_time ,color=color.red )
lower := line.new( time-10*dt ,c_m_2atr ,time+30*dt ,c_m_2atr ,xloc.bar_time ,color=color.red )

// label を描画
var label label_top = na
var label label_bottom = na
label.delete( label_top )
label.delete( label_bottom )
label_top := label.new( time-10*dt ,c_p_2atr ,xloc=xloc.bar_time ,text="+2ATR" ,style=label.style_none )
label_bottom := label.new( time-10*dt ,c_m_2atr ,xloc=xloc.bar_time ,text="-2ATR" ,style=label.style_none )
=====
Note
次の講座
Pine講座㉔ 取引量を算出してインフォパネルに表示する

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.