本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("OR Box + PM/PD Levels", shorttitle="OR·PM·PD", overlay=true,
max_boxes_count=5, max_lines_count=10, max_labels_count=15)
gOR = "Opening range — first 5-min candle (9:30–9:35 ET)"
showOR = input.bool(true, "Show OR box", group=gOR)
orBg = input.color(color.new(#00acc1, 82), "OR box fill", group=gOR)
orBorder = input.color(#00acc1, "OR box border / label", group=gOR)
gPM = "Premarket high/low (4:00–9:30 ET, needs extended hours)"
showPM = input.bool(true, "Show premarket H/L", group=gPM)
pmColor = input.color(#ffa726, "Premarket line color", group=gPM)
gPD = "Previous day high/low (RTH 9:30–16:00 ET)"
showPD = input.bool(true, "Show previous-day H/L", group=gPD)
pdColor = input.color(#bdbdbd, "Previous-day line color", group=gPD)
gLB = "Labels"
showLabels = input.bool(true, "Show price labels", group=gLB)
lblSizeIn = input.string("Small", "Label size", options=["Tiny", "Small", "Normal"], group=gLB)
lblSize = lblSizeIn == "Tiny" ? size.tiny : lblSizeIn == "Normal" ? size.normal : size.small
ET = "America/New_York"
etH = hour(time, ET)
etM = minute(time, ET)
newDay = ta.change(time("D")) != 0
isORBar = etH == 9 and etM == 30
inPM = not na(time(timeframe.period, "0400-0930:1234567", ET))
inRTH = not na(time(timeframe.period, "0930-1600:1234567", ET))
var float orH = na
var float orL = na
var box orBox = na
var label orHLbl = na
var label orLLbl = na
if isORBar
orH := high
orL := low
box.delete(orBox)
label.delete(orHLbl)
label.delete(orLLbl)
if showOR and not na(orH)
orBox := box.new(time, orH, time, orL, xloc=xloc.bar_time, extend=extend.right,
bgcolor=orBg, border_color=orBorder, border_width=1)
if showLabels
orHLbl := label.new(time, orH, "ORH " + str.tostring(orH, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=orBorder, textcolor=color.white, size=lblSize)
orLLbl := label.new(time, orL, "ORL " + str.tostring(orL, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=orBorder, textcolor=color.white, size=lblSize)
var float pmH = na
var float pmL = na
var line pmHLine = na
var line pmLLine = na
var label pmHLab = na
var label pmLLab = na
if newDay
pmH := na
pmL := na
if inPM
pmH := na(pmH) ? high : math.max(pmH, high)
pmL := na(pmL) ? low : math.min(pmL, low)
if isORBar and showPM and not na(pmH)
line.delete(pmHLine)
line.delete(pmLLine)
label.delete(pmHLab)
label.delete(pmLLab)
pmHLine := line.new(time, pmH, time, pmH, xloc=xloc.bar_time, extend=extend.right,
color=pmColor, style=line.style_dashed, width=1)
pmLLine := line.new(time, pmL, time, pmL, xloc=xloc.bar_time, extend=extend.right,
color=pmColor, style=line.style_dashed, width=1)
if showLabels
pmHLab := label.new(time, pmH, "PMH " + str.tostring(pmH, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=pmColor, textcolor=color.white, size=lblSize)
pmLLab := label.new(time, pmL, "PML " + str.tostring(pmL, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=pmColor, textcolor=color.white, size=lblSize)
var float rthH = na
var float rthL = na
var float pdH = na
var float pdL = na
var line pdHLine = na
var line pdLLine = na
var label pdHLab = na
var label pdLLab = na
if newDay
pdH := rthH
pdL := rthL
rthH := na
rthL := na
if inRTH
rthH := na(rthH) ? high : math.max(rthH, high)
rthL := na(rthL) ? low : math.min(rthL, low)
if isORBar and showPD and not na(pdH)
line.delete(pdHLine)
line.delete(pdLLine)
label.delete(pdHLab)
label.delete(pdLLab)
pdHLine := line.new(time, pdH, time, pdH, xloc=xloc.bar_time, extend=extend.right,
color=pdColor, style=line.style_dashed, width=1)
pdLLine := line.new(time, pdL, time, pdL, xloc=xloc.bar_time, extend=extend.right,
color=pdColor, style=line.style_dashed, width=1)
if showLabels
pdHLab := label.new(time, pdH, "PDH " + str.tostring(pdH, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=pdColor, textcolor=color.white, size=lblSize)
pdLLab := label.new(time, pdL, "PDL " + str.tostring(pdL, format.mintick),
xloc=xloc.bar_time, style=label.style_label_left,
color=pdColor, textcolor=color.white, size=lblSize)
if showLabels
if not na(orHLbl)
label.set_x(orHLbl, time)
label.set_x(orLLbl, time)
if not na(pmHLab)
label.set_x(pmHLab, time)
label.set_x(pmLLab, time)
if not na(pdHLab)
label.set_x(pdHLab, time)
label.set_x(pdLLab, time)