OPEN-SOURCE SCRIPT

15 min orb

73
//version=5
strategy("15min ORB Retest Strategy", overlay=true, default_qty_type=strategy.fixed, default_qty_value=2, initial_capital=50000, commission_type=strategy.commission.cash_per_contract, commission_value=2.50)

// ========== INPUTS ==========
entryLevel = input.string("Top/Bottom", "Entry Level", options=["Top/Bottom", "Midpoint"])
stopPoints = input.float(5.0, "Stop Loss (Points)", minval=0.1)
tpPoints = input.float(10.0, "Take Profit (Points)", minval=0.1)

// ========== TIME SETTINGS (Mountain Time = UTC-7 or UTC-6 depending on DST) ==========
// TradingView uses UTC, so adjust based on your MT offset
// For simplicity, using session strings. Adjust if needed for DST.
orbSession = "0600-0615:1234567" // 6:00-6:15 AM MT (adjust UTC offset as needed)
tradeSession = "0700-0730:1234567" // 7:00-7:30 AM MT

// ========== ORB BOX CALCULATION ==========
var float boxHigh = na
var float boxLow = na
var float boxMid = na
var bool boxSet = false
var bool tradeToday = false
var bool breakoutUp = false
var bool breakoutDown = false

// Detect ORB session (6:00-6:15 AM MT)
inOrbSession = not na(time(timeframe.period, orbSession, "America/Denver"))

if inOrbSession and not boxSet
boxHigh := high
boxLow := low
boxSet := true
else if inOrbSession and boxSet
boxHigh := math.max(boxHigh, high)
boxLow := math.min(boxLow, low)

// Calculate midpoint
if not na(boxHigh) and not na(boxLow)
boxMid := (boxHigh + boxLow) / 2

// Reset daily
if ta.change(time('D'))
boxSet := false
tradeToday := false
breakoutUp := false
breakoutDown := false
boxHigh := na
boxLow := na
boxMid := na

// ========== DRAW BOX ==========
var line topLine = na
var line bottomLine = na
var line midLine = na

if boxSet and not na(boxHigh)
if na(topLine)
topLine := line.new(bar_index, boxHigh, bar_index + 1, boxHigh, color=color.green, width=2)
bottomLine := line.new(bar_index, boxLow, bar_index + 1, boxLow, color=color.red, width=2)
midLine := line.new(bar_index, boxMid, bar_index + 1, boxMid, color=color.gray, width=1, style=line.style_dashed)
else
line.set_x2(topLine, bar_index)
line.set_x2(bottomLine, bar_index)
line.set_x2(midLine, bar_index)

// ========== BREAKOUT DETECTION ==========
inTradeSession = not na(time(timeframe.period, tradeSession, "America/Denver"))

// Breakout = 1m close outside box
if boxSet and not na(boxHigh) and not breakoutUp and not breakoutDown
if close > boxHigh
breakoutUp := true
if close < boxLow
breakoutDown := true

// ========== MIDPOINT INVALIDATION (with re-setup) ==========
if breakoutUp and close < boxMid
breakoutUp := false // Allow re-setup

if breakoutDown and close > boxMid
breakoutDown := false // Allow re-setup

// ========== RETEST & ENTRY LOGIC ==========
longCondition = false
shortCondition = false

if boxSet and inTradeSession and not tradeToday
// LONG: breakout up, retest top or midpoint
if breakoutUp
if entryLevel == "Top/Bottom" and close <= boxHigh and close >= boxHigh - 0.25
longCondition := true
if entryLevel == "Midpoint" and close <= boxMid and close >= boxMid - 0.25
longCondition := true

// SHORT: breakout down, retest bottom or midpoint
if breakoutDown
if entryLevel == "Top/Bottom" and close >= boxLow and close <= boxLow + 0.25
shortCondition := true
if entryLevel == "Midpoint" and close >= boxMid and close <= boxMid + 0.25
shortCondition := true

// ========== EXECUTE TRADES ==========
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("TP/SL", "Long", stop=close - stopPoints, limit=close + tpPoints)
tradeToday := true

if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("TP/SL", "Short", stop=close + stopPoints, limit=close - tpPoints)
tradeToday := true

// ========== PLOT SIGNALS ==========
plotshape(longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Long Entry")
plotshape(shortCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Short Entry")

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.