本页源码来自 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/
// © UKUTA
//@version=5
indicator("Opening Range Breakout [UkutaLabs]", overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
//#region OPENING RANGE BREAKOUT
bool show_labels = input(true,title="Show Labels",group="Configuration")
string load_period = input.string(defval="All", title="Display Mode", options=["Hidden", "Today", "Two Days", "Week", "All"], group="Configuration")
bool orb_enabled_15m = input(true, title="15 Minute", group="Range Settings")
color orb_15m_color = input(color.rgb(33, 149, 243), title="15 Minute Color", group="Range Settings")
bool orb_enabled_30m = input(false, title="30 Minute", group="Range Settings")
color orb_30m_color = input(color.rgb(155, 39, 176), title="30 Minute Color", group="Range Settings")
var int orb_mo_bar = 0
var bool orb_market_open = false
var float orb_15m_high = 0
var float orb_15m_low = 0
var float recent_15m_orb_high = 0
var float recent_15m_orb_low = 0
var orb_15m_boxes = array.new<box>(10)
var orb_15m_lines = array.new<line>(10)
var orb_15m_labels = array.new<box>(20)
var float orb_30m_high = 0
var float orb_30m_low = 0
var float recent_30m_orb_high = 0
var float recent_30m_orb_low = 0
var orb_30m_boxes = array.new<box>(10)
var orb_30m_lines = array.new<line>(10)
var orb_30m_labels = array.new<box>(20)
var int timeperhour = 3600000
deleteItems(int a) =>
if array.size(orb_15m_boxes)>a
for int i = a-1 to array.size(orb_15m_boxes)-(a+1)
box.delete(array.get(orb_15m_boxes,i))
if array.size(orb_15m_labels)>a*2 and show_labels
for int i = a-1 to array.size(orb_15m_labels)-(a*2+1)
box.delete(array.get(orb_15m_labels,i))
if array.size(orb_15m_lines)>a*3
for int i = a-1 to array.size(orb_15m_lines)-(a*3+1)
line.delete(array.get(orb_15m_lines,i))
if array.size(orb_30m_boxes)>a
for int i = a-1 to array.size(orb_30m_boxes)-(a+1)
box.delete(array.get(orb_30m_boxes,i))
if array.size(orb_30m_labels)>a*2 and show_labels
for int i = a-1 to array.size(orb_30m_labels)-(a*2+1)
box.delete(array.get(orb_30m_labels,i))
if array.size(orb_30m_lines)>a*3
for int i = a-1 to array.size(orb_30m_lines)-(a*3+1)
line.delete(array.get(orb_30m_lines,i))
if dayofmonth(syminfo.type=="futures" ? 55800000+time: time) != dayofmonth(syminfo.type=="futures" ? 55800000+time: time)[1] and dayofweek!=dayofweek.sunday
orb_mo_bar := bar_index
recent_15m_orb_high := timeframe.isminutes and str.tonumber(timeframe.period)<=15 ? ta.highest(int(15/str.tonumber(timeframe.period))) : na
recent_15m_orb_low := timeframe.isminutes and str.tonumber(timeframe.period)<=15 ? ta.lowest(int(15/str.tonumber(timeframe.period))) : na
recent_30m_orb_high := timeframe.isminutes and str.tonumber(timeframe.period)<=30 ? ta.highest(int(30/str.tonumber(timeframe.period))) : na
recent_30m_orb_low := timeframe.isminutes and str.tonumber(timeframe.period)<=30 ? ta.lowest(int(30/str.tonumber(timeframe.period))) : na
if orb_enabled_15m and load_period!="Hidden"
if dayofmonth(syminfo.type=="futures" ? 28800000+time: time) != dayofmonth(syminfo.type=="futures" ? 28800000+time: time)[1]
orb_market_open := false
else if bar_index-orb_mo_bar==(15/str.tonumber(timeframe.period))-1
orb_market_open := true
array.push(orb_15m_boxes, box.new(orb_mo_bar, recent_15m_orb_high, bar_index, recent_15m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.new(orb_15m_color,50)))
array.push(orb_15m_lines, line.new(orb_mo_bar, recent_15m_orb_high, bar_index, recent_15m_orb_high, color=orb_15m_color, style=line.style_dashed, width=1))
array.push(orb_15m_lines, line.new(orb_mo_bar, recent_15m_orb_high-(0.5*(recent_15m_orb_high-recent_15m_orb_low)), bar_index, recent_15m_orb_high-(0.5*(recent_15m_orb_high-recent_15m_orb_low)), color=orb_15m_color, style=line.style_dotted, width=1))
array.push(orb_15m_lines, line.new(orb_mo_bar, recent_15m_orb_low, bar_index, recent_15m_orb_low, color=orb_15m_color, style=line.style_dashed, width=1))
if show_labels
array.push(orb_15m_labels, box.new(orb_mo_bar, recent_15m_orb_high, bar_index, recent_15m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.rgb(33, 149, 243, 100), text="15 Minute ORB High", text_halign=text.align_right, text_valign=text.align_top, text_color=orb_15m_color, text_size=size.small))
array.push(orb_15m_labels, box.new(orb_mo_bar, recent_15m_orb_high, bar_index, recent_15m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.rgb(33, 149, 243, 100), text="15 Minute ORB Low", text_halign=text.align_right, text_valign=text.align_bottom, text_color=orb_15m_color, text_size=size.small))
if orb_market_open == true
for int i = 1 to 3
line.set_x2(array.get(orb_15m_lines, array.size(orb_15m_lines)-i), bar_index)
if show_labels
for int i = 1 to 2
box.set_right(array.get(orb_15m_labels, array.size(orb_15m_labels)-i), bar_index)
if orb_enabled_30m and load_period!="Hidden"
if dayofmonth(syminfo.type=="futures" ? 28800000+time: time) != dayofmonth(syminfo.type=="futures" ? 28800000+time: time)[1]
orb_market_open := false
else if bar_index-orb_mo_bar==(30/str.tonumber(timeframe.period))-1
orb_market_open := true
array.push(orb_30m_boxes, box.new(orb_mo_bar, recent_30m_orb_high, bar_index, recent_30m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.new(orb_30m_color,50)))
array.push(orb_30m_lines, line.new(orb_mo_bar, recent_30m_orb_high, bar_index, recent_30m_orb_high, color=orb_30m_color, style=line.style_dashed, width=1))
array.push(orb_30m_lines, line.new(orb_mo_bar, recent_30m_orb_high-(0.5*(recent_30m_orb_high-recent_30m_orb_low)), bar_index, recent_30m_orb_high-(0.5*(recent_30m_orb_high-recent_30m_orb_low)), color=orb_30m_color, style=line.style_dotted, width=1))
array.push(orb_30m_lines, line.new(orb_mo_bar, recent_30m_orb_low, bar_index, recent_30m_orb_low, color=orb_30m_color, style=line.style_dashed, width=1))
if show_labels
array.push(orb_30m_labels, box.new(orb_mo_bar, recent_30m_orb_high, bar_index, recent_30m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.rgb(33, 149, 243, 100), text="30 Minute ORB High", text_halign=text.align_right, text_valign=text.align_top, text_color=orb_30m_color, text_size=size.small))
array.push(orb_30m_labels, box.new(orb_mo_bar, recent_30m_orb_high, bar_index, recent_30m_orb_low, color.rgb(33, 149, 243, 100), bgcolor=color.rgb(33, 149, 243, 100), text="30 Minute ORB Low", text_halign=text.align_right, text_valign=text.align_bottom, text_color=orb_30m_color, text_size=size.small))
if orb_market_open == true
for int i = 1 to 3
line.set_x2(array.get(orb_30m_lines, array.size(orb_30m_lines)-i), bar_index)
if show_labels
for int i = 1 to 2
box.set_right(array.get(orb_30m_labels, array.size(orb_30m_labels)-i), bar_index)
if load_period == "Today"
deleteItems(1)
else if load_period == "Two Days"
deleteItems(2)
else if load_period == "Week"
deleteItems(5)
//#endregion OPENING RANGE BREAKOUT