Sessions (Nephew_Sam_)

nephew_sam_ · study · 118 行 · 点赞 3,005 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=4
study(title='Sessions (Nephew_Sam_)', overlay=true)
 
 
//Vertical Line
vline(BarIndex, Color, LineStyle, LineWidth) =>
    return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend=extend.both, color=Color, style=LineStyle, width=LineWidth)
 
// -----------------------------------------------------------------------------------------------
// -----------------------------------   SESSIONS   ----------------------------------------------
// -----------------------------------------------------------------------------------------------
 
temp1 = input(title="•••••••••••••••••••••••••••••••••••••••••••", type=input.bool, defval=false)
temp2 = input(title="•••••••••••••••• FX Sessions ••••••••••••••••", type=input.bool, defval=false)
showSessions = input(title="Show sessions", type=input.bool, defval=true)
londonSessionTime = input(title="London Session Time", type=input.session, defval="0300-1100")
nySessionTime = input(title="NY Session Time", type=input.session, defval="0800-1800")
asianSessionTime = input(title="Asian Session Time", type=input.session, defval="1800-0300")
 
as = time(timeframe.period, asianSessionTime)
ls = time(timeframe.period, londonSessionTime)
ns = time(timeframe.period, nySessionTime)
 
Asia = na(as) ? na : color.white
London = na(ls) ? na : color.blue
NY = na(ns) ? na : color.red
 
bgcolor(showSessions ==  true and timeframe.isintraday == true ? Asia : na, title="Asia Session")
bgcolor(showSessions ==  true and timeframe.isintraday == true ? London : na, title="London Session")
bgcolor(showSessions ==  true and timeframe.isintraday == true ? NY : na, title="New York Session")
 
 
// ----- Killzone -----
temp3 = input(title="•••••••••••••••••••••••••••••••••••••••••••••", type=input.bool, defval=false)
temp4 = input(title="•••••••••••••••••• Killzones ••••••••••••••••••", type=input.bool, defval=false)
showKillszones = input(title="Show killzones", type=input.bool, defval=false)
londonOpenKillzoneTime = input(title="London Open Killzone Time", type=input.session, defval="0200-0400")
nyOpenKillzoneTime = input(title="NY Open Killzone Time", type=input.session, defval="0700-0900")
londonCloseKillzoneTime = input(title="London Close Killzone Time", type=input.session, defval="1000-1100")
tokyoKillzoneTime = input(title="Tokyo Open Killzone Time", type=input.session, defval="1900-2000")
 
lnopen = time(timeframe.period, londonOpenKillzoneTime)
nyopen = time(timeframe.period, nyOpenKillzoneTime)
lnclose = time(timeframe.period, londonCloseKillzoneTime)
tokyo = time(timeframe.period, tokyoKillzoneTime)
 
LondonOpen = na(lnopen) ? na : color.green
NYOpen = na(nyopen) ? na : color.blue
LondonClose = na(lnclose) ? na : color.red
TokyoOpen = na(tokyo) ? na : color.silver
 
bgcolor(showKillszones ==  true and timeframe.isintraday == true ? LondonOpen : na, title="London Open Killzone")
bgcolor(showKillszones ==  true and timeframe.isintraday == true ? NYOpen : na, title="NY Open Killzone")
bgcolor(showKillszones ==  true and timeframe.isintraday == true ? LondonClose : na, title="London Close Killzone")
bgcolor(showKillszones ==  true and timeframe.isintraday == true ? TokyoOpen : na, title="Tokyo Open Killzone")
 
 
// -----------------------------------------------------------------------------------------------
// ---------------------------------   DAILY DIVIDERS   ------------------------------------------
// -----------------------------------------------------------------------------------------------
 
temp5 = input(title="•••••••••••••••••••••••••••••••••••••••••••••", type=input.bool, defval=false)
temp6 = input(title="••••••••••••••• Daily Dividers •••••••••••••••", type=input.bool, defval=false)
showDailyDividers = input(title="Show Daily Dividers ?", type=input.bool, defval=true)
divider_text_color = input(color.blue, "Divider and Text Color", type = input.color)
showDOW = input(true, title="Show days of week")
user_week_start = input(title="Week starts on?", defval="Sunday", options=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
week_start_day = user_week_start == "Sunday" ? dayofweek.sunday : user_week_start == "Monday" ? dayofweek.monday : user_week_start == "Tuesday" ? dayofweek.tuesday : user_week_start == "Wednesday" ? dayofweek.wednesday : user_week_start == "Thursday" ? dayofweek.thursday : user_week_start == "Friday" ? dayofweek.friday : user_week_start == "Saturday" ? dayofweek.saturday : dayofweek.sunday
 
 
// Forex.com use a different server time that other brokers
// So need to adjust
tickerExchangeOffset = 5
int new_day_start_time = 17
int dayLabelStartTime = 1
if (syminfo.timezone == "Etc/UTC")
    new_day_start_time := new_day_start_time + tickerExchangeOffset
    dayLabelStartTime := dayLabelStartTime + tickerExchangeOffset
 
// Add the start of week line
isNewWeek() => dayofweek == week_start_day ? 1 : 0
isStartTime() => hour == new_day_start_time and minute == 0 ? 1 : 0
    
isValidDaySeparatorResolution() => timeframe.isintraday == true ? 1 : 0
    
isValidDayTextSeparatorResolution() => timeframe.isintraday == true and not (timeframe.period == "240" or timeframe.period == "180" or timeframe.period == "360") ? 1 : 0
 
 
isValidDaySeparator = isValidDaySeparatorResolution()
isValidDayTextSeparator = isValidDayTextSeparatorResolution()
 
// Add line separator
if(showDailyDividers and isValidDaySeparator and isNewWeek()==1 and isStartTime()==1)
    vline(bar_index, divider_text_color, line.style_dashed, 1) 
 
isNewDay() => dayofweek != week_start_day ? 1 : 0
isNewDayStartTime() => hour == new_day_start_time and minute == 0 ? 1 : 0
 
if(showDailyDividers and isValidDaySeparator and isNewDay()==1 and isStartTime()==1)
    vline(bar_index, divider_text_color, line.style_dashed, 1) 
        
 
// Days Label
dot_color = color.new(color.silver,100)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.monday : false, text="Mon", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.tuesday : false, text="Tues", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.wednesday : false, text="Wed", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.thursday : false, text="Thu", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.friday : false, text="Fri", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.saturday : false, text="Sat", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)
 
plotshape(showDailyDividers and isValidDayTextSeparator and showDOW ? hour == dayLabelStartTime and minute == 0 and dayofweek == dayofweek.sunday : false, text="Sun", color=dot_color, offset=0, style=shape.circle, location = location.bottom, textcolor=divider_text_color, size=size.tiny, transp=40, editable=false)

← 返回列表