Opening Range Breakout (ORB) Scanner for ThinkorSwim

T

traderintheroom

Member
@15minofpham You can use this version of ORB where it also plots the entry line for breakout and breakdown based on the range times 0.06. You can change that amount manually via the source code. As far as the scanner I'm not too sure.

Rich (BB code):
# 30 min opening range
# Robert Payne

def OpenRangeMinutes = 30;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

def ORHigh =  if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN;
plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN;

OpenRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenRangeHigh.SetDefaultColor(Color.YELLOW);
OpenRangeHigh.SetLineWeight(2);
OpenRangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenRangeLow.SetDefaultColor(Color.YELLOW);
OpenRangeLow.SetLineWeight(2);

DefineGlobalColor("cloud", CreateColor(161, 182, 158));
AddCloud(OpenRangeHigh, OpenRangeLow, GlobalColor("cloud" ));

def dailyRange = high(period = "day" )[1] - low(period = "day" )[1];
def range = Average(dailyRange, 10);

plot entryLine1 = OpenRangeHigh + (range * 0.06);
entryLine1.SetDefaultColor(Color.GREEN);

plot entryLine2 = OpenRangeLow - (range * 0.06);
entryLine2.SetDefaultColor(Color.GREEN);

def SoundAlert = high crosses above entryLine1 or low crosses below entryLine2;
Alert(SoundAlert, "Something exciting just happened with " + GetSymbol(), Alert.BAR, Sound.Ring);

Hi Ben - I am looking to edit the alert sound on this ORB Script with a custom sound. Do you know how to write the script to replace Alert.BAR, Sound.Ring with the a custom sound?
 
T

thinky

Member
A. Is It Possible to Add Custom Sounds to Custom Study Chart Alerts in TOS
So at this point the only way to get a custom sound alert using this indicator is to build and save a custom scan. Then set the alert options for that scan. (Yes, the alert settings for a custom scan support custom sounds) We demonstrate how to set the alert options on a scan in the video titled: “Thinkorswim Overnight Range Scan Alert“.
B. Using Custom Alert Sounds In Thinkorswim
https://www.simplertrading.com/using-custom-alert-sounds-in-thinkorswim/







C. Learning Center - Sound
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Sound.html

Example: Chimes
Sound.Chimes

Change "Sound.Ring" for the sound you want from the link above (NoSound, Bell, Ding, Ring, Chimes):
Alert(SoundAlert, "Something exciting just happened with " + GetSymbol(), Alert.BAR, Sound.Ring);
 
Last edited:
T

traderintheroom

Member
@traderintheroom Notifications allow for custom sound alerts. Try adding one, then reference it in code as "Custom". Let us know.

Using Custom Alert Sounds In Thinkorswim
https://www.simplertrading.com/using-custom-alert-sounds-in-thinkorswim/







Learning Center - Sound
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Sound.html

Example: Chimes



Change "Sound.Ring" for the sound you want from the link above (NoSound, Bell, Ding, Ring, Chimes):
Thanks for the quick reply - I did try to rename the alert file name to the custom sound name in the script without luck. Script editor says invalid statement on this.

What I tried:

Alert(SoundAlert, "Something exciting just happened with " + GetSymbol(), Alert.BAR, Sound.Ring);

I replaced Ring with the file name and also tried .mp3 and Custom Alert (file name).mp3

*It plays if I do a custom price alert just fine just not in the ORB script.

EDIT - I just saw your edit re: SCAN ORB - I will try that, thank you.
 
Last edited:
Yazzy2589

Yazzy2589

New member
2019 Donor
@BenTen how are you? Do u have a link to your simple ORB chart indicator? Like the pic you posted?
 
dougn

dougn

Member
2019 Donor
Great contribution to the other ORB system that I had. Thank you!

One question...

Is there a way to separate the scan into parts ... bullish and bearish?

Solution: Easy to do within the column "Edit". Just delete one or the other and rename the column.

Outcome: Now the watchlist column alerts are sent out already categorized as breakouts or breakdowns.

Links to separated scan/watchlists added on markos suggestion. Thank you markos. Adjust settings to your personal parameters.

ORB 30m Bear Scan ... https://tos.mx/sW9VOd

ORB 30m Bull Scan ... https://tos.mx/Ppe23L
 
Last edited:
markos

markos

Well-known member
VIP
@
Great contribution to the other ORB system that I had. Thank you!

