Opening Range Breakout (ORB)

BlackJackOptionsTrades · study · 62 行 · 点赞 480 · 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/
// © nickkrause1998
 
//@version=6
indicator("Opening Range Breakout (ORB)", overlay=true)
 
// Define session times for NYSE market open
startSession = timestamp(year, month, dayofmonth, 9, 30)  // 9:30 AM EST
endSession = timestamp(year, month, dayofmonth, 10, 00)   // 10:00 AM EST
 
// Ensure `isNewDay` is a valid boolean
isNewDay = ta.change(dayofmonth) != 0
 
// Variables to store ORB high/low for the **current day only**
var float openingHigh = na
var float openingLow = na
var bool sessionComplete = false
 
// Reset ORB values at the start of a new day
if isNewDay
    openingHigh := na
    openingLow := na
    sessionComplete := false
 
// Capture high and low during the first 30 minutes (9:30 - 10:00 AM)
if (not na(time) and time >= startSession and time < endSession)
    openingHigh := na(openingHigh) ? high : math.max(openingHigh, high)
    openingLow := na(openingLow) ? low : math.min(openingLow, low)
 
// Ensure the ORB lines are only drawn for the **current day**
plot(openingHigh, title="Opening High", color=color.green, linewidth=2)
plot(openingLow, title="Opening Low", color=color.red, linewidth=2)
 
// Buy/Sell Conditions
crossAboveHigh = ta.crossover(close, openingHigh)
crossBelowHigh = ta.crossunder(close, openingHigh)
crossBelowLow = ta.crossunder(close, openingLow)
crossAboveLow = ta.crossover(close, openingLow)
 
// Ensure signals only appear **once per breakout**
var bool wasAboveHigh = false
var bool wasBelowLow = false
 
buySignal = crossAboveHigh and not wasAboveHigh
sellSignal = crossBelowLow and not wasBelowLow
 
// Reset after a retrace
if crossBelowHigh
    wasAboveHigh := true
if crossAboveLow
    wasBelowLow := true
 
if ta.barssince(crossBelowHigh) > 2
    wasAboveHigh := false
if ta.barssince(crossAboveLow) > 2
    wasBelowLow := false
 
// Plot Buy/Sell Signals
if buySignal
    label.new(bar_index, close, "BUY", color=color.green, size=size.small, textcolor=color.white)
if sellSignal
    label.new(bar_index, close, "SELL", color=color.red, size=size.small, textcolor=color.white)

← 返回列表