# Watchlist ORB Status
# Mobius
# V01 using getTIme()
# Note: Column Aggregation MUST be 30min or less
# Pensar - 07/06/2020 - modified to count bars above/below Opening Range
# - 07/31/2020 - changed code to use plot instead of AddLabel
# so that column can be sorted numerically
# The input below will show the bar count when inside the Opening Range
# if set to "yes", otherwise it will display "NaN".
input show_inside_bar_count = yes;
def Active = getTime() >= RegularTradingStart(getYYYYMMDD()) and
getTime() <= RegularTradingStart(getYYYYMMDD()) +
AggregationPeriod.Thirty_Min;
def hh = if Active and !Active[1] then high
else if Active and high > hh[1] then high
else hh[1];
def ll = if Active and !Active[1] then low
else if Active and low < ll[1] then low
else ll[1];
def current = if between(close, ll, hh) then 0
else if close > hh then 1
else if close < ll then -1
else double.nan;
def n1 = current == 1;
def n2 = current == -1;
def n3 = current == 0;
def count_up = if n1 and !n1[1] then 1 else count_up[1]+1;
def count_dn = if n2 and !n2[1] then 1 else count_dn[1]+1;
def count_in = if show_inside_bar_count then
if n3 and !n3[1] then 1
else count_in[1]+1
else double.nan;
plot Number = if n1 then count_up
else if n2 then count_dn
else count_in;
Number.AssignValueColor(if n1 then color.green
else if n2 then color.red
else color.yellow);
AssignBackgroundColor(if n1 then createColor(51,102,0)
else if n2 then createColor(155,0,0)
else createColor(180,180,5));
# End Code ORB Status