TradingViewインジケーター『Multiple Time Frame Open』

このインジケーターはTradingView公式から「ユーザーを誤解させる」として突然に強制非公開にされたインジケーターです。
ですが、勝手に誤解しているのは公式の方ですので気にしないでください。彼らはかなり雑なんです。インジ開発者はそういう扱われ方です。
ご利用の際はその点を留意した上で、自己の責任において使用してください。
ご心配でしたら、以下のPineScriptのコードをお読みください。

2021/11/15 更新。線の色と太さを変更

//@version=4
study("Multiple Time Frame Open", shorttitle="MTFO", overlay=true, max_bars_back=10)

line_color =  input(false, title="Lime?") ? color.lime : #2196f3 
show_lines = input(true, title="Show Lines? Or, Labels Only?")
show_thursday = input(false, title="Show Thursday-Weekly?")
show_close = input(false, title="Show Close Lines?")
yellow_ratio = input(0.8, type=input.float, maxval=1, minval=0, title="Close time remaining ratio for color change (yellow)")
red_ratio = input(0.9, type=input.float, maxval=1, minval=0, title="Close time remaining ratio for color change (red)")

y_open = security(syminfo.tickerid, '12M', open, lookahead=barmerge.lookahead_on)
plot(show_lines? y_open :na, title="YearlyOpen",style=plot.style_linebr, color=change(y_open)!=0?na:#0000ff, linewidth=12, transp=30)
plotchar(y_open, char='Y', show_last=1, location=location.absolute, size=size.small, color=close < y_open ? color.red : close > y_open ? color.lime :line_color, offset=4, editable=false)

m_open = security(syminfo.tickerid, 'M', open, lookahead=barmerge.lookahead_on)
plot(show_lines and timeframe.isintraday ? m_open :na, title="MonthlyOpen(bold)",style=plot.style_line, color=change(m_open)!=0?na:color.red, linewidth=9, transp=50)
plot(show_lines and (timeframe.isdaily or timeframe.isweekly) ? m_open :na, title="MonthlyOpen(thin)",style=plot.style_line, color=change(m_open)!=0?na:color.red, linewidth=2, transp=20)
plotchar(timeframe.isintraday or timeframe.isdaily or timeframe.isweekly ? m_open :na, char='M', show_last=1, location=location.absolute, size=size.small, color=close < m_open ? color.red : close > m_open ? color.lime :line_color, offset=4, editable=false)

w_open = security(syminfo.tickerid, 'W', open, lookahead=barmerge.lookahead_on)
plot(show_lines and timeframe.isintraday ? w_open :na , title="WeeklyOpen(bold)",style=plot.style_line, color=change(w_open)!=0?na:color.orange, linewidth=6, transp=50)
plot(show_lines and timeframe.isdaily ? w_open :na , title="WeeklyOpen(thin)",style=plot.style_line, color=change(w_open)!=0?na:color.orange, linewidth=1, transp=0)
plotchar(timeframe.isintraday or timeframe.isdaily ? w_open :na, char='W', show_last=1, location=location.absolute, size=size.small, color=close < w_open ? color.red : close > w_open ? color.lime :line_color, offset=4, editable=false)

thursday_back =
 dayofweek == dayofweek.thursday? 0 :
 dayofweek == dayofweek.wednesday? 6 :
 dayofweek == dayofweek.tuesday? 5 :
 dayofweek == dayofweek.monday? 4 :
 dayofweek == dayofweek.sunday? 3 :
 dayofweek == dayofweek.saturday? 2 :
 dayofweek == dayofweek.friday? 1 :na

daily_color = show_thursday and dayofweek == dayofweek.thursday? color.fuchsia :line_color
d_open = timeframe.isintraday ? security(syminfo.tickerid, 'D', open, lookahead=barmerge.lookahead_on) : na
plot(show_lines and timeframe.isintraday ? d_open :na , title="DailyOpen",style=plot.style_line, color=change(d_open)!=0?na:daily_color, linewidth=4, transp=30)
plotchar(timeframe.isintraday ? d_open :na, char='D', show_last=1, location=location.absolute, size=size.small, color=close < d_open ? color.red : close > d_open ? color.lime :line_color, offset=4, editable=false)

thursday_open = show_thursday ? security(syminfo.tickerid, 'D', open[thursday_back], lookahead=barmerge.lookahead_on) : na
thursday_open_time = show_thursday ? security(syminfo.tickerid, 'D', time[thursday_back], lookahead=barmerge.lookahead_on) : na
plotchar(show_thursday and timeframe.isintraday ? thursday_open :na, char='T', show_last=1, location=location.absolute, size=size.small, color=close < thursday_open ? color.red : close > thursday_open ? color.lime :line_color, offset=7, editable=false)

//thrsday_line = show_thursday ? line.new(x1=thursday_open_time, y1=thursday_open, x2=time, y2=thursday_open, xloc=xloc.bar_time, extend=extend.none, width=4, color=color.new(color.fuchsia,30)) :na
//line.delete(thrsday_line[1])

var line thrsday_line = show_lines and show_thursday ? line.new(x1=na, y1=thursday_open, x2=thursday_open_time, y2=thursday_open, xloc=xloc.bar_time, extend=extend.right, width=4, color=color.new(color.fuchsia,30)) :na
line.set_xy1(thrsday_line, time, thursday_open)
//line.set_xy2(thrsday_line, thursday_open_time, thursday_open) //and extend.none, not worked
line.set_xy2(thrsday_line, time[1], thursday_open)

h4_open = security(syminfo.tickerid, '240', open, lookahead=barmerge.lookahead_on)
is_under_60min = timeframe.isintraday and timeframe.multiplier < 60 ? true :na
plot(show_lines and is_under_60min ? h4_open :na , title="4HourlyOpen(bold)",style=plot.style_line, color=change(h4_open)!=0?na:color.yellow, linewidth=2, transp=0)
plot(show_lines and (timeframe.isintraday and timeframe.multiplier == 60) ? h4_open :na , title="4HourlyOpen(thin)",style=plot.style_line, color=change(h4_open)!=0?na:color.yellow,linewidth=1, transp=0)
plotchar(timeframe.isintraday and  timeframe.multiplier <= 60 ? h4_open :na, char='4', show_last=1, location=location.absolute, size=size.small, color=close < h4_open ? color.red : close > h4_open ? color.lime :line_color, transp=0, offset=3, editable=false)

h1_open = is_under_60min ? security(syminfo.tickerid, '60', open, lookahead=barmerge.lookahead_on) : na
plot(show_lines and is_under_60min ? h1_open : na, title="1HourlyOpen",style=plot.style_line, color=change(h1_open)!=0?na:line_color, linewidth=1, transp=0)
plotchar(is_under_60min ? h1_open : na, char='1', show_last=1, location=location.absolute, size=size.tiny, color=close < h1_open ? color.red : close > h1_open ? color.lime :line_color, transp=0, offset=2, editable=false)

is_1min_or_sec = timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier == 1) ? true :na
m15_open = is_1min_or_sec ? security(syminfo.tickerid, '15', open, lookahead=barmerge.lookahead_on) : na
plot(show_lines and is_1min_or_sec ? m15_open : na, title="15MunitsOpen",style=plot.style_line, color=change(m15_open)!=0?na:line_color, linewidth=1, transp=0)
//plotchar(is_1min_or_sec ? m15_open : na, char='1', show_last=1, location=location.absolute, size=size.tiny, color=close < m15_open ? color.red : close > m15_open ? color.lime :line_color, transp=0, offset=2, editable=false)

