本页源码来自 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/
// © Darkmatter513
// @version=5
indicator("NeuraEdge ORB", overlay=true, max_labels_count=500, max_lines_count=500, max_boxes_count=500)
// ═══════════════════════════════════════════════════════════════════════════════
// 15-MINUTE OPENING RANGE BREAKOUT + FVG CONFLUENCE
//
// Strategy:
// 1. Mark the 9:30-9:45 AM ET range (first 15 min)
// 2. Wait for breakout above/below with volume
// 3. Check for FVG confluence (gap in direction of breakout)
// 4. Enter on breakout, SL at opposite side or midpoint
//
// Best on: SPY, QQQ, IWM, high-volume stocks
// Timeframe: 1-5 minute charts recommended
// ═══════════════════════════════════════════════════════════════════════════════
// ═══════════════════════════════════════════════════════════════════════════════
// INPUTS
// ═══════════════════════════════════════════════════════════════════════════════
g_display = "📊 Display"
showSignals = input.bool(true, "Show Signals", group=g_display)
showORBox = input.bool(true, "Show Opening Range Box", group=g_display)
showFVG = false
showDashboard = input.bool(true, "Show Dashboard", group=g_display)
g_orb = "⏰ Opening Range Settings"
orbMinutes = input.int(15, "Opening Range Minutes", minval=5, maxval=60, step=5, group=g_orb)
sessionStart = input.session("0930-0945", "Opening Range Session", group=g_orb)
tradingEnd = input.int(15, "Stop Trading After (Hour ET)", minval=10, maxval=16, group=g_orb,tooltip="Stop taking new trades after this hour (15 = 3PM)")
g_entry = "🎯 Entry Settings"
entryType = input.string("Breakout", "Entry Type", options=["Breakout", "Retest"], group=g_entry,tooltip="Breakout: Enter immediately on break\nRetest: Wait for pullback to range")
requireVolume = input.bool(true, "Require Volume Confirmation", group=g_entry)
requireFVG = input.bool(true, "Require FVG Confluence", group=g_entry)
g_risk = "💰 Risk Management"
slType = input.string("Opposite Side", "Stop Loss Placement", options=["Opposite Side", "Midpoint", "ATR Based"], group=g_risk)
rrRatio = input.float(1.5, "Risk:Reward Ratio", minval=1.0, maxval=5.0, step=0.5, group=g_risk)
trailAfterTP1 = input.bool(false, "Trail Stop After Partial TP", group=g_risk)
// ═══════════════════════════════════════════════════════════════════════════════
// TIME & SESSION FUNCTIONS
// ═══════════════════════════════════════════════════════════════════════════════
// Convert to NY time
nyHour = hour(time, "America/New_York")
nyMinute = minute(time, "America/New_York")
// Check if we're in opening range session (9:30-9:45 default)
inOpeningRange = (nyHour == 9 and nyMinute >= 30 and nyMinute < 30 + orbMinutes)
// First bar of opening range
isFirstORBar = inOpeningRange and not inOpeningRange[1]
// Opening range just ended
orbEnded = not inOpeningRange and inOpeningRange[1]
// Trading hours (after ORB, before cutoff)
inTradingHours = nyHour >= 9 and nyHour < tradingEnd and not inOpeningRange
// New trading day
newDay = ta.change(time("D")) != 0
// ═══════════════════════════════════════════════════════════════════════════════
// OPENING RANGE TRACKING
// ═══════════════════════════════════════════════════════════════════════════════
var float orHigh = na
var float orLow = na
var float orMid = na
var int orStartBar = na
var int orEndBar = na
var bool orComplete = false
var bool brokenUp = false
var bool brokenDown = false
// Reset on new day
if newDay
orHigh := na
orLow := na
orMid := na
orStartBar := na
orEndBar := na
orComplete := false
brokenUp := false
brokenDown := false
// Build opening range
if inOpeningRange
if isFirstORBar
orHigh := high
orLow := low
orStartBar := bar_index
else
orHigh := math.max(orHigh, high)
orLow := math.min(orLow, low)
// Mark range complete
if orbEnded and not orComplete
orComplete := true
orMid := (orHigh + orLow) / 2
orEndBar := bar_index
// Calculate range size
orRange = orComplete ? orHigh - orLow : na
atr = ta.atr(14)
// ═══════════════════════════════════════════════════════════════════════════════
// FVG DETECTION (Fair Value Gaps)
// ═══════════════════════════════════════════════════════════════════════════════
type FVG
float top
float bottom
bool bullish
int bar
bool filled
var array<FVG> fvgArray = array.new<FVG>()
// Minimum FVG size
minFVGSize = atr * 0.3
// Detect new FVGs
bullishFVG = low > high[2] and (low - high[2]) > minFVGSize
bearishFVG = high < low[2] and (low[2] - high) > minFVGSize
if bullishFVG
fvg = FVG.new()
fvg.top := low
fvg.bottom := high[2]
fvg.bullish := true
fvg.bar := bar_index - 1
fvg.filled := false
if array.size(fvgArray) >= 20
array.shift(fvgArray)
array.push(fvgArray, fvg)
if bearishFVG
fvg = FVG.new()
fvg.top := low[2]
fvg.bottom := high
fvg.bullish := false
fvg.bar := bar_index - 1
fvg.filled := false
if array.size(fvgArray) >= 20
array.shift(fvgArray)
array.push(fvgArray, fvg)
// Check for FVG fill
if array.size(fvgArray) > 0
for i = array.size(fvgArray) - 1 to 0
if i < array.size(fvgArray)
fvg = array.get(fvgArray, i)
if not fvg.filled
fvgMid = (fvg.top + fvg.bottom) / 2
if fvg.bullish and low <= fvgMid
fvg.filled := true
if not fvg.bullish and high >= fvgMid
fvg.filled := true
// Check for unfilled FVG in breakout direction
f_hasFVGConfluence(bool forLong) =>
hasConfluence = false
if array.size(fvgArray) > 0
for i = array.size(fvgArray) - 1 to 0
if i < array.size(fvgArray)
fvg = array.get(fvgArray, i)
// FVG created today, unfilled, in right direction
if not fvg.filled and bar_index - fvg.bar < 100
if forLong and fvg.bullish
hasConfluence := true
break
if not forLong and not fvg.bullish
hasConfluence := true
break
hasConfluence
bullishFVGPresent = f_hasFVGConfluence(true)
bearishFVGPresent = f_hasFVGConfluence(false)
// ═══════════════════════════════════════════════════════════════════════════════
// VOLUME CONFIRMATION
// ═══════════════════════════════════════════════════════════════════════════════
avgVol = ta.sma(volume, 20)
highVolume = volume > avgVol * 1.2
volumeOK = not requireVolume or highVolume
// ═══════════════════════════════════════════════════════════════════════════════
// BREAKOUT DETECTION
// ═══════════════════════════════════════════════════════════════════════════════
// Breakout conditions
breakoutUp = orComplete and not brokenUp and close > orHigh and close[1] <= orHigh
breakoutDown = orComplete and not brokenDown and close < orLow and close[1] >= orLow
// Track breakouts
if breakoutUp
brokenUp := true
if breakoutDown
brokenDown := true
// ═══════════════════════════════════════════════════════════════════════════════
// RETEST DETECTION (for retest entry type)
// ═══════════════════════════════════════════════════════════════════════════════
var bool waitingForLongRetest = false
var bool waitingForShortRetest = false
// Start waiting for retest after breakout
if breakoutUp and entryType == "Retest"
waitingForLongRetest := true
if breakoutDown and entryType == "Retest"
waitingForShortRetest := true
// Retest conditions
longRetest = waitingForLongRetest and low <= orHigh and close > orHigh
shortRetest = waitingForShortRetest and high >= orLow and close < orLow
// Reset retest waiting
if longRetest
waitingForLongRetest := false
if shortRetest
waitingForShortRetest := false
// Cancel retest if price goes too far
if waitingForLongRetest and close < orMid
waitingForLongRetest := false
if waitingForShortRetest and close > orMid
waitingForShortRetest := false
// ═══════════════════════════════════════════════════════════════════════════════
// SIGNAL GENERATION
// ═══════════════════════════════════════════════════════════════════════════════
var int lastSignalBar = 0
var bool tradedLongToday = false
var bool tradedShortToday = false
// Reset daily trade tracking
if newDay
tradedLongToday := false
tradedShortToday := false
// Check FVG requirement
fvgOKLong = not requireFVG or bullishFVGPresent
fvgOKShort = not requireFVG or bearishFVGPresent
// Entry timing
validTiming = inTradingHours and bar_index - lastSignalBar >= 5
// LONG SIGNAL
longEntry = false
if entryType == "Breakout"
longEntry := breakoutUp and volumeOK and fvgOKLong and validTiming and not tradedLongToday
else
longEntry := longRetest and volumeOK and fvgOKLong and validTiming and not tradedLongToday
// SHORT SIGNAL
shortEntry = false
if entryType == "Breakout"
shortEntry := breakoutDown and volumeOK and fvgOKShort and validTiming and not tradedShortToday
else
shortEntry := shortRetest and volumeOK and fvgOKShort and validTiming and not tradedShortToday
// Only show signals if enabled
buySignal = showSignals and longEntry
sellSignal = showSignals and shortEntry
if buySignal
lastSignalBar := bar_index
tradedLongToday := true
if sellSignal
lastSignalBar := bar_index
tradedShortToday := true
// ═══════════════════════════════════════════════════════════════════════════════
// STOP LOSS & TAKE PROFIT
// ═══════════════════════════════════════════════════════════════════════════════
var float entryPrice = na
var float stopLoss = na
var float takeProfit = na
if buySignal and orComplete
entryPrice := close
if slType == "Opposite Side"
stopLoss := orLow - atr * 0.1
else if slType == "Midpoint"
stopLoss := orMid - atr * 0.1
else
stopLoss := close - atr * 1.5
riskAmt = entryPrice - stopLoss
takeProfit := entryPrice + (riskAmt * rrRatio)
if sellSignal and orComplete
entryPrice := close
if slType == "Opposite Side"
stopLoss := orHigh + atr * 0.1
else if slType == "Midpoint"
stopLoss := orMid + atr * 0.1
else
stopLoss := close + atr * 1.5
riskAmt = stopLoss - entryPrice
takeProfit := entryPrice - (riskAmt * rrRatio)
// ═══════════════════════════════════════════════════════════════════════════════
// PERFORMANCE TRACKING
// ═══════════════════════════════════════════════════════════════════════════════
type TradeRecord
float entry
float sl
float tp
bool isLong
int bar
bool closed
bool won
var array<TradeRecord> trades = array.new<TradeRecord>()
var array<bool> results = array.new<bool>()
var float winRate = 0.0
var int totalWins = 0
var int totalLosses = 0
if buySignal or sellSignal
t = TradeRecord.new()
t.entry := entryPrice
t.sl := stopLoss
t.tp := takeProfit
t.isLong := buySignal
t.bar := bar_index
t.closed := false
t.won := false
if array.size(trades) >= 50
array.shift(trades)
array.push(trades, t)
if array.size(trades) > 0
for i = array.size(trades) - 1 to 0
if i < array.size(trades)
t = array.get(trades, i)
if not t.closed and bar_index > t.bar
won = false
lost = false
if t.isLong
if low <= t.sl
lost := true
else if high >= t.tp
won := true
else if bar_index - t.bar > 80
won := close > t.entry
lost := not won
else
if high >= t.sl
lost := true
else if low <= t.tp
won := true
else if bar_index - t.bar > 80
won := close < t.entry
lost := not won
if won or lost
t.closed := true
t.won := won
if won
totalWins := totalWins + 1
else
totalLosses := totalLosses + 1
if array.size(results) >= 50
array.shift(results)
array.push(results, won)
if array.size(results) > 0
wins = 0
for i = 0 to array.size(results) - 1
if array.get(results, i)
wins := wins + 1
winRate := (wins / array.size(results)) * 100
if array.size(trades) > 0
for i = array.size(trades) - 1 to 0
if i < array.size(trades)
t = array.get(trades, i)
if t.closed
array.remove(trades, i)
// ═══════════════════════════════════════════════════════════════════════════════
// VISUALIZATION
// ═══════════════════════════════════════════════════════════════════════════════
bullColor = #00E676
bearColor = #FF5252
orbColor = #2196F3
fvgBullColor = color.new(#00E676, 85)
fvgBearColor = color.new(#FF5252, 85)
// Draw Opening Range Box
var box orBox = na
if showORBox and orComplete and not na(orStartBar)
box.delete(orBox)
orBox := box.new(orStartBar, orHigh, bar_index + 20, orLow,
border_color=orbColor, border_width=2,
bgcolor=color.new(orbColor, 90))
// Draw OR levels extending right
var line orHighLine = na
var line orLowLine = na
var line orMidLine = na
if orComplete
line.delete(orHighLine)
line.delete(orLowLine)
line.delete(orMidLine)
orHighLine := line.new(orEndBar, orHigh, bar_index + 50, orHigh,
color=bullColor, style=line.style_solid, width=2)
orLowLine := line.new(orEndBar, orLow, bar_index + 50, orLow,
color=bearColor, style=line.style_solid, width=2)
orMidLine := line.new(orEndBar, orMid, bar_index + 50, orMid,
color=color.gray, style=line.style_dotted, width=1)
// Draw FVG boxes
if showFVG and array.size(fvgArray) > 0
for i = math.max(0, array.size(fvgArray) - 5) to array.size(fvgArray) - 1
fvg = array.get(fvgArray, i)
if not fvg.filled and bar_index - fvg.bar < 50
fvgCol = fvg.bullish ? fvgBullColor : fvgBearColor
box.new(fvg.bar, fvg.top, bar_index + 10, fvg.bottom,
border_color=na, bgcolor=fvgCol)
// Draw Signals
if buySignal
labelText = "🎯 LONG\nORB Break"
if requireFVG and bullishFVGPresent
labelText := labelText + "\n+FVG ✓"
label.new(bar_index, low - atr * 0.5,
text=labelText,
style=label.style_label_up,
color=color.new(bullColor, 20),
textcolor=color.white,
size=size.normal)
line.new(bar_index, stopLoss, bar_index + 30, stopLoss, color=color.new(bearColor, 50), width=1, style=line.style_dashed)
line.new(bar_index, takeProfit, bar_index + 30, takeProfit, color=color.new(bullColor, 50), width=1, style=line.style_dashed)
label.new(bar_index + 30, stopLoss, "SL", style=label.style_label_left, color=color.new(bearColor, 80), textcolor=bearColor, size=size.tiny)
label.new(bar_index + 30, takeProfit, "TP", style=label.style_label_left, color=color.new(bullColor, 80), textcolor=bullColor, size=size.tiny)
if sellSignal
labelText = "🎯 SHORT\nORB Break"
if requireFVG and bearishFVGPresent
labelText := labelText + "\n+FVG ✓"
label.new(bar_index, high + atr * 0.5,
text=labelText,
style=label.style_label_down,
color=color.new(bearColor, 20),
textcolor=color.white,
size=size.normal)
line.new(bar_index, stopLoss, bar_index + 30, stopLoss, color=color.new(bearColor, 50), width=1, style=line.style_dashed)
line.new(bar_index, takeProfit, bar_index + 30, takeProfit, color=color.new(bullColor, 50), width=1, style=line.style_dashed)
label.new(bar_index + 30, stopLoss, "SL", style=label.style_label_left, color=color.new(bearColor, 80), textcolor=bearColor, size=size.tiny)
label.new(bar_index + 30, takeProfit, "TP", style=label.style_label_left, color=color.new(bullColor, 80), textcolor=bullColor, size=size.tiny)
// ═══════════════════════════════════════════════════════════════════════════════
// DASHBOARD
// ═══════════════════════════════════════════════════════════════════════════════
if showDashboard and barstate.islast
// Status
orbStatus = orComplete ? "✅ COMPLETE" : inOpeningRange ? "⏳ FORMING" : "❌ WAITING"
breakStatus = brokenUp ? "🟢 LONG" : brokenDown ? "🔴 SHORT" : "⚪ NONE"
fvgStatus = bullishFVGPresent ? "🟢 BULL" : bearishFVGPresent ? "🔴 BEAR" : "⚪ NONE"
volStatus = highVolume ? "🟢 HIGH" : "⚪ NORMAL"
// Range info
rangeText = orComplete ? str.tostring(orRange, "#.##") : "--"
rangeATR = orComplete and not na(atr) ? str.tostring(orRange / atr, "#.#") + "x ATR" : "--"
dashText = "═══ NEURAEDGE ORB ═══\n"
dashText := dashText + "TF: " + timeframe.period + "\n"
dashText := dashText + "──────────────────────\n"
dashText := dashText + "OR Status: " + orbStatus + "\n"
if orComplete
dashText := dashText + "OR High: " + str.tostring(orHigh, "#.##") + "\n"
dashText := dashText + "OR Low: " + str.tostring(orLow, "#.##") + "\n"
dashText := dashText + "Range: " + rangeText + " (" + rangeATR + ")\n"
dashText := dashText + "──────────────────────\n"
dashText := dashText + "Breakout: " + breakStatus + "\n"
dashText := dashText + "FVG: " + fvgStatus + "\n"
dashText := dashText + "Volume: " + volStatus + "\n"
dashText := dashText + "──────────────────────\n"
dashText := dashText + "Entry: " + entryType + "\n"
dashText := dashText + "R:R: " + str.tostring(rrRatio, "#.#") + "\n"
dashText := dashText + "SL: " + slType + "\n"
dashText := dashText + "──────────────────────\n"
if array.size(results) > 0
dashText := dashText + "📈 Win Rate: " + str.tostring(winRate, "#.#") + "%\n"
dashText := dashText + "W/L: " + str.tostring(totalWins) + "/" + str.tostring(totalLosses) + "\n"
else
dashText := dashText + "📈 No trades yet\n"
dashText := dashText + "══════════════════════"
var table dashboard = table.new(position.top_right, 1, 1, bgcolor=color.new(color.black, 85))
table.cell(dashboard, 0, 0, text=dashText, text_color=color.white, text_size=size.small)
// ═══════════════════════════════════════════════════════════════════════════════
// ALERTS
// ═══════════════════════════════════════════════════════════════════════════════
alertcondition(orComplete and not orComplete[1], title="Opening Range Complete", message="15-Min Opening Range Complete! High: {{plot_0}} Low: {{plot_1}}")
alertcondition(buySignal, title="ORB Long Signal", message="ORB LONG Breakout Signal!")
alertcondition(sellSignal, title="ORB Short Signal", message="ORB SHORT Breakout Signal!")
alertcondition(breakoutUp, title="Breakout Up", message="Price broke above Opening Range!")
alertcondition(breakoutDown, title="Breakout Down", message="Price broke below Opening Range!")
// Plot for alerts
plot(orHigh, "OR High", display=display.none)
plot(orLow, "OR Low", display=display.none)