本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// This script is provided for educational and personal use only.
// Redistribution, republication, or commercial use is not permitted without the author’s permission.
// No warranties are provided. Use at your own risk.
// © osantan310
//@version=5
indicator("Basic ORB [MOT]", overlay=true, max_lines_count=500)
// === Inputs ===
highColor = input.color(color.green, "High Line Color")
lowColor = input.color(color.red, "Low Line Color")
midlineColor = input.color(color.white, "Midline Color")
linewidth = input.int(2, "Line Width", minval=1, maxval=4)
showHistory = input.bool(true, "Show Previous ORBs")
maxSavedOrbs = input.int(5, "Show previous number of ORBs")
showLabels = input.bool(true, "Show Price Labels")
labelBgColor = input.color(color.black, "Label Background Color")
labelTextColor = input.color(color.white, "Label Text Color")
labelSizeOpt = input.string("Small", "Label Size", options=["Tiny", "Small", "Normal", "Large", "Huge"])
labelOffset = input.int(10, "Label X Offset", minval=1, maxval=100)
// Map string to label size enum
labelSize = labelSizeOpt == "Tiny" ? size.tiny :labelSizeOpt == "Small" ? size.small :labelSizeOpt == "Normal" ? size.normal :labelSizeOpt == "Large" ? size.large :size.huge
f_plotLabel(_y, _text) =>
if showLabels
label.new(x=bar_index + labelOffset,y=_y,text=_text + " - " + str.tostring(_y, format.mintick),style=label.style_label_left,textcolor=labelTextColor,size=labelSize,color=labelBgColor)
// === Time Logic ===
startTime = timestamp("America/New_York", year, month, dayofmonth, 9, 30)
endTime = timestamp("America/New_York", year, month, dayofmonth, 9, 45)
inSession = time >= startTime and time < endTime
// === Arrays ===
var line[] orbHighLines = array.new_line()
var line[] orbLowLines = array.new_line()
var line[] orbMidLines = array.new_line()
var line[] fibLines = array.new_line()
// === ORB Variables ===
var float sessionHigh = na
var float sessionLow = na
var float mid = na
var int orb_index = na
var line liveHighLine = na
var line liveLowLine = na
var line liveMidLine = na
var int start_index = na
var bool sessionFinalized = false
// === Previous Day High/Low Lines ===
var line prevHighLine = na
var line prevLowLine = na
prevHigh = request.security(syminfo.tickerid, "D", high[1])
prevLow = request.security(syminfo.tickerid, "D", low[1])
if dayofmonth!=dayofmonth[1]
start_index := bar_index
if not inSession[1] and inSession and showHistory
finalHigh = line.new(x1=orb_index, y1=sessionHigh, x2=bar_index-1, y2=sessionHigh,
color=highColor, width=linewidth, style=line.style_solid)
finalLow = line.new(x1=orb_index, y1=sessionLow, x2=bar_index-1, y2=sessionLow,
color=lowColor, width=linewidth, style=line.style_solid)
finalMid = line.new(x1=orb_index, y1=mid, x2=bar_index-1, y2=mid,
color=midlineColor, width=linewidth, style=line.style_solid)
// Store lines in arrays
array.push(orbHighLines, finalHigh)
array.push(orbLowLines, finalLow)
array.push(orbMidLines, finalMid)
// Limit to maxSavedOrbs
if array.size(orbHighLines) > maxSavedOrbs
line.delete(array.shift(orbHighLines))
line.delete(array.shift(orbLowLines))
line.delete(array.shift(orbMidLines))
// === Capture High/Low During ORB Session ===
if not inSession[1] and inSession
orb_index := bar_index
sessionHigh := na
sessionLow := na
mid:=na
sessionFinalized := false
line.delete(liveHighLine)
line.delete(liveLowLine)
line.delete(liveMidLine)
liveHighLine := na
liveLowLine := na
liveMidLine := na
if inSession
sessionHigh := na(sessionHigh) ? high : math.max(sessionHigh, high)
sessionLow := na(sessionLow) ? low : math.min(sessionLow, low)
mid:= (sessionHigh + sessionLow) / 2
line.delete(liveHighLine)
line.delete(liveLowLine)
line.delete(liveMidLine)
// Draw real-time updating lines
liveHighLine := line.new(x1=orb_index, y1=sessionHigh, x2=bar_index+2, y2=sessionHigh,color=highColor, width=linewidth)
liveLowLine := line.new(x1=orb_index, y1=sessionLow, x2=bar_index+2, y2=sessionLow,color=lowColor, width=linewidth)
liveMidLine := line.new(x1=orb_index, y1=mid, x2=bar_index+2, y2=mid,color=midlineColor, width=linewidth)
if not inSession
line.set_x2(liveHighLine,bar_index+2)
line.set_x2(liveLowLine,bar_index+2)
line.set_x2(liveMidLine,bar_index+2)
var label orbHighLabel = na
var label orbLowLabel = na
var label orbMidLabel = na
var label prevHighLabel = na
var label prevLowLabel = na
label.delete(orbHighLabel)
label.delete(orbLowLabel)
label.delete(orbMidLabel)
orbHighLabel := f_plotLabel(sessionHigh, "ORB High")
orbLowLabel := f_plotLabel(sessionLow, "ORB Low")
orbMidLabel := f_plotLabel(mid, "ORB Mid")