本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Riding the 9 - Session Levels v1.5", overlay=true, max_lines_count=20, max_labels_count=20)
pdColor = input.color(color.yellow, "Previous day")
asiaColor = input.color(color.purple, "Asia")
londonColor = input.color(color.blue, "London")
currentColor = input.color(color.lime, "Current day")
// The CME equity-index futures session runs from 18:00 to 17:00 New York time.
// Exchange session timestamps, not the chart display timezone, drive the reset.
nyTZ = "America/New_York"
londonTZ = "Europe/London"
newDay = hour(time, nyTZ) == 18 and minute(time, nyTZ) == 0
londonOpen = hour(time, londonTZ) == 8 and minute(time, londonTZ) == 0
nyOpen = hour(time, nyTZ) == 9 and minute(time, nyTZ) == 30
nyClose = hour(time, nyTZ) == 16 and minute(time, nyTZ) == 0
var float pdH = na
var float pdL = na
var int pdHT = na
var int pdLT = na
var float fullH = na
var float fullL = na
var int fullHT = na
var int fullLT = na
var bool nyActive = false
var float cdH = na
var float cdL = na
var int cdHT = na
var int cdLT = na
var float aH = na
var float aL = na
var int aHT = na
var int aLT = na
var float lH = na
var float lL = na
var int lHT = na
var int lLT = na
var bool asiaActive = false
var bool londonActive = false
// Previous day refers to the entire completed CME futures session.
// Current day refers ONLY to New York regular hours: 09:30-16:00 ET.
// Boundary bars belong to the new session, not the session that ended.
if newDay
if not na(fullH)
pdH := fullH
pdL := fullL
pdHT := fullHT
pdLT := fullLT
fullH := high
fullL := low
fullHT := time
fullLT := time
cdH := na
cdL := na
cdHT := na
cdLT := na
nyActive := false
aH := high
aL := low
aHT := time
aLT := time
asiaActive := true
londonActive := false
lH := na
lL := na
lHT := na
lLT := na
else
if na(fullH) or high > fullH
fullH := high
fullHT := time
if na(fullL) or low < fullL
fullL := low
fullLT := time
if londonOpen
asiaActive := false
lH := high
lL := low
lHT := time
lLT := time
londonActive := true
if asiaActive and not newDay and not londonOpen
if na(aH) or high > aH
aH := high
aHT := time
if na(aL) or low < aL
aL := low
aLT := time
if nyOpen
londonActive := false
nyActive := true
cdH := high
cdL := low
cdHT := time
cdLT := time
if londonActive and not londonOpen and not nyOpen
if na(lH) or high > lH
lH := high
lHT := time
if na(lL) or low < lL
lL := low
lLT := time
if nyClose
nyActive := false
if nyActive and not nyOpen
if na(cdH) or high > cdH
cdH := high
cdHT := time
if na(cdL) or low < cdL
cdL := low
cdLT := time
var array<line> drawnLines = array.new<line>()
var array<label> drawnLabels = array.new<label>()
if barstate.islast
for ln in drawnLines
line.delete(ln)
for lb in drawnLabels
label.delete(lb)
array.clear(drawnLines)
array.clear(drawnLabels)
prices = array.from(pdH, pdL, aH, aL, lH, lL, cdH, cdL)
anchors = array.from(pdHT, pdLT, aHT, aLT, lHT, lLT, cdHT, cdLT)
names = array.from("PDH", "PDL", "AH", "AL", "LH", "LL", "CDH", "CDL")
colors = array.from(pdColor, pdColor, asiaColor, asiaColor, londonColor, londonColor, currentColor, currentColor)
used = array.new_bool(8, false)
for i = 0 to 7
price = array.get(prices, i)
if not na(price) and not array.get(used, i)
txt = array.get(names, i)
anchor = array.get(anchors, i)
col = array.get(colors, i)
array.set(used, i, true)
if i < 7
for j = i + 1 to 7
other = array.get(prices, j)
if not na(other) and math.round(other / syminfo.mintick) == math.round(price / syminfo.mintick)
txt += " / " + array.get(names, j)
otherAnchor = array.get(anchors, j)
if not na(otherAnchor)
anchor := na(anchor) ? otherAnchor : math.min(anchor, otherAnchor)
array.set(used, j, true)
if not na(anchor)
ln = line.new(anchor, price, time, price, xloc=xloc.bar_time, extend=extend.right, color=col, style=line.style_dashed, width=1)
lb = label.new(time + timeframe.in_seconds() * 1000 * 3, price, txt, xloc=xloc.bar_time, style=label.style_none, textcolor=col, size=size.tiny)
array.push(drawnLines, ln)
array.push(drawnLabels, lb)