ボックス描画機能

はじめに #

PineScriptにボックス描画機能が追加されました。
この機能ではチャート上に長方形を簡単に書くことができます。 サンプルを踏まえて、PineScriptでの使い方を見ていきます。

サンプル #

//@version=4
study("Box Example", overlay=true)
c_green = color.rgb(33, 150, 243, 80)
ll = lowest(10)
hh = highest(10)
b1 = box(na)
if barstate.islast
    b1 := box.new(bar_index[9], hh, bar_index, ll,
     bgcolor=c_green, border_style=line.style_dashed)
    box.delete(b1[1])
  • //@version=4
    バージョン4のPineScriptを使用しています。
  • study("Box Example", overlay=true)
    Box Exampleという名前でインジケータを作成します。
    overlay=trueでチャートを重ねて表示します。
  • c_green = color.rgb(33, 150, 243, 80)
    color.rgb(red, green, blue, transp)の文法で色を定義します。
    各色は0~255,transpは0(不透明)~100(不可視)です。
  • ll = lowest(10)
    lowestは指定された過去バーの範囲での最安値を意味します。 この場合は過去10本のバーの中での最安値のことです。
  • hh = highest(10)
    lowestと逆で過去10本のバーの中で最高値を意味します。
  • b1 = box(na)
    ifが別のスコープを作成するので、再代入する元になるb1変数を先に空で定義しておきます。
  • if barstate.islast barstate.islastは現在のバーがバーセットの最後のバーの場合はtrueを返し、そうでない場合はfalseを返します。
  • b1 := box.new(bar_index[9], hh, bar_index, ll, bgcolor=c_green, border_style=line.style_dashed)
    b1に値を再代入します。(=は代入で、:=は再代入を表します)
    box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor)で長方形を描画します。
  • box.delete(b1[1])
    box.delete(id)で指定されたボックスを削除します。

このスクリプトを描画すると以下のようになります。
新しい描画 — ボックス

参考 #

© - 2021 - TradingViewの教科書