var label m15_open_label = is_1min_or_sec ? label.new(na, na, "15min", textcolor=na, color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_xy(m15_open_label, time + 5 * (time - time[1]), m15_open)
label.set_textcolor(m15_open_label, close < m15_open ? color.red : close > m15_open ? color.lime :line_color)

////next close time
show_close_at_1min_or_sec = show_close and is_1min_or_sec ? true : false

//15 min 900000
m1_last_close_price = show_close ? security(syminfo.tickerid, '1', close[1], lookahead=barmerge.lookahead_on) : na

m15_open_time = show_close_at_1min_or_sec ? security(syminfo.tickerid, '15', time, lookahead=barmerge.lookahead_on) : na
m15_close_time = m15_open_time + 900000
//m15_textcolor = (m15_open_time + 810000) < timenow ? color.red : #00ff00 
m15_textcolor = (900000 * red_ratio) + m15_open_time < timenow ? #ff0000  : (900000 * yellow_ratio) + m15_open_time < timenow ? #ffff00  : #00ff00 
var label m15_close_label = show_close_at_1min_or_sec ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
//remaining_sec_text = tostring(second(m15_close_time - timenow))
label.set_text(m15_close_label, "                           ⓒ15min: " + tostring(minute(m15_close_time - timenow)) + "min ")// + remaining_sec_text + "sec")
label.set_textcolor(m15_close_label, m15_textcolor)
label.set_xy(m15_close_label, m15_close_time, m1_last_close_price)

var line m15_close_line = show_close_at_1min_or_sec ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=1, color=m15_textcolor) :na
line.set_xy1(m15_close_line, m15_close_time, 1)
line.set_xy2(m15_close_line, m15_close_time, -1)
line.set_color(m15_close_line, m15_textcolor)

