本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
strategy("Gold ORB Strategy (15-min Range, 5-min Entry)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === INPUTS ===
startHour = input.int(9, "ORB Start Hour (EST)")
startMinute = input.int(30, "ORB Start Minute (EST)")
endMinute = input.int(45, "ORB End Minute (EST)")
cutoffHour = input.int(12, "Entry Cutoff Hour (EST)")
// === ORB RANGE LOGIC ===
inORB = (hour == startHour and minute >= startMinute and minute < endMinute)
var float orbHigh = na
var float orbLow = na
// Capture high and low during the ORB time range
if inORB
orbHigh := na(orbHigh) ? high : math.max(orbHigh, high)
orbLow := na(orbLow) ? low : math.min(orbLow, low)
// Reset ORB values at the end of the range
if hour == startHour and minute == endMinute
orbHigh := na
orbLow := na
// === PLOT ORB LINES ===
plot(orbHigh, title="ORB High", color=color.green, linewidth=1)
plot(orbLow, title="ORB Low", color=color.red, linewidth=1)
// === ENTRY CONDITIONS ===
rangeSize = orbHigh - orbLow
stopSize = rangeSize * 0.5
takeProfit = rangeSize * 2.0
// Trade window until cutoff hour
inTradeWindow = hour < cutoffHour
// Long condition: Close breaks above ORB high
longCondition = not na(orbHigh) and close > orbHigh and inTradeWindow
// Short condition: Close breaks below ORB low
shortCondition = not na(orbLow) and close < orbLow and inTradeWindow
// === STRATEGY ENTRIES ===
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Long TP/SL", from_entry="Long", limit=orbHigh + takeProfit, stop=orbHigh - stopSize)
if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Short TP/SL", from_entry="Short", limit=orbLow - takeProfit, stop=orbLow + stopSize)
// === VISUAL MARKERS ===
plotshape(longCondition, title="Long Trigger", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(shortCondition, title="Short Trigger", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)