Opening Range (ORB) Watchlist Column for ThinkorSwim

H

HighBredCloud

Well-known member
VIP
@HighBredCloud Interesting idea. @diazlaz and I were talking about this last week. Going to tag him in here just in case he has a watchlist column for that.
IF anyone could do something like this I know he'd be more than fully capable if his time permits. This would be the best way to search for stocks ABOVE or BELOW the ORB that are generated from the scanner and are in the watchlist if you can see the bar count of how many bars are ABOVE or BELOW the ORB...sorting it would allow you to get in at bar 1 that would indicate the most recent cross ABOVE or BELOW ORB such as a reversal or pull back...or bar 100+ that would indicate a steady trend in a given direction of the ORB...
 
P

Pensar

Member
VIP
@BenTen @HighBredCloud I don't wish to barge in, but earlier this month I added a count to Mobius' ORB watchlist column, but was still using the original AddLabel function. After seeing your comments here I realized that it was a wise idea to use the plot function instead. Here's my modified watchlist code that I changed to use plot instead of AddLabel.

Code:
# 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
 
Last edited:
H

HighBredCloud

Well-known member
VIP
@Pensar Thank You! Looking at it now in after hours market...Everything seem to be GOOD...I did notice that some stocks come up with NaN...this could be because the market is closed and it just didn't update...The rest of it seems to plot correctly...I can't wait to test this out in a live market...This will be a great way to sort through the results in a watchlist.
 
P

Pensar

Member
VIP
@HighBredCloud I run it at a 5 min aggregation with extended hours unchecked on the watchlist column. I've not noticed any problems, but if I do I'll be sure to post. :)
 
H

HighBredCloud

Well-known member
VIP
@HighBredCloud I run it at a 5 min aggregation with extended hours unchecked on the watchlist column. I've not noticed any problems, but if I do I'll be sure to post. :)
I just unchecked the extended hours...and still the same thing...it must be because the market is closed...BUT here is what I am referring to on my end...just incase take a look at the stocks with the NaN on your end to see if you get the same thing as I do...


I am further looking into the stocks that should be above the ORB from today...I noticed that the following from my list do not match up up with the bar count on the LONG side...there may be more from that list...so far I just caught these 3...Figured I would share this just incase something is amiss and needs to be fixed. Short side seemed OK...but I would need to look through everything to be sure...and again not sure IF the after hours has anything to do with this or not. I also unchecked the Extended Hours and also set it to 5 min...I am using slightly different ORB that Robert Payne made...but its also set to 5 min so that shouldn't be an issue....



 
P

Pensar

Member
VIP
@HighBredCloud Thanks for the picture. (y) I ran through the stocks and can confirm that the watchlist is displaying correctly when it says "NaN". When I modified the code, I only counted the bars above the Opening Range and below the OR. When price is inside/between the high and low of the OR, it plots yellow and displays "NaN".

I added a yes/no input and a third count for the bars when inside the Opening Range, and updated the above code.
 
Last edited:
H

HighBredCloud

Well-known member
VIP
@HighBredCloud Thanks for the picture. (y) I ran through the stocks and can confirm that the watchlist is displaying correctly when it says "NaN". When I modified the code, I only counted the bars above the Opening Range and below the OR. When price is inside/between the high and low of the OR, it plots yellow and displays "NaN".

I added a third count for the bars when inside the Opening Range and updated the above code.
Sounds good...I also saw the mistake that I made...In your original code the aggregation was set to 30 min...I only changed to 5 min on the ThinkScript Editor...and not in the actual code...

I was literally counting the bars on the 5 min chart and it appeared as if it was the 30 min...and it was...I guess that's what I get for not looking at the code...oh well not much of a coder but hopefully others who read this will need to change the aggregation time in the actual script itself if anyone wants to run 5 min ORB or anything different...

Thanks again for your help in this...
 
P

Pensar

Member
VIP
Sounds good...I also saw the mistake that I made...In your original code the aggregation was set to 30 min...I only changed to 5 min on the ThinkScript Editor...and not in the actual code...

I was literally counting the bars on the 5 min chart and it appeared as if it was the 30 min...and it was...I guess that's what I get for not looking at the code...oh well not much of a coder but hopefully others who read this will need to change the aggregation time in the actual script itself if anyone wants to run 5 min ORB or anything different...

Thanks again for your help in this...
@HighBredCloud Sure, glad to help. The 30 min agg period was coded in by Mobius (I'm guessing to prevent it from being used on higher watchlist aggregations, since the ORB trading method works off the 30 minute opening range). I have not changed it in my code, and I would recommend not doing so. Just set your column aggregation to any aggregation 30 min or lower and it should work fine. ;)
 
H

HighBredCloud

Well-known member
VIP
@HighBredCloud Sure, glad to help. The 30 min agg period was coded in by Mobius (I'm guessing to prevent it from being used on higher watchlist aggregations, since the ORB trading method works off the 30 minute opening range). I have not changed it in my code, and I would recommend not doing so. Just set your column aggregation to any aggregation 30 min or lower and it should work fine. ;)
Correct me if I am wrong...but IF I do not change the 30 min aggregation in the scrip to 5 min...and I only change the column to 5 min...the bars for the opening range will still be counted as if they were on a 30 min chart using a 30 min ORB instead of 5 min ORB...That was my original issue...After changing to 5 min everything seems to be working fine. In the pictures that I provided I displayed the 5 min ORB on my chart...I guess its a personal preference on what to set the ORB to...some prefer 5 min...others 15 min and Mobius suggests 30 min ORB...Either way...this works now for me and will be a great help in sorting...

What I would like to know now from anyone with experience or a strategy for ORB is what else to combine this with? Too many times I have engaged in trades where I thought the ORB was breaking out/down only to have it pull back on me and continue on inside day etc...Anyone have any recommendations on what to pair the ORB with? I have been playing with the idea of Trend Magic Indicator set to 1 hour...followed by another instance of Trend Magic set to 15 min...The idea is to trade when both the 1 hour and 15 min are going in the direction of the ORB...not sure if there is a better way that someone has found. I chose the Trend Magic because its a line that needs to be crossed essentially just like the ORB...not a lagging indicator.
 
J

Jrock1982

New member
Hey all... I love these scripts and thank you for them! I was curious if there was an alert that can be added for when the stocks switch from inside to above?
 
BenTen

BenTen

Administrative
Staff
VIP
@Jrock1982 Setup the scanner > save as watchlist > get alerted for new changes.
 
Top