//5 min 300000
m5_open_time = show_close_at_1min_or_sec ? security(syminfo.tickerid, '5', time, lookahead=barmerge.lookahead_on) : na
m5_close_time = m5_open_time + 300000
//m5_textcolor = (m5_open_time + 810000) < timenow ? color.red : #00ff00 
m5_textcolor = (300000 * red_ratio) + m5_open_time < timenow ? #ff0000  : (300000 * yellow_ratio) + m5_open_time < timenow ? #ffff00  : #00ff00 
var label m5_close_label = show_close_at_1min_or_sec ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,100), style=label.style_labelup, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(m5_close_label, "\n                           ⓒ5min: " + tostring(minute(m5_close_time - timenow)) + "min ")// + remaining_sec_text + "sec")
label.set_textcolor(m5_close_label, m5_textcolor)
label.set_xy(m5_close_label, m5_close_time, m1_last_close_price)

var line m5_close_line = show_close_at_1min_or_sec ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=1, color=m5_textcolor) :na
line.set_xy1(m5_close_line, m5_close_time, 1)
line.set_xy2(m5_close_line, m5_close_time, -1)
line.set_color(m5_close_line, m5_textcolor)

//1 Hourly 3600000
h1_open_time = show_close_at_1min_or_sec ? security(syminfo.tickerid, '60', time, lookahead=barmerge.lookahead_on) : na
h1_close_time = show_close_at_1min_or_sec ? security(syminfo.tickerid, '60', time_close, lookahead=barmerge.lookahead_on) : na
//h1_textcolor = (h1_open_time + 3240000) < timenow ? #ff0000  : #00ff00 
h1_textcolor = ((h1_close_time - h1_open_time) * red_ratio) + h1_open_time < timenow ? #ff0000  : ((h1_close_time - h1_open_time) * yellow_ratio) + h1_open_time < timenow ? #ffff00  : #00ff00 
var label h1_close_label = show_close_at_1min_or_sec ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(h1_close_label, "                     ⓒ1h: " + tostring(minute(h1_close_time - timenow)) + "min \n")// + remaining_sec_text + "sec\n")
label.set_textcolor(h1_close_label, h1_textcolor)
label.set_xy(h1_close_label, h1_close_time, m1_last_close_price)

var line h1_close_line = show_close_at_1min_or_sec ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=1, color=h1_textcolor) :na
line.set_xy1(h1_close_line, h1_close_time, 1)
line.set_xy2(h1_close_line, h1_close_time, -1)
line.set_color(h1_close_line, h1_textcolor)

//4 Hourly 14400000
show_close_at_under_60min =  show_close and is_under_60min ? true : false
h4_open_time = show_close_at_under_60min ? security(syminfo.tickerid, '240', time, lookahead=barmerge.lookahead_on) : na
h4_close_time = show_close_at_under_60min ? security(syminfo.tickerid, '240', time_close, lookahead=barmerge.lookahead_on) : na
//h4_textcolor = (h4_open_time + 12960000) < timenow ? #ff0000  : #00ff00 
h4_textcolor = ((h4_close_time - h4_open_time) * red_ratio) + h4_open_time < timenow ? #ff0000  : ((h4_close_time - h4_open_time) * yellow_ratio) + h4_open_time < timenow ? #ffff00  : #00ff00 
var label h4_close_label = show_close_at_under_60min ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(h4_close_label, "                         ⓒ4h: " + tostring(floor((h4_close_time - timenow) / 3600000)) + "h " + tostring(minute(h4_close_time - timenow)) + "min \n\n")// + remaining_sec_text + "sec\n\n")
label.set_textcolor(h4_close_label, h4_textcolor)
label.set_xy(h4_close_label, h4_close_time, m1_last_close_price)

