Opening Range Breakout

jdraket · study · 48 行 · 点赞 440 · 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/
// © jdraket
 
//@version=6
indicator('Opening Range Breakout', overlay = true)
 
// inputs
or_sess = input.session('0930-0945', title = 'Opening Range Start/Stop Time')
orb_sess = input.session('0945-1430', title = 'Opening Range Breakout Start/Stop Time')
ema_len = input.int(3, minval=1, title="EMA Length")
src_ema = input(close, title="Source for EMA")
 
or_t = time(timeframe.period, or_sess + ':1234567')
orb_t = time(timeframe.period, orb_sess + ':1234567')
plot_true = timeframe.isintraday
 
in_or_sess = time == or_t ? true : false
in_orb_sess = time == orb_t ? true : false
 
var or_high = 0.0
var or_low = 10000.0
 
if in_or_sess
    if not in_or_sess[1]
        or_high := high
        or_low := low
    else
        or_high := math.max(high,or_high)
        or_low := math.min(low,or_low)
 
// plot the opening range
plot(plot_true ? or_high : na, style = plot.style_line, color = or_high[1] != or_high ? na : color.green, title = 'OR High', linewidth = 2)
plot(plot_true ? or_low : na, style = plot.style_line, color = or_low[1] != or_low ? na : color.red, title = 'OR Low', linewidth = 2)
 
// plot ema
the_ema = ta.ema(src_ema, ema_len)
plot(the_ema, title="EMA", color=#33a0e9, offset=0)
 
// are we breaking out of the opening reange?
break_out_above = in_orb_sess and the_ema > the_ema[1] and close > or_high and close > the_ema and the_ema > or_high
break_out_below = in_orb_sess and the_ema < the_ema[1] and close < or_low and close < the_ema and the_ema < or_low
 
// alerts
alertcondition(break_out_above, title = 'Bullish ORB', message = 'Bullish ORB')
alertcondition(break_out_below, title = 'Bearish ORB', message = 'Bearish ORB')
 
// pine logs
log.info("close {0}, ema {1}, or_high {2}, or_low {3}, break_out_above {4}, break_out_below {5}, in_or_sess {6}, in_orb_sess {7}",close,the_ema,or_high,or_low,break_out_above,break_out_below,in_or_sess,in_orb_sess)

← 返回列表