Previous Day Opening Range Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This indicator displays the previous day 30min Opening Range high and low on today's chart rather than using the first 30 min range of the current day. I found it interesting considering that ORB is quite popular on this forum.

By default, it will show the 30-minute range. But you can adjust that by changing the value for `input begin` and `input end`.





thinkScript Code
Rich (BB code):
#Example_PreviousDaysOpeningRange-option_to_each_extended_thru_expansion
#20181120 - sleepyzzzz
#Example Opening RangeBands Highs/Lows from previous days, shown on next day, with option to extend from each day through the right expansion

script philow {
    input begin   = 0930;
    input end     = 1000;
    input end_day = 1600;
    input extend_lines_to_today = no;
    input n = 1;
    def ymd = GetYYYYMMDD();
    def ok = !IsNaN(close);
    def capture = ok and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture 
                                    then dayCount[1] + 1 
                                    else dayCount[1], 0);
    def thisDay = (HighestAll(dayCount) - dayCount) ;
    def hh = CompoundValue(1, if thisDay == n and SecondsFromTime(begin) == 0 
                              then high
                              else if thisDay == n and  high > hh[1] and SecondsTillTime(end) > 0
                              then high 
                              else hh[1] , high);
    def hhnan = if IsNaN(close) then hhnan[1] else hh;
    plot hhplot = if thisDay == n and SecondsFromTime(begin) < 0 
                  then Double.NaN 
                  else if extend_lines_to_today == yes  and thisDay <= n - 1 then if thisDay == n - 1 and SecondsFromTime(begin) < 0 then Double.NaN 
                  else hhnan
                  else if thisDay == n - 1 and SecondsFromTime(begin) >= 0 and SecondsTillTime(end_day) > 0
                  then hh
                  else Double.NaN;

    def ll = CompoundValue(1, if thisDay == n and SecondsFromTime(begin) == 0
                              then low
                              else if  thisDay == n and low < ll[1] and SecondsTillTime(end) > 0
                              then low
                              else ll[1] , low);
    def llnan   = if IsNaN(ll) then llnan[1] else ll;
    plot llplot = if thisDay == n and SecondsFromTime(begin) < 0
                  then Double.NaN 
                  else if extend_lines_to_today == yes and thisDay <= n - 1 then if thisDay == n - 1 and SecondsFromTime(begin) < 0 then Double.NaN 
                  else llnan
                  else if thisDay == n - 1 and SecondsFromTime(begin) >= 0 and SecondsTillTime(end_day) > 0
                  then ll
                  else Double.NaN;
}

#Plots of Highs/Lows based upon script...add more days using similar plot statements, increasing the value by 1
input extend_lines_to_today = no;
input begin   = 0930;
input end     = 0935;
input end_day = 1600;
plot H1 = philow(begin, end, end_day, extend_lines_to_today, n = 1);
plot H2 = philow(begin, end, end_day, extend_lines_to_today, n = 2);
plot H3 = philow(begin, end, end_day, extend_lines_to_today, n = 3);
plot H4 = philow(begin, end, end_day, extend_lines_to_today, n = 4);
plot H5 = philow(begin, end, end_day, extend_lines_to_today, n = 5);
plot H6 = philow(begin, end, end_day, extend_lines_to_today, n = 6);

plot L1 = philow(begin, end, end_day, extend_lines_to_today, n = 1).llplot;
plot L2 = philow(begin, end, end_day, extend_lines_to_today, n = 2).llplot;
plot L3 = philow(begin, end, end_day, extend_lines_to_today, n = 3).llplot;
plot L4 = philow(begin, end, end_day, extend_lines_to_today, n = 4).llplot;
plot L5 = philow(begin, end, end_day, extend_lines_to_today, n = 5).llplot;
plot L6 = philow(begin, end, end_day, extend_lines_to_today, n = 6).llplot;

H1.setdefaultColor(color.green);
H2.setdefaultColor(color.green);
H3.setdefaultColor(color.green);
H4.setdefaultColor(color.green);
H5.setdefaultColor(color.green);
H6.setdefaultColor(color.green);

L1.setdefaultColor(color.red);
L2.setdefaultColor(color.red);
L3.setdefaultColor(color.red);
L4.setdefaultColor(color.red);
L5.setdefaultColor(color.red);
L6.setdefaultColor(color.red);
Shareable Link
http://tos.mx/IoiQCn

Credit:

 
Last edited:

Top