var line h4_close_line = show_close_at_under_60min ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=2, color=h4_textcolor) :na
line.set_xy1(h4_close_line, h4_close_time, 1)
line.set_xy2(h4_close_line, h4_close_time, -1)
line.set_color(h4_close_line, h4_textcolor)

//Daily 86400000
show_close_at_intraday = show_close and timeframe.isintraday ? true : false
d_open_time = show_close_at_intraday ? security(syminfo.tickerid, 'D', time, lookahead=barmerge.lookahead_on) : na
d_close_time = show_close_at_intraday ? security(syminfo.tickerid, 'D', time_close, lookahead=barmerge.lookahead_on) : na
//d_textcolor = (d_open_time + 77760000) < timenow ? #ff0000  : #00ff00 
d_textcolor = ((d_close_time - d_open_time) * red_ratio) + d_open_time < timenow ? #ff0000  : ((d_close_time - d_open_time) * yellow_ratio) + d_open_time < timenow ? #ffff00  : #00ff00 
var label d_close_label = show_close_at_intraday ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_textcolor(d_close_label, d_textcolor)
label.set_xy(d_close_label, d_close_time, m1_last_close_price)
label.set_text(d_close_label, "                         ⓒd: " + tostring(floor((d_close_time - timenow) / 3600000)) + "h " + tostring(minute(d_close_time - timenow)) + "min \n\n\n")// + remaining_sec_text + "sec\n\n\n")

