Session Opening Range Breakout (ORBO)

PinegenAI · strategy · 76 行 · 点赞 192 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AIScripts
 
//@version=6
strategy("Session Opening Range Breakout (ORBO)",
     overlay           = true,
     initial_capital   = 100000,
     default_qty_type  = strategy.percent_of_equity,
     default_qty_value = 10,
     commission_type   = strategy.commission.percent,
     commission_value  = 0.01)
 
//──────────────────────────────
// Inputs
//──────────────────────────────
orSession = input.session("0930-0950", "Opening range session")
showRange = input.bool(true, "Show OR levels")
fillRange = input.bool(true, "Fill range body")
 
//──────────────────────────────
// Session & day detection
//──────────────────────────────
inSession = not na(time(timeframe.period, orSession))
isNewDay  = ta.change(time("D")) != 0
 
//──────────────────────────────
// Track Opening Range High / Low
//──────────────────────────────
var float orHigh = na
var float orLow  = na
 
// Reset OR levels at the start of a new day
if isNewDay
    orHigh := na
    orLow  := na
 
// Build opening range during the session
if inSession
    orHigh := na(orHigh) ? high : math.max(orHigh, high)
    orLow  := na(orLow)  ? low  : math.min(orLow, low)
 
//──────────────────────────────
// Breakout logic (after OR session ends)
//──────────────────────────────
sessionFinished = not inSession and not na(orHigh) and not na(orLow)
 
longBreak  = sessionFinished and ta.crossover(close, orHigh)
shortBreak = sessionFinished and ta.crossunder(close, orLow)
 
if longBreak
    strategy.entry("OR Long", strategy.long)
 
if shortBreak
    strategy.entry("OR Short", strategy.short)
 
//──────────────────────────────
// Visuals
//──────────────────────────────
plotOrHigh = plot(
     showRange ? orHigh : na,
     title = "OR High",
     color = color.new(color.green, 0),
     style = plot.style_linebr)
 
plotOrLow = plot(
     showRange ? orLow : na,
     title = "OR Low",
     color = color.new(color.red, 0),
     style = plot.style_linebr)
 
// Global-scope fill (required in Pine)
fillColor = showRange and fillRange ? color.new(color.yellow, 90) : na
fill(plotOrHigh, plotOrLow, fillColor)
 
// Highlight while OR is being built
bgcolor(inSession ? color.new(color.yellow, 92) : na)

← 返回列表