本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study("FXN - Asian Session Range", overlay=true)
// Get User Inputs
user_ssth = input(title="Start Session Hour (EST)", defval="20", options=["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"])
user_sstm = input(title="End Session Minute (EST)", defval="00", options=["00", "15", "30", "45"])
user_esth = input(title="End Session Hour (EST)", defval="02", options=["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"])
user_estm = input(title="End Session Minute (EST)", defval="00", options=["00", "15", "30", "45"])
user_elth = input(title="Extend Session Lines Until Hour", defval="16", options=["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"])
user_eltm = input(title="Extend Session Lines Until Minute", defval="00", options=["00", "15", "30", "45"])
user_box_line_color = input(title="Asian Range Border Color", defval="blue", options=["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"])
boxLineWidth = input(title="Asian Box Line Width", defval=2)
user_box_line_style = input(title="Asian Box Line Style", defval="solid", options=["solid", "dashed", "dotted"])
sessionLineWidth = input(title="Session High / Low / Mid Line Width", defval=4)
user_upperlower_line_style = input(title="Session High / Low Line Style", defval="dotted", options=["solid", "dashed", "dotted"])
user_midline_color = input(title="Middle Range Line Color", defval="orange", options=["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"])
user_middle_line_style = input(title="Middle Range Line Style", defval="dotted", options=["solid", "dashed", "dotted"])
user_text_color = input(title="Text Color", defval="blue", options=["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"])
user_label_size = input(title="Text Size", defval="normal", options=["tiny", "small", "normal", "large"])
line_color = user_box_line_color == "aqua" ? color.aqua : user_box_line_color == "black" ? color.black : user_box_line_color == "blue" ? color.blue : user_box_line_color == "fuchsia" ? color.fuchsia : user_box_line_color == "gray" ? color.gray : user_box_line_color == "green" ? color.green : user_box_line_color == "lime" ? color.lime : user_box_line_color == "maroon" ? color.maroon : user_box_line_color == "navy" ? color.navy : user_box_line_color == "olive" ? color.olive : user_box_line_color == "orange" ? color.orange : user_box_line_color == "purple" ? color.purple : user_box_line_color == "red" ? color.red : user_box_line_color == "silver" ? color.silver : user_box_line_color == "teal" ? color.teal : user_box_line_color == "white" ? color.white : user_box_line_color == "yellow" ? color.yellow : color.black
midline_color = user_midline_color == "aqua" ? color.aqua : user_midline_color == "black" ? color.black : user_midline_color == "blue" ? color.blue : user_midline_color == "fuchsia" ? color.fuchsia : user_midline_color == "gray" ? color.gray : user_midline_color == "green" ? color.green : user_midline_color == "lime" ? color.lime : user_midline_color == "maroon" ? color.maroon : user_midline_color == "navy" ? color.navy : user_midline_color == "olive" ? color.olive : user_midline_color == "orange" ? color.orange : user_midline_color == "purple" ? color.purple : user_midline_color == "red" ? color.red : user_midline_color == "silver" ? color.silver : user_midline_color == "teal" ? color.teal : user_midline_color == "white" ? color.white : user_midline_color == "yellow" ? color.yellow : color.black
text_color = user_text_color == "aqua" ? color.aqua : user_text_color == "black" ? color.black : user_text_color == "blue" ? color.blue : user_text_color == "fuchsia" ? color.fuchsia : user_text_color == "gray" ? color.gray : user_text_color == "green" ? color.green : user_text_color == "lime" ? color.lime : user_text_color == "maroon" ? color.maroon : user_text_color == "navy" ? color.navy : user_text_color == "olive" ? color.olive : user_text_color == "orange" ? color.orange : user_text_color == "purple" ? color.purple : user_text_color == "red" ? color.red : user_text_color == "silver" ? color.silver : user_text_color == "teal" ? color.teal : user_text_color == "white" ? color.white : user_text_color == "yellow" ? color.yellow : color.black
box_line_style = user_box_line_style == "solid" ? line.style_solid : user_box_line_style == "dashed" ? line.style_dashed : user_box_line_style == "dotted" ? line.style_dotted : line.style_solid
upperlower_line_style = user_upperlower_line_style == "solid" ? line.style_solid : user_upperlower_line_style == "dashed" ? line.style_dashed : user_upperlower_line_style == "dotted" ? line.style_dotted : line.style_solid
middle_line_style = user_middle_line_style == "solid" ? line.style_solid : user_middle_line_style == "dashed" ? line.style_dashed : user_middle_line_style == "dotted" ? line.style_dotted : line.style_solid
labelsize = user_label_size == "tiny" ? size.tiny : user_label_size == "small" ? size.small : user_label_size == "normal" ? size.normal : user_label_size == "large" ? size.large : size.normal
start_session_hour_int = user_ssth == "00" ? 0 : user_ssth == "01" ? 1 : user_ssth == "02" ? 2 : user_ssth == "03" ? 3 : user_ssth == "04" ? 4 : user_ssth == "05" ? 5 : user_ssth == "06" ? 6 : user_ssth == "07" ? 7 : user_ssth == "08" ? 8 : user_ssth == "09" ? 9 : user_ssth == "10" ? 10 : user_ssth == "11" ? 11 : user_ssth == "12" ? 12 : user_ssth == "13" ? 13 : user_ssth == "14" ? 14 : user_ssth == "15" ? 15 : user_ssth == "16" ? 16 : user_ssth == "17" ? 17 : user_ssth == "18" ? 18 : user_ssth == "19" ? 19 : user_ssth == "20" ? 20 : user_ssth == "21" ? 21 : user_ssth == "22" ? 22 : user_ssth == "23" ? 23 : 0
start_session_minute_int = user_sstm == "00" ? 0 : user_sstm == "15" ? 15 : user_sstm == "30" ? 30 : user_sstm == "45" ? 45 : 0
end_session_hour_int = user_esth == "00" ? 0 : user_esth == "01" ? 1 : user_esth == "02" ? 2 : user_esth == "03" ? 3 : user_esth == "04" ? 4 : user_esth == "05" ? 5 : user_esth == "06" ? 6 : user_esth == "07" ? 7 : user_esth == "08" ? 8 : user_esth == "09" ? 9 : user_esth == "10" ? 10 : user_esth == "11" ? 11 : user_esth == "12" ? 12 : user_esth == "13" ? 13 : user_esth == "14" ? 14 : user_esth == "15" ? 15 : user_esth == "16" ? 16 : user_esth == "17" ? 17 : user_esth == "18" ? 18 : user_esth == "19" ? 19 : user_esth == "20" ? 20 : user_esth == "21" ? 21 : user_esth == "22" ? 22 : user_esth == "23" ? 23 : 0
end_session_minute_int = user_estm == "00" ? 0 : user_estm == "15" ? 15 : user_estm == "30" ? 30 : user_estm == "45" ? 45 : 0
end_line_hour_int = user_elth == "00" ? 0 : user_elth == "01" ? 1 : user_elth == "02" ? 2 : user_elth == "03" ? 3 : user_elth == "04" ? 4 : user_elth == "05" ? 5 : user_elth == "06" ? 6 : user_elth == "07" ? 7 : user_elth == "08" ? 8 : user_elth == "09" ? 9 : user_elth == "10" ? 10 : user_elth == "11" ? 11 : user_elth == "12" ? 12 : user_elth == "13" ? 13 : user_elth == "14" ? 14 : user_elth == "15" ? 15 : user_elth == "16" ? 16 : user_elth == "17" ? 17 : user_elth == "18" ? 18 : user_elth == "19" ? 19 : user_elth == "20" ? 20 : user_elth == "21" ? 21 : user_elth == "22" ? 22 : user_elth == "23" ? 23 : 0
end_line_minute_int = user_eltm == "00" ? 0 : user_eltm == "15" ? 15 : user_eltm == "30" ? 30 : user_eltm == "45" ? 45 : 0
chart_time_period_int = timeframe.period == "1" ? 1 : timeframe.period == "3" ? 3 : timeframe.period == "5" ? 5 : timeframe.period == "15" ? 15 : timeframe.period == "30" ? 30 : timeframe.period == "45" ? 45 : 15
end_session_minute_int_offset = (end_session_minute_int + chart_time_period_int)
rth_ses = (user_ssth) + (user_sstm) + "-" + (user_esth) + tostring(end_session_minute_int_offset)
// End User Inputs
open_bar(ses) =>
t = time("D", ses)
na(t[1]) and not na(t) or t[1] < t
is_open(ses) =>
not na(time(timeframe.period, ses))
srcHi = high
srcLo = low
var hi = 10e-10
var lo = 10e10
FromDate = timestamp(year, month, dayofmonth - 1, start_session_hour_int, start_session_minute_int)
ToDate = timestamp(year, month, dayofmonth , end_session_hour_int, end_session_minute_int) - chart_time_period_int
LineFromDate = timestamp(year, month, dayofmonth, end_session_hour_int, end_session_minute_int) - chart_time_period_int
LineToDate = timestamp(year, month, dayofmonth, end_line_hour_int, end_line_minute_int)
// When a new period begins, reset hi/lo.
hi := change(FromDate) ? srcHi : max(srcHi, hi)
lo := change(FromDate) ? srcLo : min(srcLo, lo)
inSession = not na(time(timeframe.period, rth_ses))
rth_open_bar = open_bar(rth_ses)
rth_is_open = is_open(rth_ses)
rth_low = float(na)
rth_low := rth_is_open ? rth_open_bar ? low : min(rth_low[1], low) : rth_low[1]
rth_high = float(na)
rth_high := rth_is_open ? rth_open_bar ? high : max(rth_high[1], high) : rth_high[1]
rth_mid = avg(rth_low, rth_high)
float range = na
// Build the Asian Box
trl = line.new(FromDate, rth_low, ToDate, rth_low, xloc=xloc.bar_time, color=line_color, style=box_line_style, width = boxLineWidth)
line.delete(trl[1])
trh = line.new(FromDate, rth_high, ToDate, rth_high, xloc=xloc.bar_time, color=line_color, style=box_line_style, width = boxLineWidth)
line.delete(trh[1])
trm = line.new(FromDate, rth_mid, ToDate, rth_mid, xloc=xloc.bar_time, color=midline_color, style=middle_line_style, width = sessionLineWidth)
line.delete(trm[1])
startBox = line.new(FromDate, rth_high, FromDate, rth_low, extend=extend.none, xloc=xloc.bar_time, color=line_color, style=box_line_style, width=boxLineWidth)
line.delete(startBox[1])
endBox = line.new(ToDate, rth_high, ToDate, rth_low, extend=extend.none, xloc=xloc.bar_time, color=line_color, style=box_line_style, width=boxLineWidth)
line.delete(endBox[1])
// End Section
//Apply the High / Low / Mid Session Lines for London / NY
tl = line.new(LineFromDate, rth_low, LineToDate, rth_low, xloc=xloc.bar_time, color=line_color, style=upperlower_line_style, width = sessionLineWidth)
line.delete(tl[1])
th = line.new(LineFromDate, rth_high, LineToDate, rth_high, xloc=xloc.bar_time, color=line_color, style=upperlower_line_style, width = sessionLineWidth)
line.delete(th[1])
tm = line.new(LineFromDate, rth_mid, LineToDate, rth_mid, xloc=xloc.bar_time, color=midline_color, style=middle_line_style, width = sessionLineWidth)
line.delete(tm[1])
// End Section
//Formula For Opening Range
highRes = rth_high
lowRes = rth_low
lineColor = color.new(color.white,100)
timerange(res, sess) => not na(time(res, sess)) ? 1 : 0
//Plot Statements For Opening Range Lines
openRangeHigh = plot(timerange(timeframe.period, rth_ses) > 0 ? highRes : na, color=lineColor, style=plot.style_line, linewidth=0, show_last=5)
openRangeLow = plot(timerange(timeframe.period, rth_ses) > 0 ? lowRes : na, color=lineColor, style=plot.style_line, linewidth=0, show_last=5)
bgcolor(time(timeframe.period, rth_ses) > 0 ? color.silver : na, transp=100, title="Asian Session Background Color")
fill(openRangeHigh, openRangeLow, color=color.blue, transp=90, title="Fill Asian Range Color")
if not inSession and inSession[1]
range := ((rth_high[1]-rth_low[1])/(syminfo.mintick))/10
labeloffset = barssince(not inSession)[2]/2
label mLabel = label.new(time[labeloffset], rth_low[1], "R = " + tostring(range), xloc.bar_time, yloc.price, color.new(color.black,100), label.style_labelup, text_color, labelsize)
// Debugger Section
//
f_print(_txt) => var _lbl = label(na), label.delete(_lbl), _lbl := label.new(time + (time-time[1])*3, high, _txt, xloc.bar_time, yloc.price, size = size.large)
//f_print("rth_ses = " + (rth_ses) + "\nPeriod = " + timeframe.period + "\nend_session_minute_int_offset = " + tostring(end_session_minute_int_offset))