Pine講座㉓ 終値から ±2-ATR にラインを描画する 教育 U.S. Dollar/Japanese Yen FXCM
詳細 ⋅ 2019年7月15日午後10時58分 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 ) =====