var line d_close_line = show_close_at_intraday ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=4, color=d_textcolor) :na
line.set_xy1(d_close_line, d_close_time, 1)
line.set_xy2(d_close_line, d_close_time, -1)
line.set_color(d_close_line, d_textcolor == #ff0000  ? color.new(#ff0000, 70) : d_textcolor == #ffff00  ? color.new(#ffff00, 70) : d_textcolor == #00ff00  ? color.new(#00ff00, 70) : color.white)

//Weekly 604800000
is_intraday_or_daily =  timeframe.isintraday or timeframe.isdaily ? true : false
show_close_at_intraday_or_daily = is_intraday_or_daily and show_close ? true : false
w_open_time = show_close_at_intraday_or_daily ? security(syminfo.tickerid, 'W', time, lookahead=barmerge.lookahead_on) : na
w_close_time = show_close_at_intraday_or_daily ? security(syminfo.tickerid, 'W', time_close, lookahead=barmerge.lookahead_on) : na
w_time_length = w_close_time - w_open_time
//w_textcolor = (w_open_time + 544320000) < timenow ? #ff0000  : #00ff00 
w_textcolor = (w_time_length * red_ratio) + w_open_time < timenow ? #ff0000  : (w_time_length * yellow_ratio) + w_open_time < timenow ? #ffff00  : #00ff00 
var label w_close_label = show_close_at_intraday_or_daily ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(w_close_label, "                               ⓒwk: " + tostring(floor((w_close_time - timenow) / 86400000)) + "d " + tostring(floor((w_close_time - timenow) / 3600000) % 24) + "h " + tostring(minute(w_close_time - timenow)) + "min \n\n\n\n")// + remaining_sec_text + "sec\n\n\n\n")
label.set_textcolor(w_close_label, w_textcolor)
label.set_xy(w_close_label, w_close_time, m1_last_close_price)

var line w_close_line = show_close_at_intraday_or_daily ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=6, color=w_textcolor) :na
line.set_xy1(w_close_line, w_close_time, 1)
line.set_xy2(w_close_line, w_close_time, -1)
line.set_color(w_close_line, w_textcolor == #ff0000  ? color.new(#ff0000, 70) : w_textcolor == #ffff00  ? color.new(#ffff00, 70) : w_textcolor == #00ff00  ? color.new(#00ff00, 70) : color.white)

//Thursday 604800000
thursday_close_time = thursday_open_time + 604800000
//thursday_textcolor = (thursday_open_time + 544320000) < timenow ? #ff0000  : #00ff00 
thursday_textcolor = (w_time_length * red_ratio) + thursday_open_time < timenow ? #ff0000  : (w_time_length * yellow_ratio) + thursday_open_time < timenow ? #ffff00  : #00ff00 
var label thursday_close_label = show_thursday and show_close_at_intraday_or_daily ? label.new(na, na, "                          Thursday close\n\n\n\n", textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(thursday_close_label, "                                           ⓒThursday: " + tostring(floor((thursday_close_time - timenow) / 86400000) - 1) + "d " + tostring(floor((thursday_close_time - timenow) / 3600000) % 24) + "h " + tostring(minute(thursday_close_time - timenow)) + "min \n\n\n\n")// + remaining_sec_text + "sec\n\n\n\n")
label.set_textcolor(thursday_close_label, thursday_textcolor)
label.set_xy(thursday_close_label, thursday_close_time, m1_last_close_price)

var line thursday_close_line = show_thursday and show_close_at_intraday_or_daily ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=6, color=thursday_textcolor) :na
line.set_xy1(thursday_close_line, thursday_close_time, 1)
line.set_xy2(thursday_close_line, thursday_close_time, -1)
line.set_color(thursday_close_line, thursday_textcolor == #ff0000  ? color.new(#ff0000, 70) : thursday_textcolor == #ffff00  ? color.new(#ffff00, 70) : thursday_textcolor == #00ff00  ? color.new(#00ff00, 70) : color.white)

//Monthly
m_open_time = security(syminfo.tickerid, 'M', time, lookahead=barmerge.lookahead_on)
m_close_time = security(syminfo.tickerid, 'M', time_close, lookahead=barmerge.lookahead_on)
m_textcolor = ((m_close_time - m_open_time) * red_ratio) + m_open_time < timenow ? #ff0000  : ((m_close_time - m_open_time) * yellow_ratio) + m_open_time < timenow ? #ffff00  : #00ff00 
var label m_close_label = show_close and (is_intraday_or_daily or timeframe.isweekly) ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(m_close_label, "                                   ⓒmo: " + tostring(floor((m_close_time - timenow) / 86400000)) + "d " + tostring(floor((m_close_time - timenow) / 3600000) % 24) + "h " + tostring(minute(m_close_time - timenow)) + "min \n\n\n\n\n")// + remaining_sec_text + "sec\n\n\n\n\n")
label.set_textcolor(m_close_label, m_textcolor)
label.set_xy(m_close_label, m_close_time, m1_last_close_price)

var line m_close_line = show_close and (is_intraday_or_daily or timeframe.isweekly) ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=8, color=m_textcolor) :na
line.set_xy1(m_close_line, m_close_time, 1)
line.set_xy2(m_close_line, m_close_time, -1)
line.set_color(m_close_line, m_textcolor == #ff0000  ? color.new(#ff0000, 70) : m_textcolor == #ffff00  ? color.new(#ffff00, 70) : m_textcolor == #00ff00  ? color.new(#00ff00, 70) : color.white)

//Yearly
y_open_time = security(syminfo.tickerid, '12M', time, lookahead=barmerge.lookahead_on)
y_close_time = security(syminfo.tickerid, '12M', time_close, lookahead=barmerge.lookahead_on)
y_textcolor = ((y_close_time - y_open_time) * red_ratio) + y_open_time < timenow ? #ff0000  : ((y_close_time - y_open_time) * yellow_ratio) + y_open_time < timenow ? #ffff00  : #00ff00 
var label y_close_label = show_close ? label.new(na, na, na, textcolor=color.new(color.gray,0), color=color.new(color.white,50), style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price) :na
label.set_text(y_close_label, "                                       ⓒyr: " + tostring(floor((y_close_time - timenow) / 86400000)) + "d " + tostring(floor((y_close_time - timenow) / 3600000) % 24) + "h " + tostring(minute(y_close_time - timenow)) + "min \n\n\n\n\n\n")// + remaining_sec_text + "sec\n\n\n\n\n\n")
label.set_textcolor(y_close_label, y_textcolor)
label.set_xy(y_close_label, y_close_time, m1_last_close_price)

var line y_close_line = show_close ? line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.both, width=10, color=y_textcolor) :na
line.set_xy1(y_close_line, y_close_time, 1)
line.set_xy2(y_close_line, y_close_time, -1)
line.set_color(y_close_line, y_textcolor == #ff0000  ? color.new(#ff0000, 70) : y_textcolor == #ffff00  ? color.new(#ffff00, 70) : y_textcolor == #00ff00  ? color.new(#00ff00, 70) : color.white)


plot(close,title="Current Price", transp=100, editable=false)




この記事が気に入ったらサポートをしてみませんか?