どんな記事
TradingView(トレーディングビュー)の Pineスクリプトでつくる「Study(インジケーター)」のよく使う組み合わせをまとめてみました(主に自分用)。どれもコピペで機能をつけ加えることができる簡単なものです。
今後も、新たに見つけたり思いついたものがあれば、ここに加えていく予定です!
Twitterでも紹介していただいています
追記
2021年11月13日 更新
「配列を使う」を追加し、いくつかの簡単なサンプルを削除しました。
2020年6月18日 更新
「timezoneと夏時間の認識」の最適化を行いました。
2019年8月17日 追記
timezone
label
line
に関するコードを追加しました。その他、version4の公開に伴い加筆修正を行いました。
2019年6月8日 追記
「VWAPの累積平均を算出」を追加しました。
2019年5月4日 更新・追記
「チャート以外の価格データを取得」のコードを最新のものに更新、「Quandlから金融データを取得」を追加しました。
Security()
でメインチャート以外の価格データを取得
別の銘柄のデータ
security()
で、チャート以外の銘柄のデータを取得できる。security("usdjpy" ,"D" ,close)
のclose
を、ema(close ,20)
などと指定することもできる。Security()
を複数記述すると、すべて取りにいってしまうのか重くなる。要注意。
以下のコードは、メインチャートの価格を指定した通貨で為替換算するもの。
currency = input("None" ,title="為替換算" ,options=["None" ,"USD" ,"EUR" ,"GBP" ,"AUD" ,"CAD" ,"CHF"])
get_root(currency) =>
currency=="USD" ? "usdjpy" :
currency=="EUR" ? "eurjpy" :
currency=="GBP" ? "gbpjpy" :
currency=="AUD" ? "audjpy" :
currency=="CAD" ? "cadjpy" :
currency=="CHF" ? "chfjpy" :
"usdjpy"
sc1(currency ,root) =>
currency=="None" ? 1 :
security(root ,"D" ,close)
root = get_root(currency)
value = close * sc1(currency ,root)
※ 銘柄コード「4005」など、複数の取引所で同じコードが使われている場合、「TSE:4005」のように取引所コードで渡さないと取得することができない。組込み変数なら、ticker
ではなくtickerid
を使うこと。
別の時間軸のデータ
メインチャートより上の時間軸の価格を取得することもできる。
//1時間足を取得
Security( syminfo.tickerid ,"60" ,close )
//4時間足を取得
Security( syminfo.tickerid ,"240" ,close )
//日足を取得
Security( syminfo.tickerid ,"D" ,close )
//週足を取得
Security( syminfo.tickerid ,"W" ,close )
//月足を取得
Security( syminfo.tickerid ,"M" ,close )
日足の正確な四本値
OSE:NK225
の金~月曜日にかけてなど、ごく稀にSecurity()
で取得する価格データがズレることがある。正確な日足などの四本値が欲しい場合は、以下のように対応する。
//@version=4
sessionStart = input( "Morning" ,options=[ "Night" ,"Morning" ] )
is_nkx = syminfo.root=="NK225" or syminfo.root=="NK225M"
morning_open = hour[1] == 05 and hour == 08 and minute >= 30
night_open = hour[1] == 15 and hour == 16 and minute >= 30
is_morning_open = sessionStart=="Morning" and morning_open
is_night_open = sessionStart=="Night" and night_open
is_open = is_nkx and ( is_morning_open or is_night_open )
var float dayOpen = na
dayOpen := is_open ? open : dayOpen[1]
直線を引く
na
で間を空けて
//@version=3
isRegularFractal(mode) =>
ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] : mode == -1 ? low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] : false
topFractal = isRegularFractal(1) ? high[2] : isRegularFractal(-1) ? low[2] : na
plot(topFractal ,color=red ,offset=-2)
na
が入ると、有効なデータの点と点を直線でつないでくれる。
上昇幅を算出して
//@version=3
shortl = input(10)
longl = input(100)
offset_f = input(2)
offset_b = input(20)
// タイムラインを作成しておく
timeline = 0
timeline:= nz(timeline[1]) + 1
// ボトムを探す
a = valuewhen(low==lowest(low ,shortl) ,low ,0)
b = valuewhen(low==lowest(low ,longl) ,low ,0)
whena = valuewhen(low==lowest(low ,shortl) ,timeline ,0)
whenb = valuewhen(low==lowest(low ,longl) ,timeline ,0)
m = (b-a) / (whenb-whena)
bot_price = m * (timeline-whena) + a
back_bot_price = m * (timeline-whena-offset_b) + a
forward_bot_price = m * (timeline-whena+offset_f) + a
bot_price := b-a==0 ? nz(bot_price[1]) : bot_price
same_bot = a==a[1] and b==b[1] and a!=0 and b!=0 and whena!=whenb
plot(same_top ? top_price : na ,style=linebr ,color=red ,linewidth=2 ,offset= 0 ,transp=50 ,title="_top")
plot(same_top ? back_top_price : na ,style=linebr ,color=red ,linewidth=1 ,offset=-offset_b ,transp=50 ,title="back_top")
plot(same_top ? forward_top_price : na ,style=linebr ,color=red ,linewidth=1 ,offset= offset_f ,transp=70 ,title="forward_top")
タイムラインと上昇幅を算出して、力技で直線を引く。
line.new()
を使って
圧倒的に使いやすい。
bar_index
で位置を指定する。以下のコードは、4本過去にタテ線を描画するもの。
※ bar_index
で将来を指定することはできない
//@version=4
var line vl01 = na
line.delete( vl01 )
vl01 := line.new( bar_index[4] ,high+tr ,bar_index[4] ,low-tr )
time
で位置を指定する
※ 将来を指定することはできるが、ズレる場合がある
//@version=4
showHL = input( true ,title="当日クローズまでの ヨコ線 を描画 (30分足以下)")
showVL = input( true ,title="当日クローズまでの タテ線 の描画 (30分足以下)" )
is_intraday_smaller30 = timeframe.isintraday and timeframe.multiplier <= 30
b4high5 = security( syminfo.tickerid ,"D" ,highest( high ,5 )[1] ,lookahead=barmerge.lookahead_on )
b4low5 = security( syminfo.tickerid ,"D" ,lowest( low ,5 )[1] ,lookahead=barmerge.lookahead_on )
b4mid5 = ( b4high5 + b4low5 ) / 2
is_nan = b4atr[1]!=b4atr
var start = time
var end = time
if is_nan and is_intraday_smaller30
start := timestamp( year,month,dayofmonth,hour,minute )
end := timestamp( year,month, dayofmonth + 1 ,hour,minute )
var line ln_high5 = na
var line ln_mid5 = na
var line ln_low5 = na
var line ln_01 = na
var line ln_02 = na
if showHL
line.delete( ln_high5 )
line.delete( ln_mid5 )
line.delete( ln_low5 )
ln_high5 := line.new( start ,b4high5 ,end ,b4high5 ,xloc.bar_time )
ln_mid5 := line.new( start ,b4mid5 ,end ,b4mid5 ,xloc.bar_time )
ln_low5 := line.new( start ,b4low5 ,end ,b4low5 ,xloc.bar_time )
if showVL
line.delete( ln_01 )
line.delete( ln_02 )
ln_01 := line.new( start ,b4high5 ,end ,b4low5 ,xloc.bar_time )
ln_02 := line.new( start ,b4high5 ,end ,b4low5 ,xloc.bar_time )
TradingViewの時間軸のクセに注意
- TradingViewの時間軸には以下の特徴がある
- 過去のセッション時間外は表示されない
- 未来の時間外は表示される(24時間すべて表示されている)
- セッションが始まるタイミングで時間外の目盛りが削除される
- timeでラインを詳細に描画
- そのまま③で省略されるとズレる
- ローソク足とラインの間隔が優先される(時間ではない)
- 省略された分、未来に描画されたことになる
指標発表の時刻にタテ線を引くようなコードを作成した場合、大変不便な思いをする。(「F5」で更新すれば良いだけなのだが)
文字を出力する
plotshape()
を使って
version3まではこれしかできなかった。textの内容をtostring()
で動的に変えるようなことはできない。
//@version=4
data = close >= open
plotshape( data ,text="UP" ,textcolor=color.black ,style=shape.labeldown )
label.new()
を使って
bar_index
で位置を指定する。
//@version=4
label.new( bar_index ,high ,"x="+tostring(bar_index)+"\ny="+tostring(high) ,style=label.style_none )
time
で位置を指定する。
//@version=4
dt = time - time[1]
var label xy = na
label.delete( xy )
xy := label.new( time+3 * dt ,hlc3 ,"x="+tostring(bar_index)+"\ny="+tostring(high) ,xloc.bar_time ,style=label.style_none )
配列を使う
全期間の統計
取得している全データの、実体と窓の「平均」「標準偏差」(いずれも対数の差分)を算出。
//@version=5
stdev_multiplier = 2
body = math.log(close) - math.log(open)
body_abs = math.abs(body)
var array_body = array.new_float(0)
array.push(array_body, body_abs)
body_mean = array.avg(array_body)
body_stdev = array.stdev(array_body)
gap = math.log(open) - math.log(close[1])
gap_abs = math.abs(gap)
var array_gap = array.new_float(0)
if gap > 0
array.push(array_gap, gap_abs)
gap_mean = array.avg(array_gap)
gap_stdev = array.stdev(array_gap)
plot( body_abs, "body", color=color.red )
plot( body_mean + body_stdev * stdev_multiplier ,"body mean + stdev", color=color.red )
plot( gap_abs, "gap" )
plot( gap_mean + gap_stdev * stdev_multiplier ,"gap mena + stdev" )
相関係数一覧表
配列が使える範囲に制限があり、どうしても長いコードになってしまう。あと、計算に時間が掛かる。
//@version=5
indicator( '相関係数一覧表', precision=2, overlay=true )
s1 = input.symbol( '', inline='s1' )
s2 = input.symbol( '', inline='s2' )
s3 = input.symbol( '', inline='s3' )
s4 = input.symbol( '', inline='s4' )
s5 = input.symbol( '', inline='s5' )
s6 = input.symbol( '', inline='s6' )
s7 = input.symbol( '', inline='s7' )
s8 = input.symbol( '', inline='s8' )
s9 = input.symbol( '', inline='s9' )
s10 = input.symbol( '', inline='s10' )
timeframe = input.timeframe( 'D', '時間軸', inline="算出の条件", group="算出の条件" )
len = input( 1000, inline="算出の条件", group="算出の条件" )
threshold_high = input( .8, "強", inline="強い相関", group="相関表の設定" )
color_high_p = input.color( color.red, "順", inline="強い相関", group="相関表の設定" )
color_high_m = input.color( color.red, "逆", inline="強い相関", group="相関表の設定" )
threshold_mid = input( .6, "中", inline="中程度の相関", group="相関表の設定" )
color_mid_p = input( color.yellow, "順", inline="中程度の相関", group="相関表の設定" )
color_mid_m = input( color.yellow, "逆", inline="中程度の相関", group="相関表の設定" )
color_low = input( color.new( #eeeeee, 0 ), "弱", inline="弱い相関", group="相関表の設定" )
color_same = input( color.black, "同じ銘柄", inline="弱い相関", group="相関表の設定" )
color_base = input( color.white, "背景", inline="色", group="相関表の設定" )
color_text = input( color.black, "テキスト", inline="色", group="相関表の設定" )
num = 10
get_color( x ) => x > .999 ? color_same
: x >= threshold_high ? color_high_p
: x >= threshold_mid ? color_mid_p
: x <= -threshold_high ? color_high_m
: x <= -threshold_mid ? color_mid_m
: color_low
close_s1 = s1=='' ? na : request.security( s1, timeframe, close )
close_s2 = s2=='' ? na : request.security( s2, timeframe, close )
close_s3 = s3=='' ? na : request.security( s3, timeframe, close )
close_s4 = s4=='' ? na : request.security( s4, timeframe, close )
close_s5 = s5=='' ? na : request.security( s5, timeframe, close )
close_s6 = s6=='' ? na : request.security( s6, timeframe, close )
close_s7 = s7=='' ? na : request.security( s7, timeframe, close )
close_s8 = s8=='' ? na : request.security( s8, timeframe, close )
close_s9 = s9=='' ? na : request.security( s9, timeframe, close )
close_s10 = s10=='' ? na : request.security( s10, timeframe, close )
var arr_correl_s1 = array.new_float( num, na )
var arr_correl_s2 = array.new_float( num, na )
var arr_correl_s3 = array.new_float( num, na )
var arr_correl_s4 = array.new_float( num, na )
var arr_correl_s5 = array.new_float( num, na )
var arr_correl_s6 = array.new_float( num, na )
var arr_correl_s7 = array.new_float( num, na )
var arr_correl_s8 = array.new_float( num, na )
var arr_correl_s9 = array.new_float( num, na )
var arr_correl_s10 = array.new_float( num, na )
array.set( arr_correl_s1, 0, math.round( ta.correlation( close_s1, close_s1, len ), 2 ) )
array.set( arr_correl_s1, 1, math.round( ta.correlation( close_s1, close_s2, len ), 2 ) )
array.set( arr_correl_s1, 2, math.round( ta.correlation( close_s1, close_s3, len ), 2 ) )
array.set( arr_correl_s1, 3, math.round( ta.correlation( close_s1, close_s4, len ), 2 ) )
array.set( arr_correl_s1, 4, math.round( ta.correlation( close_s1, close_s5, len ), 2 ) )
array.set( arr_correl_s1, 5, math.round( ta.correlation( close_s1, close_s6, len ), 2 ) )
array.set( arr_correl_s1, 6, math.round( ta.correlation( close_s1, close_s7, len ), 2 ) )
array.set( arr_correl_s1, 7, math.round( ta.correlation( close_s1, close_s8, len ), 2 ) )
array.set( arr_correl_s1, 8, math.round( ta.correlation( close_s1, close_s9, len ), 2 ) )
array.set( arr_correl_s1, 9, math.round( ta.correlation( close_s1, close_s10, len ), 2 ) )
array.set( arr_correl_s2, 0, math.round( ta.correlation( close_s2, close_s1, len ), 2 ) )
array.set( arr_correl_s2, 1, math.round( ta.correlation( close_s2, close_s2, len ), 2 ) )
array.set( arr_correl_s2, 2, math.round( ta.correlation( close_s2, close_s3, len ), 2 ) )
array.set( arr_correl_s2, 3, math.round( ta.correlation( close_s2, close_s4, len ), 2 ) )
array.set( arr_correl_s2, 4, math.round( ta.correlation( close_s2, close_s5, len ), 2 ) )
array.set( arr_correl_s2, 5, math.round( ta.correlation( close_s2, close_s6, len ), 2 ) )
array.set( arr_correl_s2, 6, math.round( ta.correlation( close_s2, close_s7, len ), 2 ) )
array.set( arr_correl_s2, 7, math.round( ta.correlation( close_s2, close_s8, len ), 2 ) )
array.set( arr_correl_s2, 8, math.round( ta.correlation( close_s2, close_s9, len ), 2 ) )
array.set( arr_correl_s2, 9, math.round( ta.correlation( close_s2, close_s10, len ), 2 ) )
array.set( arr_correl_s3, 0, math.round( ta.correlation( close_s3, close_s1, len ), 2 ) )
array.set( arr_correl_s3, 1, math.round( ta.correlation( close_s3, close_s2, len ), 2 ) )
array.set( arr_correl_s3, 2, math.round( ta.correlation( close_s3, close_s3, len ), 2 ) )
array.set( arr_correl_s3, 3, math.round( ta.correlation( close_s3, close_s4, len ), 2 ) )
array.set( arr_correl_s3, 4, math.round( ta.correlation( close_s3, close_s5, len ), 2 ) )
array.set( arr_correl_s3, 5, math.round( ta.correlation( close_s3, close_s6, len ), 2 ) )
array.set( arr_correl_s3, 6, math.round( ta.correlation( close_s3, close_s7, len ), 2 ) )
array.set( arr_correl_s3, 7, math.round( ta.correlation( close_s3, close_s8, len ), 2 ) )
array.set( arr_correl_s3, 8, math.round( ta.correlation( close_s3, close_s9, len ), 2 ) )
array.set( arr_correl_s3, 9, math.round( ta.correlation( close_s3, close_s10, len ), 2 ) )
array.set( arr_correl_s4, 0, math.round( ta.correlation( close_s4, close_s1, len ), 2 ) )
array.set( arr_correl_s4, 1, math.round( ta.correlation( close_s4, close_s2, len ), 2 ) )
array.set( arr_correl_s4, 2, math.round( ta.correlation( close_s4, close_s3, len ), 2 ) )
array.set( arr_correl_s4, 3, math.round( ta.correlation( close_s4, close_s4, len ), 2 ) )
array.set( arr_correl_s4, 4, math.round( ta.correlation( close_s4, close_s5, len ), 2 ) )
array.set( arr_correl_s4, 5, math.round( ta.correlation( close_s4, close_s6, len ), 2 ) )
array.set( arr_correl_s4, 6, math.round( ta.correlation( close_s4, close_s7, len ), 2 ) )
array.set( arr_correl_s4, 7, math.round( ta.correlation( close_s4, close_s8, len ), 2 ) )
array.set( arr_correl_s4, 8, math.round( ta.correlation( close_s4, close_s9, len ), 2 ) )
array.set( arr_correl_s4, 9, math.round( ta.correlation( close_s4, close_s10, len ), 2 ) )
array.set( arr_correl_s5, 0, math.round( ta.correlation( close_s5, close_s1, len ), 2 ) )
array.set( arr_correl_s5, 1, math.round( ta.correlation( close_s5, close_s2, len ), 2 ) )
array.set( arr_correl_s5, 2, math.round( ta.correlation( close_s5, close_s3, len ), 2 ) )
array.set( arr_correl_s5, 3, math.round( ta.correlation( close_s5, close_s4, len ), 2 ) )
array.set( arr_correl_s5, 4, math.round( ta.correlation( close_s5, close_s5, len ), 2 ) )
array.set( arr_correl_s5, 5, math.round( ta.correlation( close_s5, close_s6, len ), 2 ) )
array.set( arr_correl_s5, 6, math.round( ta.correlation( close_s5, close_s7, len ), 2 ) )
array.set( arr_correl_s5, 7, math.round( ta.correlation( close_s5, close_s8, len ), 2 ) )
array.set( arr_correl_s5, 8, math.round( ta.correlation( close_s5, close_s9, len ), 2 ) )
array.set( arr_correl_s5, 9, math.round( ta.correlation( close_s5, close_s10, len ), 2 ) )
array.set( arr_correl_s6, 0, math.round( ta.correlation( close_s6, close_s1, len ), 2 ) )
array.set( arr_correl_s6, 1, math.round( ta.correlation( close_s6, close_s2, len ), 2 ) )
array.set( arr_correl_s6, 2, math.round( ta.correlation( close_s6, close_s3, len ), 2 ) )
array.set( arr_correl_s6, 3, math.round( ta.correlation( close_s6, close_s4, len ), 2 ) )
array.set( arr_correl_s6, 4, math.round( ta.correlation( close_s6, close_s5, len ), 2 ) )
array.set( arr_correl_s6, 5, math.round( ta.correlation( close_s6, close_s6, len ), 2 ) )
array.set( arr_correl_s6, 6, math.round( ta.correlation( close_s6, close_s7, len ), 2 ) )
array.set( arr_correl_s6, 7, math.round( ta.correlation( close_s6, close_s8, len ), 2 ) )
array.set( arr_correl_s6, 8, math.round( ta.correlation( close_s6, close_s9, len ), 2 ) )
array.set( arr_correl_s6, 9, math.round( ta.correlation( close_s6, close_s10, len ), 2 ) )
array.set( arr_correl_s7, 0, math.round( ta.correlation( close_s7, close_s1, len ), 2 ) )
array.set( arr_correl_s7, 1, math.round( ta.correlation( close_s7, close_s2, len ), 2 ) )
array.set( arr_correl_s7, 2, math.round( ta.correlation( close_s7, close_s3, len ), 2 ) )
array.set( arr_correl_s7, 3, math.round( ta.correlation( close_s7, close_s4, len ), 2 ) )
array.set( arr_correl_s7, 4, math.round( ta.correlation( close_s7, close_s5, len ), 2 ) )
array.set( arr_correl_s7, 5, math.round( ta.correlation( close_s7, close_s6, len ), 2 ) )
array.set( arr_correl_s7, 6, math.round( ta.correlation( close_s7, close_s7, len ), 2 ) )
array.set( arr_correl_s7, 7, math.round( ta.correlation( close_s7, close_s8, len ), 2 ) )
array.set( arr_correl_s7, 8, math.round( ta.correlation( close_s7, close_s9, len ), 2 ) )
array.set( arr_correl_s7, 9, math.round( ta.correlation( close_s7, close_s10, len ), 2 ) )
array.set( arr_correl_s8, 0, math.round( ta.correlation( close_s8, close_s1, len ), 2 ) )
array.set( arr_correl_s8, 1, math.round( ta.correlation( close_s8, close_s2, len ), 2 ) )
array.set( arr_correl_s8, 2, math.round( ta.correlation( close_s8, close_s3, len ), 2 ) )
array.set( arr_correl_s8, 3, math.round( ta.correlation( close_s8, close_s4, len ), 2 ) )
array.set( arr_correl_s8, 4, math.round( ta.correlation( close_s8, close_s5, len ), 2 ) )
array.set( arr_correl_s8, 5, math.round( ta.correlation( close_s8, close_s6, len ), 2 ) )
array.set( arr_correl_s8, 6, math.round( ta.correlation( close_s8, close_s7, len ), 2 ) )
array.set( arr_correl_s8, 7, math.round( ta.correlation( close_s8, close_s8, len ), 2 ) )
array.set( arr_correl_s8, 8, math.round( ta.correlation( close_s8, close_s9, len ), 2 ) )
array.set( arr_correl_s8, 9, math.round( ta.correlation( close_s8, close_s10, len ), 2 ) )
array.set( arr_correl_s9, 0, math.round( ta.correlation( close_s9, close_s1, len ), 2 ) )
array.set( arr_correl_s9, 1, math.round( ta.correlation( close_s9, close_s2, len ), 2 ) )
array.set( arr_correl_s9, 2, math.round( ta.correlation( close_s9, close_s3, len ), 2 ) )
array.set( arr_correl_s9, 3, math.round( ta.correlation( close_s9, close_s4, len ), 2 ) )
array.set( arr_correl_s9, 4, math.round( ta.correlation( close_s9, close_s5, len ), 2 ) )
array.set( arr_correl_s9, 5, math.round( ta.correlation( close_s9, close_s6, len ), 2 ) )
array.set( arr_correl_s9, 6, math.round( ta.correlation( close_s9, close_s7, len ), 2 ) )
array.set( arr_correl_s9, 7, math.round( ta.correlation( close_s9, close_s8, len ), 2 ) )
array.set( arr_correl_s9, 8, math.round( ta.correlation( close_s9, close_s9, len ), 2 ) )
array.set( arr_correl_s9, 9, math.round( ta.correlation( close_s9, close_s10, len ), 2 ) )
array.set( arr_correl_s10, 0, math.round( ta.correlation( close_s10, close_s1, len ), 2 ) )
array.set( arr_correl_s10, 1, math.round( ta.correlation( close_s10, close_s2, len ), 2 ) )
array.set( arr_correl_s10, 2, math.round( ta.correlation( close_s10, close_s3, len ), 2 ) )
array.set( arr_correl_s10, 3, math.round( ta.correlation( close_s10, close_s4, len ), 2 ) )
array.set( arr_correl_s10, 4, math.round( ta.correlation( close_s10, close_s5, len ), 2 ) )
array.set( arr_correl_s10, 5, math.round( ta.correlation( close_s10, close_s6, len ), 2 ) )
array.set( arr_correl_s10, 6, math.round( ta.correlation( close_s10, close_s7, len ), 2 ) )
array.set( arr_correl_s10, 7, math.round( ta.correlation( close_s10, close_s8, len ), 2 ) )
array.set( arr_correl_s10, 8, math.round( ta.correlation( close_s10, close_s9, len ), 2 ) )
array.set( arr_correl_s10, 9, math.round( ta.correlation( close_s10, close_s10, len ), 2 ) )
if barstate.islast
var table_correl = table.new( position.bottom_left, num+2, num+1 )
table.cell( table_correl, 0, 0, "", bgcolor=color_base, text_color=color_text )
table.cell( table_correl, 1, 0, "Symbol", bgcolor=color_base, text_color=color_text )
for i=1 to num
symbol_i = i==1 ? s1 : i==2 ? s2 : i==3 ? s3 : i==4 ? s4 : i==5 ? s5 : i==6 ? s6 : i==7 ? s7 : i==8 ? s8 : i==9 ? s9 : s10
if symbol_i != ''
table.cell( table_correl, i+1, 0, str.tostring( i ), bgcolor=color_base, text_color=color_text )
for i=1 to num
symbol_i = i==1 ? s1 : i==2 ? s2 : i==3 ? s3 : i==4 ? s4 : i==5 ? s5 : i==6 ? s6 : i==7 ? s7 : i==8 ? s8 : i==9 ? s9 : s10
if symbol_i != ''
correl_1_i = array.get( arr_correl_s1, i-1 )
correl_2_i = array.get( arr_correl_s2, i-1 )
correl_3_i = array.get( arr_correl_s3, i-1 )
correl_4_i = array.get( arr_correl_s4, i-1 )
correl_5_i = array.get( arr_correl_s5, i-1 )
correl_6_i = array.get( arr_correl_s6, i-1 )
correl_7_i = array.get( arr_correl_s7, i-1 )
correl_8_i = array.get( arr_correl_s8, i-1 )
correl_9_i = array.get( arr_correl_s9, i-1 )
correl_10_i = array.get( arr_correl_s10, i-1 )
table.cell( table_correl, 0, i, str.tostring( i ), bgcolor=color_base, text_color=color_text )
table.cell( table_correl, 1, i, symbol_i, bgcolor=color_base, text_color=color_text )
if s1 != ''
table.cell( table_correl, 2, i, str.tostring( correl_1_i ), bgcolor=get_color( correl_1_i ), text_color=color_text )
if s2 != ''
table.cell( table_correl, 3, i, str.tostring( correl_2_i ), bgcolor=get_color( correl_2_i ), text_color=color_text )
if s3 != ''
table.cell( table_correl, 4, i, str.tostring( correl_3_i ), bgcolor=get_color( correl_3_i ), text_color=color_text )
if s4 != ''
table.cell( table_correl, 5, i, str.tostring( correl_4_i ), bgcolor=get_color( correl_4_i ), text_color=color_text )
if s5 != ''
table.cell( table_correl, 6, i, str.tostring( correl_5_i ), bgcolor=get_color( correl_5_i ), text_color=color_text )
if s6 != ''
table.cell( table_correl, 7, i, str.tostring( correl_6_i ), bgcolor=get_color( correl_6_i ), text_color=color_text )
if s7 != ''
table.cell( table_correl, 8, i, str.tostring( correl_7_i ), bgcolor=get_color( correl_7_i ), text_color=color_text )
if s8 != ''
table.cell( table_correl, 9, i, str.tostring( correl_8_i ), bgcolor=get_color( correl_8_i ), text_color=color_text )
if s9 != ''
table.cell( table_correl, 10, i, str.tostring( correl_9_i ), bgcolor=get_color( correl_9_i ), text_color=color_text )
if s10 != ''
table.cell( table_correl, 11, i, str.tostring( correl_10_i ), bgcolor=get_color( correl_10_i ), text_color=color_text )
複数のシグナルを表示
//@version=3
a = ema(close ,5)
b = ema(close ,25)
c = ema(close ,50)
sig1 = cross(a ,b)
sig2 = cross(a ,c)
sig3 = cross(b ,c)
p1 = plot(4 ,color=black ,editable=false ,trackprice=false)
p2 = plot(3 ,color=black ,editable=false ,trackprice=false)
p3 = plot(2 ,color=black ,editable=false ,trackprice=false)
p4 = plot(1 ,color=black ,editable=false ,trackprice=false)
fill(p1 ,p2 ,color = sig1 ? red : gray ,title="sig1" ,transp=50)
fill(p2 ,p3 ,color = sig2 ? red : gray ,title="sig2" ,transp=50)
fill(p3 ,p4 ,color = sig3 ? red : gray ,title="sig3" ,transp=50)
直近のデータだけ描画
plotshape(close, show_last=7)
他にも、plot
plotbar
plotchar
fill
などでもshow_last
を使うことができる。
前々回の安値・高値更新を元にしたトレイリングストップ
//@version=3
vw_low = valuewhen(low > low[1] ,low[1] ,1)
vw_high = valuewhen(high < high[1] ,high[1] ,1)
low_active = close > vw_low
high_active = close < vw_high
p1 = plot(low_active ? vw_low : na ,linewidth=1 ,color=purple ,style=linebr ,title="前々回の安値更新")
p2 = plot(high_active ? vw_high : na ,linewidth=1 ,color=purple ,style=linebr ,title="前々回の高値更新")
当然だが、有効なときとそうでないときがある。
数秘を算出
「Astrology(占星)が有効なら、Numerology(数秘)も有効なんじゃないか」と、ちょっと気になって作成してみたコード。実用性はあまりなさそう。サクッと試せるのはTradingViewの良いところ。
calc_n(target) =>
n4 = target >= 2000 ? 2 : target >= 1000 ? 1 : 0
n3_ = target - n4*1000
n3 = n3_ >= 900 ? 9 : n3_ >= 800 ? 8 : n3_ >= 700 ? 7 : n3_ >= 600 ? 6 : n3_ >= 500 ? 5 : n3_ >= 400 ? 4 : n3_ >= 300 ? 3 : n3_ >= 200 ? 2 : n3_ >= 100 ? 1 : 0
n2_ = n3_ - n3*100
n2 = n2_ >= 90 ? 9 : n2_ >= 80 ? 8 : n2_ >= 70 ? 7 : n2_ >= 60 ? 6 : n2_ >= 50 ? 5 : n2_ >= 40 ? 4 : n2_ >= 30 ? 3 : n2_ >= 20 ? 2 : n2_ >= 10 ? 1 : 0
n1 = n2_ - n2*10
[n4 ,n3 ,n2 ,n1]
[y4 ,y3 ,y2 ,y1] = calc_n(year)
[_ ,_ ,m2 ,m1] = calc_n(month)
[_ ,_ ,d2 ,d1] = calc_n(dayofmonth)
num__ = y4 + y3 + y2 + y1 + m2 + m1 + d2 + d1
[_ ,_ ,n2_ ,n1_] = calc_n(num__)
num_ = n2_ + n1_
[_ ,_ ,n2 ,n1] = calc_n(num_)
num = n2 + n1
変化率の対数を算出
roc()
が変化率。1%を、0.01
ではなく1
と返すため、100で割っている。log()
は対数を返す。これを必要なだけ足していくと Ku-Chart ができあがる。
calc_log(target) => nz( log( 1 + roc(target ,1) / 100 ))
強弱の順位を算出
同程度の数値があって順位が欲しい場合に使う。
target1 = __YOUR_PROGRAM__
target2 = __YOUR_PROGRAM__
target3 = __YOUR_PROGRAM__
target4 = __YOUR_PROGRAM__
target5 = __YOUR_PROGRAM__
target6 = __YOUR_PROGRAM__
target7 = __YOUR_PROGRAM__
target8 = __YOUR_PROGRAM__
rank(target) =>
_1 = target > target1 ? 0 : 1
_2 = target > target2 ? 0 : 1
_3 = target > target3 ? 0 : 1
_4 = target > target4 ? 0 : 1
_5 = target > target5 ? 0 : 1
_6 = target > target6 ? 0 : 1
_7 = target > target7 ? 0 : 1
_8 = target > target8 ? 0 : 1
_1 + _2 + _3 + _4 + _5 + _6 + _7 + _8
rank1 = rank(target1)
Quandlから金融データを取得
金融データと言えば Quandl。人口やGDPの推移、機関投資家の取引状況等を確認することができます。なんと、TradingView は Quandl からデータを取得することができます。すごい。最近では、quande()
という専用の関数も追加されています。
以下のコードは、CFTCの建玉明細を表示するもの。
//@vertion=3
force_root = input("", title="Override Product")
is_includeoptions = input(false, type=bool, title="Include Options")
fxroot =
ticker == "USDCAD" ? "CD" :
ticker == "USDCAD" ? "CD" :
ticker == "USDCHF" ? "SF" :
ticker == "USDCZK" ? "CZ" :
ticker == "USDHUF" ? "FR" :
ticker == "USDILS" ? "IS" :
ticker == "USDJPY" ? "JY" :
ticker == "USDMXN" ? "MP" :
ticker == "USDNOK" ? "UN" :
ticker == "USDPLN" ? "PZ" :
ticker == "USDRUB" ? "RU" :
ticker == "USDSEK" ? "SE" :
ticker == "USDZAR" ? "RA" :
ticker == "EURUSD" ? "EC" :
ticker == "AUDUSD" ? "AD" :
ticker == "GBPUSD" ? "BP" :
ticker == "NZDUSD" ? "NE" :
ticker == "BRLUSD" ? "BR" :
""
root = force_root == "" ? fxroot == "" ? syminfo.root : fxroot : force_root
code = root + (is_includeoptions ? "_FO" : "_F") + "_L_ALL"
long = security("QUANDL:CFTC/"+code+"|1", "D", close)
short = security("QUANDL:CFTC/"+code+"|2", "D", close)
plot(long, color = red, title="Long" ,style=stepline)
plot(short, color = blue, title="Short" ,style=stepline)
plot(long-short, color = orange, title="Net", style=columns ,transp=50)
VWAPの累積平均を算出
VWAPというのは、「Volume Weighted Average Price(出来高加重平均価格)」のこと。多くの機関投資家が参考にするものらしく、このラインよりも価格が上にあれば、起点とする日より後に買った投資家の損益合計はプラスになるとのこと。VWAP の移動平均はvwma()
という関数が用意されている。
isWork = timestamp( fromY ,fromM ,fromD ,00 ,00 ) <= time
volume_sum = volume
volume_sum := isWork ? isWork[1] != isWork ? volume : volume_sum[1] + volume : 0
vwap_sum = vwap
vwap_sum := isWork ? isWork[1] != isWork ? vwap
: (vwap_sum[1] * volume_sum[1] + vwap * volume) / volume_sum
: na
注意点
起点となる足のvwap
をna
などで削ると正確に計算されない。想像するに、vwap
は組み込み変数のようで、ウラは関数。以下のコードは上手くいかない。
//@version=4
dayOpen = security( syminfo.tickerid ,"D" ,open ,lookahead=barmerge.lookahead_on )
is_open = dayOpen[1]!=dayOpen
plot( is_open ? na : vwap ,color=color.red )
次のようにすると上手くいく。
//@version=4
dayOpen = security( syminfo.tickerid ,"D" ,open ,lookahead=barmerge.lookahead_on )
is_open = dayOpen[1]!=dayOpen
VWAP = vwap
plot( is_open ? na : VWAP ,color=color.blue )
timezoneと夏時間の認識
各国のOpen/Closeや、中値・経済指標等の発表時刻を描画するコードです。夏時間や各取引所の時差を認識し調整します。過去~現在では背景色で表し、当日の変化点に縦線を引きます。
上図では、それぞれ「灰色:日本」「赤:香港」「青:ロンドン」「オレンジ:米国」を表しています。
//@version=4
study( "Sessions" ,overlay=true )
showVL = input( true ,title="縦線 の描画 (30分足以下)" )
showVLBG = input( true ,title="市場ごとの背景色を入れる" )
_colorVL = input( "市場ごと" ,title="縦線 の色" ,options=[ "黒" ,"グレー" ,"白" ,"緑" ,"市場ごと" ] )
_styleVL = input( "破線" ,title="縦線 の形式" ,options=[ "直線" ,"破線" ,"点線" ] )
widthVL = input( 1 ,title="縦線 の太さ (1~3)" ,type=input.integer ,minval=1 ,maxval=3 )
_extendVL = input( true ,title="縦線 を上下に延長する" )
is_intraday = timeframe.isintraday
b4h20 = security( syminfo.tickerid ,"D" ,highest( high ,5 )[1] ,lookahead=barmerge.lookahead_on )
b4l20 = security( syminfo.tickerid ,"D" ,lowest( low ,5 )[1] ,lookahead=barmerge.lookahead_on )
var adjustGMT = syminfo.timezone=="America/New_York" ? -4
: syminfo.timezone=="Asia/Tokyo" ? 9
: syminfo.timezone=="Etc/UTC" ? 0
: syminfo.timezone=="America/Los_Angeles" ? -7
: syminfo.timezone=="America/Chicago" ? -5
: syminfo.timezone=="America/Phoenix" ? -7
: syminfo.timezone=="America/Toronto" ? -4
: syminfo.timezone=="America/Vancouver" ? -7
: syminfo.timezone=="America/Argentina/Buenos_Aires" ? -3
: syminfo.timezone=="America/El_Salvador" ? -6
: syminfo.timezone=="America/Sao_Paulo" ? -3
: syminfo.timezone=="America/Bogota" ? -5
: syminfo.timezone=="Europe/Moscow" ? 3
: syminfo.timezone=="Europe/Athens" ? 3
: syminfo.timezone=="Europe/Berlin" ? 2
: syminfo.timezone=="Europe/London" ? 1
: syminfo.timezone=="Europe/Madrid" ? 2
: syminfo.timezone=="Europe/Paris" ? 2
: syminfo.timezone=="Europe/Warsaw" ? 2
: syminfo.timezone=="Australia/Sydney" ? 10
: syminfo.timezone=="Australia/Brisbane" ? 10
: syminfo.timezone=="Australia/ACT" ? 10
: syminfo.timezone=="Asia/Almaty" ? 6
: syminfo.timezone=="Asia/Ashkhabad" ? 5
: syminfo.timezone=="Asia/Taipei" ? 8
: syminfo.timezone=="Asia/Singapore" ? 8
: syminfo.timezone=="Asia/Shanghai" ? 8
: syminfo.timezone=="Asia/Seoul" ? 9
: syminfo.timezone=="Asia/Dubai" ? 4
: syminfo.timezone=="Asia/Hong_Kong" ? 8
: syminfo.timezone=="Asia/Bangkok" ? 7
: syminfo.timezone=="Pacific/Auckland" ? 12
: syminfo.timezone=="Pacific/Honolulu" ? -10 : 0
var s_ny_st = time
var s_uk_st = time
var e_ny_st = time
var e_uk_st = time
if( month[1]==2 and month==3 )
remainder_s = ( 31 - dayofmonth ) % 7
calc_pointday_s = 31 - remainder_s
target_date_s_uk = 8 - dayofweek <= remainder_s ? calc_pointday_s + ( 8 - dayofweek ) : calc_pointday_s - ( dayofweek - 1 )
s_uk_st := timestamp( "GMT",year,3,target_date_s_uk,1,0 )
target_date_s_ny = dayofweek <= dayofmonth ? dayofmonth - ( dayofweek -1 ) : dayofmonth + ( 8 - dayofweek )
s_ny_st := timestamp( "GMT-4",year,3, target_date_s_ny + 7 ,2,0 )
if( month[1]==9 and month==10 )
remiander_e = ( 31 - dayofmonth ) % 7
calc_pointday_e = 31 - remiander_e
target_date_e_uk = 8 - dayofweek <= remiander_e ? calc_pointday_e + ( 8 - dayofweek ) : calc_pointday_e - ( dayofweek - 1 )
e_uk_st := timestamp( "GMT",year,10,target_date_e_uk,1,0 )
if( month[1]==10 and month==11 )
target_date_e_ny = dayofweek <= dayofmonth ? dayofmonth - ( dayofweek -1 ) : dayofmonth + ( 8 - dayofweek )
e_ny_st := timestamp( "GMT-4",year,11,target_date_e_ny,2,0 )
toggle_ny_st = ( 3 < month and month < 11 ) or ( month==3 and s_ny_st <= time ) or ( month==11 and time <= e_ny_st )
toggle_uk_st = ( 3 < month and month < 10 ) or ( month==3 and s_uk_st <= time ) or ( month==10 and time <= e_uk_st )
var jp1_open = time
var jp_fix = time
var jp1_close = time
var jp2_open = time
var jp2_close = time
var hk1_open = time
var hk1_close = time
var hk2_open = time
var hk2_close = time
var uk_open = time
var uk_fix = time
var uk_close = time
var us_econ = time
var ny_open = time
var ny_close = time
checkGMT( gtm ,h ,m ) =>
gap = hour - adjustGMT + gtm
gap_day1 = gap >= 24 ? 1 : gap < 0 ? -1 : 0
gap_day2 = h * 60 + m >= 24 * 60 ? 1 : 0
gap_day1 + gap_day2
if is_intraday
jp1_open := timestamp("GMT+9",year,month, dayofmonth + checkGMT( 9 ,08 ,00 ) ,09,00)
jp_fix := timestamp("GMT+9",year,month, dayofmonth + checkGMT( 9 ,09 ,55 ) ,09,55)
jp1_close := timestamp("GMT+9",year,month, dayofmonth + checkGMT( 9 ,11 ,00 ) ,11,00)
jp2_open := timestamp("GMT+9",year,month, dayofmonth + checkGMT( 9 ,12 ,30 ) ,12,30)
jp2_close := timestamp("GMT+9",year,month, dayofmonth + checkGMT( 9 ,17 ,00 ) ,15,00)
hk1_open := timestamp("GMT+8",year,month, dayofmonth + checkGMT( 8 ,09 ,30 ) ,09,30)
hk1_close := timestamp("GMT+8",year,month, dayofmonth + checkGMT( 8 ,12 ,00 ) ,12,00)
hk2_open := timestamp("GMT+8",year,month, dayofmonth + checkGMT( 8 ,13 ,30 ) ,13,30)
hk2_close := timestamp("GMT+8",year,month, dayofmonth + checkGMT( 8 ,16 ,00 ) ,16,00)
uk_open := toggle_uk_st ? timestamp("GMT+1",year,month, dayofmonth + checkGMT( 1 ,08 ,00 ) ,08,00) : timestamp("GMT",year,month, dayofmonth + checkGMT( 0 ,08 ,00 ) ,08,00)
uk_fix := toggle_uk_st ? timestamp("GMT+1",year,month, dayofmonth + checkGMT( 1 ,16 ,00 ) ,16,00) : timestamp("GMT",year,month, dayofmonth + checkGMT( 0 ,16 ,00 ) ,16,00)
uk_close := toggle_uk_st ? timestamp("GMT+1",year,month, dayofmonth + checkGMT( 1 ,17 ,00 ) ,17,00) : timestamp("GMT",year,month, dayofmonth + checkGMT( 0 ,17 ,00 ) ,17,00)
ny_open := toggle_ny_st ? timestamp("GMT-4",year,month, dayofmonth + checkGMT( -4 ,08 ,00 ) ,08,00) : timestamp("GMT-5",year,month, dayofmonth + checkGMT( -5 ,08 ,00 ) ,08,00)
us_econ := toggle_ny_st ? timestamp("GMT-4",year,month, dayofmonth + checkGMT( -4 ,08 ,30 ) ,08,30) : timestamp("GMT-5",year,month, dayofmonth + checkGMT( -5 ,08 ,30 ) ,08,30)
ny_close := toggle_ny_st ? timestamp("GMT-4",year,month, dayofmonth + checkGMT( -4 ,17 ,00 ) ,17,00) : timestamp("GMT-5",year,month, dayofmonth + checkGMT( -5 ,17 ,00 ) ,17,00)
var line ln_01 = na
var line ln_02 = na
var line ln_03 = na
var line ln_04 = na
var line ln_05 = na
var line ln_06 = na
var line ln_07 = na
var line ln_08 = na
var line ln_09 = na
var line ln_10 = na
var line ln_11 = na
var line ln_12 = na
var line ln_13 = na
var line ln_14 = na
var line ln_15 = na
colorVL = _colorVL=="黒" ? color.black : _colorVL=="グレー" ? #cccccc : _colorVL=="緑" ? #4CAF50 : color.white
styleVL = _styleVL=="直線" ? line.style_solid : _styleVL=="破線" ? line.style_dashed : line.style_dotted
extendVL = _extendVL ? extend.both : extend.none
if is_intraday and showVL
line.delete( ln_01 )
line.delete( ln_02 )
line.delete( ln_03 )
line.delete( ln_04 )
line.delete( ln_05 )
line.delete( ln_06 )
line.delete( ln_07 )
line.delete( ln_08 )
line.delete( ln_09 )
line.delete( ln_10 )
line.delete( ln_11 )
line.delete( ln_12 )
line.delete( ln_13 )
line.delete( ln_14 )
line.delete( ln_15 )
ln_01 := line.new( jp1_open ,b4h20 ,jp1_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.gray : colorVL ,styleVL ,widthVL )
ln_02 := line.new( jp_fix ,b4h20 ,jp_fix ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.gray : colorVL ,styleVL ,widthVL )
ln_03 := line.new( jp1_close ,b4h20 ,jp1_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.gray : colorVL ,styleVL ,widthVL )
ln_04 := line.new( jp2_open ,b4h20 ,jp2_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.gray : colorVL ,styleVL ,widthVL )
ln_05 := line.new( jp2_close ,b4h20 ,jp2_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.gray : colorVL ,styleVL ,widthVL )
ln_06 := line.new( hk1_open ,b4h20 ,hk1_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.red : colorVL ,styleVL ,widthVL )
ln_07 := line.new( hk1_close ,b4h20 ,hk1_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.red : colorVL ,styleVL ,widthVL )
ln_08 := line.new( hk2_open ,b4h20 ,hk2_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.red : colorVL ,styleVL ,widthVL )
ln_09 := line.new( hk2_close ,b4h20 ,hk2_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.red : colorVL ,styleVL ,widthVL )
ln_10 := line.new( uk_open ,b4h20 ,uk_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.blue : colorVL ,styleVL ,widthVL )
ln_11 := line.new( uk_fix ,b4h20 ,uk_fix ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.blue : colorVL ,styleVL ,widthVL )
ln_12 := line.new( uk_close ,b4h20 ,uk_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.blue : colorVL ,styleVL ,widthVL )
ln_13 := line.new( ny_open ,b4h20 ,ny_open ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.orange : colorVL ,styleVL ,widthVL )
ln_14 := line.new( us_econ ,b4h20 ,us_econ ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.orange : colorVL ,styleVL ,widthVL )
ln_15 := line.new( ny_close ,b4h20 ,ny_close ,b4l20 ,xloc.bar_time ,extendVL ,_colorVL=="市場ごと" ? color.orange : colorVL ,styleVL ,widthVL )
var is_weekend = false
is_saturday = dayofweek == dayofweek.saturday
is_end_of_sunday = ( dayofweek == dayofweek.sunday and dayofmonth[1] != dayofmonth ) or ( dayofweek[1] == dayofweek.sunday and dayofweek == dayofweek.monday )
if ( is_saturday )
is_weekend := true
if ( is_end_of_sunday )
is_weekend := false
JP = not showVLBG ? color.white : not is_weekend and ( ( jp1_open < time and time < jp1_close ) or ( jp2_open < time and time < jp2_close ) ) ? color.gray : color.white
HK = not showVLBG ? color.white : not is_weekend and ( ( hk1_open < time and time < hk1_close ) or ( hk2_open < time and time < hk2_close ) ) ? color.red : color.white
UK = not showVLBG ? color.white : not is_weekend and uk_open < time and time < uk_close ? color.blue : color.white
NY = not showVLBG ? color.white : not is_weekend and ny_open < time and time < ny_close ? color.orange : color.white
bgcolor( JP ,title="日本" )
bgcolor( HK ,title="香港" )
bgcolor( UK ,title="ロンドン" )
bgcolor( NY ,title="ニューヨーク" )
デバック
plot()
を使って
確認したい値が「数値」の場合は、plot()
でデバックする。なんか上手くいっていないときは、とにかくまずplot()
。
label.new()
を使って
確認したい項目が「文字列」の場合は、label.new()
で確認する。
//@version=4
study("マイスクリプト" ,overlay=true )
dayOpen = security( syminfo.tickerid ,"D" ,open ,lookahead=barmerge.lookahead_on )
is_open = dayOpen[1]!=dayOpen
if( is_open )
label.new( bar_index ,high+tr/2 ,syminfo.timezone ,style=label.style_none )
tostring()
を組み合わせて数値を確認することもできる。
//@version=4
study("マイスクリプト" ,overlay=true )
dayOpen = security( syminfo.tickerid ,"D" ,open ,lookahead=barmerge.lookahead_on )
is_open = dayOpen[1]!=dayOpen
if( is_open )
label.new( bar_index ,high+tr/2 ,tostrign( open ) ,style=label.style_none )
開発を承っています
- Pineスクリプト(インジケーターやストラテジー)
- Google Apps Script
- Python
- MQL4
などの開発を承っています。とくに投資関連が得意です。過去の事例は「実績ページ(不定期更新)」でご確認ください。ご相談は「お問い合わせ」からお願いします。

- どんな記事
- Security()でメインチャート以外の価格データを取得
- 直線を引く
- 文字を出力する
- 配列を使う
- 複数のシグナルを表示
- 直近のデータだけ描画
- 前々回の安値・高値更新を元にしたトレイリングストップ
- 数秘を算出
- 変化率の対数を算出
- 強弱の順位を算出
- Quandlから金融データを取得
- VWAPの累積平均を算出
- timezoneと夏時間の認識
- デバック
- 記事をシェア