【最終更新日】2021年2月15日

line.new()

チャート上にラインオブジェクトを作成するための関数。

Pine Scriptには水平ラインを引くためのhline()が用意されているが、垂直ラインを引くための関数は用意されていない。 垂直ラインを引きたい場合は、このline.new()を使うことになる。

サンプル

//@version=4
isHour     = hour == 8
isMinute   = minute == 45
    
if(isHour and isMinute)
    line.new(bar_index, low - tr, bar_index, high + tr, xloc.bar_index, extend.both,
             color=color.silver, style=line.style_dotted, width=1) 

毎8時45分に垂直ラインを引く場合のサンプル

参考:Session break 225

構文

line.new(x1, y1, x2, y2, xloc, extend, color, style, width)

戻り値

ラインIDオブジェクト。

引数

x1 (series)

ラインの「起点」のX座標。xlocの指定により記載方法が異なる。

  • 「xloc = xloc.bar_index」の場合は、バーインデックス
  • 「xloc = xloc.bar_time」の場合は、UNIXタイム

y1 (series)

ラインの「起点」のY座標。数値(価格)で指定する。

x2 (series)

ラインの「終点」のX座標。xlocの指定により記載方法が異なる。

  • 「xloc = xloc.bar_index」の場合は、バーインデックス
  • 「xloc = xloc.bar_time」の場合は、UNIXタイム

y2 (series)

ラインの「終点」のY座標。数値(価格)で指定する。

y2 (series)

ラインの「終点」のY座標。数値(価格)で指定する。

xloc (string)

X座標の指定をどのように行うか。デフォルトはxloc.bar_index

  • xloc.bar_index
  • xloc.bar_time

extend (string)

起点から終点までのラインを延長するかどうか。

  • extend.none
  • extend.both
  • extend.left
  • extendright

color (color)

ラインの色の指定。

style (string)

描写されるラインのスタイル。設定可能なのは以下の6種。それぞれの見た目は、インジケーターの設定 ➡ スタイルで確認できる。

  • line.style_solid
  • line.style_dotted
  • line.style_dashed
  • line.style_arrow_left
  • line.style_arrow_right
  • line.style_arrow_both

width (integer)

プロットされるラインの幅。デフォルトは1。

ブログ記事


PAGE TOP