見出し画像

Pine Script™ (v6) の覚書 - 作ってみる: StochasticsとRSIを描くインジケータの作成 (2)

前回までの話


必要なパーツの作成

線の右端にラベルを付与する関数の定義

mylabel(float series,string label_text,color label_color=color.blue,color text_color=color.white,size=8)=>
    var l=label.new(na,na,label_text,style=label.style_label_left,color=label_color,textcolor=text_color,size=size)
    if barstate.islast
        l.set_xy(bar_index,series)

線の右端に表示するため、珍しくxloc.bar_indexを使用する。
最新バーを処理する際に、最新の座標に更新する。

変数の定義

stochastics関連の変数を定義

まずは期間について、

STOK=input.int( 9, "%K期間", group="stochastics")
STOD=input.int( 3, "%D期間", group="stochastics")
STOSD=input.int( 3, "%SD期間", group="stochastics")

これを利用してstochasticsの各値を取得する。

k=ta.stoch(close,high,low,STOK)
d=ta.sma(k,STOD)
sd=ta.sma(d,STOSD)

次に、plotとlabelのための色や線の太さを定義する。

colorSTOK=input.color(color.new(color.red,40), "%K", group="stochastics", inline="%K")
widthSTOK=input.int(1, "線幅", group="stochastics", inline="%K")
labelSTOK=input.bool(true, "label", group="stochastics", inline="%K")
labelbgSTOK=input.color(color.new(color.red,90), "", group="stochastics", inline="%K")
labeltextSTOK=input.color(color.new(color.red,20), "", group="stochastics", inline="%K")

colorSTOD=input.color(color.new(color.fuchsia,40), "%D", group="stochastics", inline="%D")
widthSTOD=input.int(1, "線幅", group="stochastics", inline="%D")
labelSTOD=input.bool(true, "label", group="stochastics", inline="%D")
labelbgSTOD=input.color(color.new(color.fuchsia,90), "", group="stochastics", inline="%D")
labeltextSTOD=input.color(color.new(color.fuchsia,20), "", group="stochastics", inline="%D")

colorSTOSD=input.color(color.new(color.aqua,40), "slow%D", group="stochastics", inline="slow%D")
widthSTOSD=input.int(1, "線幅", group="stochastics", inline="slow%D")
labelSTOSD=input.bool(true, "label", group="stochastics", inline="slow%D")
labelbgSTOSD=input.color(color.new(color.aqua,90), "", group="stochastics", inline="slow%D")
labeltextSTOSD=input.color(color.new(color.aqua,20), "", group="stochastics", inline="slow%D")

RSI関連の変数を定義

まずは期間について、

RSIS=input.int( 7, "RSI(短)", group="RSI")
RSIM=input.int( 14, "RSI(中)", group="RSI")

これを利用してRSI値を取得する。

rsis=ta.rsi(close,RSIS)
rsim=ta.rsi(close,RSIM)

次に、plotとlabelのための色や線の太さを定義する。

colorRSIS=input.color(color.new(color.orange,40), "RSI(短)", group="RSI", inline="RSIS")
widthRSIS=input.int(2, "線幅", group="RSI", inline="RSIS")
labelRSIS=input.bool(true, "label", group="RSI", inline="RSIS")
labelbgRSIS=input.color(color.new(color.orange,90), "", group="RSI", inline="RSIS")
labeltextRSIS=input.color(color.new(color.orange,20), "", group="RSI", inline="RSIS")

colorRSIM=input.color(color.new(color.yellow,40), "RSI(中)", group="RSI", inline="RSIM")
widthRSIM=input.int(2, "線幅", group="RSI", inline="RSIM")
labelRSIM=input.bool(true, "label", group="RSI", inline="RSIM")
labelbgRSIM=input.color(color.new(color.yellow,90), "", group="RSI", inline="RSIM")
labeltextRSIM=input.color(color.new(color.yellow,20), "", group="RSI", inline="RSIM")

続く


いいなと思ったら応援しよう!

rca
よろしければ応援お願いします!