Opening Range

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

The Opening Range / First Bar By Market Mindset - Zero To Endles by marketmindset

copy

// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © marketmindset
//@version=5
indicator("The Opening Range / First Bar By Market Mindset"
, "ORB - Z2E", true
, max_lines_count=500
, max_labels_count = 500)
//---------------------------------------------------------------------------------
----------------
// Constants / Strings
//---------------------------------------------------------------------------------
----------------
AUTO = "Auto"
DAILY = "Daily"
WEEKLY = "Weekly"
MONTHLY = "Monthly"
QUARTERLY = "Quarterly"
HALFYEARLY = "Half Yearly"
YEARLY = "Yearly"

//---------------------------------------------------------------------------------
----------------
// Inputs
//---------------------------------------------------------------------------------
----------------
res = input.string( AUTO , "Resolution" , options=[AUTO, DAILY, WEEKLY,
MONTHLY, QUARTERLY, HALFYEARLY, YEARLY])
timeframe = input.timeframe( "" , "Timeframe", tooltip = "A timeframe higher
than or equls to the chart timeframe is recommended.")
midLine = input.bool( true, "Show Midline")
hist = input.bool( false, "Show Historical Ranges")

showL = input.bool( true , "Show Labels" , inline = "Labels", group =


"Style")
showP = input.bool( false , "Show Prices" , inline = "Labels", group =
"Style")
pos = input.string("Left", "Position", options = ["Left", "Right"] ,
group = "Style")

boxStyle = input.string("──────" , "Range : ", options = ["──────", "─ ─ ─ ─",


"· · · · · ·"] , inline = "Box" , group = "Style")
lineStyle = input.string("─ ─ ─ ─" , "MidLine : ", options = ["──────", "─ ─
─ ─", "· · · · · ·"] , inline = "Line" , group = "Style")
borderWidth = input.int( 1 , ' / ' , 1 , 10 , inline = "Box" , group =
"Style")
lineWidth = input.int( 1 , ' / ' , 1 , 10 , inline = "Line" , group =
"Style")
_color = input.color(color.lime, "Color : " , inline = "Color" , group =
"Style")
__color = input.color(color.lime, "Color : " , inline = "Color" , group =
"Style")
_fillcolor = input.color(color.new(color.lime,85), " / " , inline = "Color" ,
group = "Style")
//---------------------------------------------------------------------------------
----------------
// Functions /Calculations
//---------------------------------------------------------------------------------
----------------
get_style(style) =>
switch style
"──────" => line.style_solid
"─ ─ ─ ─" => line.style_dashed
"· · · · · ·" => line.style_dotted

get_auto_resolution() =>
resolution = '12M'
if timeframe.isintraday
resolution := timeframe.multiplier <= 15 ? 'D' : 'W'
else if timeframe.isdaily
resolution := 'M'
resolution

resolution = switch res


AUTO => get_auto_resolution()
DAILY => "D"
WEEKLY => "W"
MONTHLY => "M"
QUARTERLY => "3M"
HALFYEARLY => "6M"
=> "12M"

if (resolution == "D" or resolution == "W") and timeframe.isdwm


runtime.error("Timeframe is higher than the resolution used.")

[newBar, end] = request.security(syminfo.tickerid, resolution , [time,


time_close], lookahead=barmerge.lookahead_on)
[H, L, M] = request.security(ticker.standard(syminfo.tickerid), timeframe ,
[high, low, hl2], lookahead=barmerge.lookahead_on)

start = time(resolution)
isNewPeriod = ta.change(newBar) != 0

_style = pos == "Left" ? label.style_label_right : label.style_label_left


x = pos == "Left" ? start : end

var line _mid = na


var line _top = na
var line _bot = na

//---------------------------------------------------------------------------------
----------------
// Outputs
//---------------------------------------------------------------------------------
----------------
draw_label(y, _txt) =>
_tmptxt = str.tostring(y, format.mintick)
var label _label = na

if (showL or showP) and isNewPeriod


display_text = (showL ? _txt : na) + (showP ? " (" + _tmptxt + ")": na)
_label := label.new(x,y, display_text, style = _style, color =
#00000000, textcolor = _color, xloc = xloc.bar_time, size = size.normal)
label.set_tooltip(_label, _txt + '\n' + str.tostring(y, format.mintick))
if not hist
label.delete(_label[1])

if isNewPeriod
_top := line.new(start, H, end, H, color = _color , style =
get_style(boxStyle), width=2, xloc = xloc.bar_time)
_bot := line.new(start, L, end, L, color = _color , style =
get_style(boxStyle), width=2, xloc = xloc.bar_time)
linefill.new(_top, _bot, _fillcolor)

if midLine
_mid := line.new(start, M, end, M, color = __color , style =
get_style(lineStyle), width=lineWidth, xloc = xloc.bar_time)

if not hist
line.delete(_top[1])
line.delete(_bot[1])
line.delete(_mid[1])

draw_label(H, "T")
draw_label(L, "B")
if midLine
draw_label(M, "M")

You might also like