One question...

Is there a way to separate the scan into parts ... bullish and bearish?

Solution: Easy to do within the column "Edit". Just delete one or the other and rename the column.

Outcome: Now the watchlist column alerts are sent out already categorized as breakouts or breakdowns.
@dougn please put the share links in for the benefit of this community. Yes I could go back to the beginning, but if I was new at this, I would appreciate a share link. Just a thought. Thanks!
 
Last edited:
dougn

dougn

Member
2019 Donor
Yes that's the right way to do it and I'll make sure it happens going forward.

Edits have been made and links added to my post.
 
Tradervic

Tradervic

New member
VIP
Hi everyone. I have been trading on TOS for many years but not familiar with Thinkscript. I tried many times to copy the formula to my platform but it seems I can get the scan but the ORB doesn't show up on my charts. I guess I am dumb! Can someone give me step by step on how to import this into my TOS? Also is it a strategy or a study and how to do I save it as such. Any help would be appreciated !
 
BenTen

BenTen

Administrative
Staff
VIP
@Tradervic Are you having trouble with the scanner or the indicator itself?
 
Tradervic

Tradervic

New member
VIP
BenTen: I copied your scanner script (https://tos.mx/NzMhcR ), and it opens up on my TOS as a scan. But your instructions in the thread is to add study filters and conditions. I get stuck at this part where you want us to select ORB indicator because there isn't a choice for that. Your instructions.....((On the right field, select your ORB indicator. Under plot > ORH2 within 2 bars. Altogether you'll have something like this.))

Also I can't seem to show the indicator on the charts.

I must be missing something really simple. Appreciate your time and help.
 
R

RPrado

Member
Lifetime
Great contribution to the other ORB system that I had. Thank you!

One question...

Is there a way to separate the scan into parts ... bullish and bearish?

Solution: Easy to do within the column "Edit". Just delete one or the other and rename the column.

Outcome: Now the watchlist column alerts are sent out already categorized as breakouts or breakdowns.

Links to separated scan/watchlists added on markos suggestion. Thank you markos. Adjust settings to your personal parameters.

ORB 30m Bear Scan ... https://tos.mx/sW9VOd

ORB 30m Bull Scan ... https://tos.mx/Ppe23L
Thanks a lot for this ORB scanner. It sure will help.
 
P

Playstation

Active member
VIP
Qns: I'm on a 12 hrs different time zone.
If I'm trading futures, can I set the market opening orbegin and orbegin2 to say, 430?
Why is the orend and orend2 set at 935/1030? It's not set to market closing bell?
 
Grunt Trader

Grunt Trader

New member
VIP
Qns: I'm on a 12 hrs different time zone.
If I'm trading futures, can I set the market opening orbegin and orbegin2 to say, 430?
Why is the orend and orend2 set at 935/1030? It's not set to market closing bell?
It's an opening indicator, precisely the first 30 minutes of trading. You can set the period to whatever correlates to your local time.
 
S

sobiswas

New member
VIP
Hi,

I setup the scanner and set up alerts on it. The scanner does not start reading even after 2 hours of market open. I see stocks manually with the ORB study alerting properly. Do I need to tweak something in the scanner?
 
T

tomsk

Well-known member
VIP
Not sure which scan code you are using. Post your code here so we can help you figure out if there is a fundamental reason why the scan is not working as you mentioned
 
S

sobiswas

New member
VIP
I am using the below code, with

Code:
# Clayburgs Directional Day Filter
# Written by KumoBob Dec 31 2009

# Thanks to ThinkScriptor and aPPLE_PI for helping me with the secondsfromtime() function by showing me the code writen by Prospectus in his Opening Range study.


# Directional Day Filter Line - After the first five minutes calculate the average range for this 5-minute bar. Draw a horizontal line at this level.
# Time Line - Draw a vertical line at 60-minute bar (Low to High of the day so far).
# (slower value for faster moving charts like currency and S&P – Faster value for slower moving charts) (45 minutes to 90 minutes)
# Determine the amount of activity above and below the Directional Day Filter Line prior to the Time Line.
# (A rectangle can be drawn with Blue shading above and Red below the Directional Day Filter Line)
# If the majority of the activity is above the Directional Day Filter Line the trend bias for the day will be higher.
# If the majority of the activity is below the Directional Day Filter Line the trend bias for the day will be lower.
# If it's even the day will most likely be flat.
# If the closing bar on the Time Line is within 1/3 the distance from the Directional Day Filter Line then added bias can be anticipated.

#hint: Best used in a 1 to 5 minute chart period


def na = double.nan;
############### Directional Day Filter Line ##############


input ORBegin = 0930;
input OREnd = 0935;
# Show Today only? (Default Yes)
input ShowTodayOnly = { default "No", "Yes"};
def s = ShowTodayOnly;
# Create logic for OR definition: 1 if between fist 5 minutes
Def ORActive = if secondsTillTime(OREnd) > 0 AND secondsFromTime(ORBegin) >= 0 then 1 else 0;
# Create logic to paint only current day post-open:
def today = if s == 0 OR getDay() == getLastDay() AND secondsFromTime(ORBegin) >= 0 then 1 else 0;
# Track OR High:
Rec ORHigh = if ORHigh[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then high else if ORActive AND high > ORHigh[1] then high else ORHigh[1];
# Track OR Low:
Rec ORLow = if ORLow[1] == 0 or ORActive[1] == 0 AND ORActive == 1 then low else if ORActive AND low < ORLow[1] then low else ORLow[1];
# Calculate OR width:
Def ORWidth = ORHigh - ORLow;
# Define all the plots:
Def ORHA = if ORActive OR today < 1 then na else ORHigh;
Def ORLA = if ORActive OR today < 1 then na else ORLow;
Def O = ORHA - (ORHA - ORLA) / 2;
Plot ORL = if (o == 0 , na, o);
ORL.SetDefaultColor(color.Yellow);
ORL.SetStyle(curve.Long_DASH);
ORL.SetLineWeight(3);

################## Time Line #####################

input ORBegin2 = 0930;
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd2 = 1030;
# Show Today only? (Default Yes)
####input ShowTodayOnly={"No", default "Yes"};
####def s=ShowTodayOnly;
# Create logic for OR definition:
Def ORActive2 = if secondsTillTime(OREnd2) > 0 AND secondsFromTime(ORBegin2) >= 0 then 1 else 0;
# Create logic to paint only current day post-open:
#####def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin2)>=0 then 1 else 0;
# Track OR High:
Rec ORHigh2 = if ORHigh2[1] == 0 or ORActive2[1] == 0 AND ORActive2 == 1 then high else if ORActive2 AND high > ORHigh2[1] then high else ORHigh2[1];
# Track OR Low:
Rec ORLow2 = if ORLow2[1] == 0 or ORActive2[1] == 0 AND ORActive2 == 1 then low else if ORActive2 AND low < ORLow2[1] then low else ORLow2[1];
# Calculate OR width:
Def ORWidth2 = ORHigh2 - ORLow2;
# Define all the plots:
Plot ORH2 = if ORActive2 OR today < 1 then na else ORHigh2;
Plot ORL2 = if ORActive2 OR today < 1 then na else ORLow2;
# Formatting:
ORH2.SetDefaultColor(color.green);
ORH2.SetStyle(curve.Long_DASH);
ORH2.SetLineWeight(3);
ORL2.SetDefaultColor(color.red);
ORL2.SetStyle(curve.Long_DASH);
ORL2.SetLineWeight(3);

################################
Def TimeLine = if secondsTillTime(OREnd2) == 0 then 1 else 0;

Def pos = (ORH2 - ORL2) / 10;

plot d1 = if (TimeLine , ORH2, na);
plot d2 = if (TimeLine , ORH2 - ( pos * 2), na);
plot d3 = if (TimeLine , ORH2 - ( pos * 3), na);
plot d4 = if (TimeLine , ORH2 - ( pos * 4), na);
plot d5 = if (TimeLine , ORH2 - ( pos * 5), na);
plot d6 = if (TimeLine , ORH2 - ( pos * 6), na);
plot d7 = if (TimeLine , ORH2 - ( pos * 7), na);
plot d8 = if (TimeLine , ORH2 - ( pos * 8), na);
plot d9 = if (TimeLine , ORH2 - ( pos * 9), na);
plot d10 = if (TimeLine , (ORL2), na);

d1.SetPaintingStrategy(PaintingStrategy.arrow_down);
d2.SetPaintingStrategy(PaintingStrategy.POINTS);
d3.SetPaintingStrategy(PaintingStrategy.POINTS);
d4.SetPaintingStrategy(PaintingStrategy.POINTS);
d5.SetPaintingStrategy(PaintingStrategy.POINTS);
d6.SetPaintingStrategy(PaintingStrategy.POINTS);
d7.SetPaintingStrategy(PaintingStrategy.POINTS);
d8.SetPaintingStrategy(PaintingStrategy.POINTS);
d9.SetPaintingStrategy(PaintingStrategy.POINTS);
d10.SetPaintingStrategy(PaintingStrategy.ARROW_UP);


d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();



DEF Span = (O - ORL2) / (ORH2 - ORL2);
rec colorState = if Span > 0.66 then -1
else if Span < 0.33 then 1 else 0;


d1.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d2.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d3.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d4.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d5.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d6.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d7.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d8.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d9.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.GREEN else
Color.Yellow
);

d10.AssignValueColor(
if colorState < 0 then Color.RED else
if colorState > 0 then Color.red else
Color.Yellow
);
d1.SetLineWeight(5);
d2.SetLineWeight(5);
d3.SetLineWeight(5);
d4.SetLineWeight(5);
d5.SetLineWeight(5);
d6.SetLineWeight(5);
d7.SetLineWeight(5);
d8.SetLineWeight(5);
d9.SetLineWeight(5);
d10.SetLineWeight(5);

#######################################################################


Def TimeLineb = if secondsTillTime(OREND) == 0 then 1 else 0;

Def posbd = (ORHA - ORLA) / 10;

plot bd1 = if (TimeLineb , ORHA, na);
plot bd2 = if (TimeLineb , ORHA - ( posbd * 2), na);
plot bd3 = if (TimeLineb , ORHA - ( posbd * 3), na);
plot bd4 = if (TimeLineb , ORHA - ( posbd * 4), na);
plot bd5 = if (TimeLineb , ORHA - ( posbd * 5), na);
plot bd6 = if (TimeLineb , ORHA - ( posbd * 6), na);
plot bd7 = if (TimeLineb , ORHA - ( posbd * 7), na);
plot bd8 = if (TimeLineb , ORHA - ( posbd * 8), na);
plot bd9 = if (TimeLineb , ORHA - ( posbd * 9), na);
plot bd10 = if (TimeLineb , (ORL2), na);

bd1.SetPaintingStrategy(PaintingStrategy.POINTS);
bd2.SetPaintingStrategy(PaintingStrategy.POINTS);
bd3.SetPaintingStrategy(PaintingStrategy.POINTS);
bd4.SetPaintingStrategy(PaintingStrategy.POINTS);
bd5.SetPaintingStrategy(PaintingStrategy.POINTS);
bd6.SetPaintingStrategy(PaintingStrategy.POINTS);
bd7.SetPaintingStrategy(PaintingStrategy.POINTS);
bd8.SetPaintingStrategy(PaintingStrategy.POINTS);
bd9.SetPaintingStrategy(PaintingStrategy.POINTS);
bd10.SetPaintingStrategy(PaintingStrategy.POINTS);

bd1.SetDefaultColor(Color.YELLOW);
bd2.SetDefaultColor(Color.YELLOW);
bd3.SetDefaultColor(Color.YELLOW);
bd4.SetDefaultColor(Color.YELLOW);
bd5.SetDefaultColor(Color.YELLOW);
bd6.SetDefaultColor(Color.YELLOW);
bd7.SetDefaultColor(Color.YELLOW);
bd8.SetDefaultColor(Color.YELLOW);
bd9.SetDefaultColor(Color.YELLOW);
bd10.SetDefaultColor(Color.YELLOW);

bd1.HideBubble();
bd2.HideBubble();
bd3.HideBubble();
bd4.HideBubble();
bd5.HideBubble();
bd6.HideBubble();
bd7.HideBubble();
bd8.HideBubble();
bd9.HideBubble();
bd10.HideBubble();

AddCloud(ORL2, ORH2, color.green, color.green);
#def aggregation = if getAggregationPeriod() == (AggregationPeriod.MIN * 5) or (AggregationPeriod.MIN * 10) or (AggregationPeriod.MIN * 15) then 1 else 0 ;
def aggregation = 1;
with this as custom study, and stock last > $20 & MarketCap $500M. The scan populated only after 1-2 hours of market open

Code:
BetterORB()."ORH2" crosses close within 2 bars or BetterORB()."ORL2" crosses close
 
Top