Opening Range Indicator for ThinkorSwim with Fibonacci Levels

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Here is another version of the Opening Range Breakout indicator I mentioned in this post.

Automatic Opening Range and Fibonacci Levels This Thinkscript is designed to plot the OR high, low, 50% fib retrace, and fib extensions for the current day. This will only work correctly on time-based charts, where the OR time frame is divisible by the bar period e.g. 30 minute OR, 10 min bars. An extra fib extension may be used if desired...

ncVLk3M.png


thinkScript Code

Rich (BB code):
#
def na=double.nan;
#
# Define time that OR begins (in hhmm format,
# 0930 is the default):
#
input ORBegin = 0930;
#
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
#
input OREnd = 1000;
#
# Input first and second fib extension levels
# (default 1.382, 1.621):
#
Input FibExt1=1.382;
Input FibExt2=1.621;
#
# Show Today only? (Default Yes)
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
# Show Second fib extension? (Default No)
#
input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
#
# Create logic for OR definition:
#
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;
#
# Calculate fib levels:
#
Def fib_mid = (ORHigh+ORLow)/2;
Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);
Def fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);
Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);
Def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);
#
# Define all the plots:
#
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot FibMid=if ORActive OR today<1 then na else fib_mid;
Plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;
Plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;
Plot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;
Plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;
#
# Formatting:
#
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Long_DASH);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Long_DASH);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setStyle(curve.SHORT_DASH);
FibMid.setlineweight(3);
FibExtUp1.setdefaultcolor(color.green);
FibExtUp1.setStyle(curve.SHORT_DASH);
FibExtUp1.setlineweight(2);
FibExtDown1.setdefaultcolor(color.red);
FibExtDown1.setStyle(curve.SHORT_DASH);
FibExtDown1.setlineweight(2);
FibExtUp2.setdefaultcolor(color.green);
FibExtUp2.setStyle(curve.SHORT_DASH);
FibExtUp2.setlineweight(1);
FibExtDown2.setdefaultcolor(color.red);
FibExtDown2.setStyle(curve.SHORT_DASH);
FibExtDown2.setlineweight(1);

Shareable Link

https://tos.mx/2PO45h
 
Last edited:
Thank you for sharing your trading tips and script, they are all informative. I just want to ask you a newbie question regarding the above Fib script, can you add a cloud for the green line and red line similar to the opening range breakout indicator, do you have a code that I can paste?
 
Last edited:
@NathanJames Hey, glad you're liking the contents on here. If you want the cloud, you can use the previous version. Just enable it via the indicator's settings page.

Oops, I just re-read the comment lol. I'll look into it and see if I can send you the code.

Code:
addCloud(ORL, ORH, color.gray, color.gray);

Place it on the bottom of your script.
 
Last edited:
Hi @BenTen , what is that MacDGrip you are using at the bottom of the screen?, can you please share or explain how you use that indicator? Thanks again for all your help.
 
Hey everyone. This should work on any time frame below 30 min. , it for sure works on the 5 min. I have used it and the levels are the same. Interesting thing is the mid fib line will pretty closely match the Magic 1.272 Fib study. If interested in that level pick one or the other , no need for both.
 
@ganq I believe this is what you're looking for. Be sure to adjust the MACD length to the default settings if that's what you prefer.

Code:
## Archive Name: MACD_withBreakoutSignals_InvTools
## Archive Section: Momentum
## Suggested Tos Name: MACD_withBreakoutSignals_InvTools
## Archive Date: 5.13.2018
## Archive Notes:

## "##" indicates an addition by the Archivist

#Number Two MACD with Breakout Signals  [email protected]
declare lower;

input fastLength = 8;
input slowLength = 17;
input MACDLength = 9;
input AverageType = {SMA, default EMA};

plot Diff = MACD(fastLength, slowLength, MACDLength, AverageType).Diff;

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));

plot zeroline = 0;
zeroline.assignValueColor(getcolor(7));

def crossedb = Crosses(diff, 0, CrossingDirection.BELOW);
plot crossbelow = if crossedb then crossedb-1 else double.NaN;
crossbelow.AssignValueColor(getcolor(5));
crossbelow.SetPaintingStrategy(PaintingStrategy.arrow_DOWN);

def crossedu = Crosses(diff, 0, CrossingDirection.above);
plot crossabove = if crossedu then crossedu-1 else double.NaN;
crossabove.AssignValueColor(getcolor(1));
crossabove.SetPaintingStrategy(PaintingStrategy.arrow_up);
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@horserider I believe it's similar to Fib 1.272 because the ORB indicator uses 1.382 as one of the extensions.
 
Nope. It is the mid fib line. The 1.382 lines are above and below he opening range lines.

@ganq Better to just use ToS MACD Histogram and switch dark green to dark red and dark red to dark green.
 
hello i like this ORB indicator but a need more extra line to it, it has the ext 1 and ext 2, but i need the ext 3 ext 4 ext 5( extended Fibonacci line 2.00, 2.618 & 4.236. thank you so much here the code

pWqbcjI.png
 
Last edited by a moderator:
@tradetollive See if this works. Change Fib Ext 2 to yes.


Code:
# Automatic Opening Range and Fibonacci Levels

# By Prospectus @ https://readtheprospectus.wordpress.com

# Inspired by Trader-X @ http://traderx.blogspot.com

#

# This Thinkscript is designed to plot the OR high, low,

# 50% fib retrace, and fib extensions for the current day.

# This will only work correctly on time-based charts,

# where the OR timeframe is divisible by the bar period

# e.g. 30 minute OR, 10 min bars. An extra fib extension

# may be used if desired to create a target zone.

# Added additional Fib_exts_.  Horserider 12/14/2019

def na=double.nan;

#

# Define time that OR begins (in hhmm format,

# 0930 is the default):

#

input ORBegin = 0930;

#

# Define time that OR is finished (in hhmm format,

# 10:00 is the default):

#

input OREnd = 0945;

#

# Input first and second fib extension levels

# (default 1.382, 1.621):

#

Input FibExt1=1.382;

Input FibExt2=1.621;

Input FibExt3=2.0;

Input FibExt4=2.618;

Input FibExt5=4.236;



#

# Show Today only? (Default Yes)

#

input ShowTodayOnly={"No", default "Yes"};

def s=ShowTodayOnly;

#

# Show Second fib extension? (Default No)

#

input ShowFibExt2={default "No", "Yes"};

def sf2=ShowFibExt2;

#

# Create logic for OR definition:

#

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;

#

# Calculate fib levels:

#

Def fib_mid = (ORHigh+ORLow)/2;



Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);

Def fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);

Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);

Def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);

Def fib_ext_up3 = ORHigh + ORWidth*(FibExt3 - 1);

Def fib_ext_down3 = ORLow - ORWidth*(FibExt3 - 1);

Def fib_ext_up4= ORHigh + ORWidth*(FibExt4 - 1);

Def fib_ext_down4 = ORLow - ORWidth*(FibExt4 - 1);

Def fib_ext_up5= ORHigh + ORWidth*(FibExt5 - 1);

Def fib_ext_down5 = ORLow - ORWidth*(FibExt5 - 1);

#

# Define all the plots:

#

Plot ORH=if ORActive OR today<1 then na else ORHigh;

Plot ORL=if ORActive OR today<1 then na else ORLow;

Plot FibMid=if ORActive OR today<1 then na else fib_mid;

Plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;

Plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;

Plot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;

Plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;


Plot FibExtUp3=if ORActive OR today<1 then na else fib_ext_up3;

Plot FibExtDown3=if ORActive OR today<1 then na else fib_ext_down3;

Plot FibExtUp4=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up4;

Plot FibExtDown4=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down4;

Plot FibExtUp5=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up5;

Plot FibExtDown5=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down5;

#

# Formatting:

#

ORH.setdefaultcolor(color.green);

ORH.setStyle(curve.Long_DASH);

ORH.setlineweight(3);

ORL.setdefaultcolor(color.red);

ORL.setStyle(curve.Long_DASH);

ORL.setlineweight(3);

FibMid.setdefaultcolor(color.gray);

FibMid.setStyle(curve.SHORT_DASH);

FibMid.setlineweight(3);

FibExtUp1.setdefaultcolor(color.green);

FibExtUp1.setStyle(curve.SHORT_DASH);

FibExtUp1.setlineweight(2);

FibExtDown1.setdefaultcolor(color.red);

FibExtDown1.setStyle(curve.SHORT_DASH);

FibExtDown1.setlineweight(2);

FibExtUp2.setdefaultcolor(color.green);

FibExtUp2.setStyle(curve.SHORT_DASH);

FibExtUp2.setlineweight(1);

FibExtDown2.setdefaultcolor(color.red);

FibExtDown2.setStyle(curve.SHORT_DASH);

FibExtDown2.setlineweight(1);

FibExtUp3.setdefaultcolor(color.green);

FibExtUp3.setStyle(curve.SHORT_DASH);

FibExtUp3.setlineweight(2);

FibExtDown3.setdefaultcolor(color.red);

FibExtDown3.setStyle(curve.SHORT_DASH);

FibExtDown3.setlineweight(2);

FibExtUp4.setdefaultcolor(color.green);

FibExtUp4.setStyle(curve.SHORT_DASH);

FibExtUp4.setlineweight(1);

FibExtDown4.setdefaultcolor(color.red);

FibExtDown4.setStyle(curve.SHORT_DASH);

FibExtDown4.setlineweight(1);

FibExtUp5.setdefaultcolor(color.green);

FibExtUp5.setStyle(curve.SHORT_DASH);

FibExtUp5.setlineweight(1);

FibExtDown5.setdefaultcolor(color.red);

FibExtDown5.setStyle(curve.SHORT_DASH);

FibExtDown5.setlineweight(1);
 
hi thank you for the script in my thinkorswim it only shows the fib. lines only for 1 day is it possible to show these line in past five days
 
@BenTen anyway to make this work on mobile? this plus the macd seem like a great combo.

also curious if you have any thoughts on how this would apply to a scanner.. something along the lines of if a stock with X factors (volume, price, etc) bounces off the support, set an alert in the scanner.
 
i currently am using a script that will find the low and high of a certain time period and output a price level (thickest Green & red dotted lines) along with fib levels above and below (thinner dotted lines). My issue is that the Line is drawn as time progresses rather than drawing the line all the way across the chart on the x (time) axis. i have searched everywhere for the function that controls the length of the line but i cannot find a solution anywhere. any help is appreciated.

Code:
# Automatic Opening Range and Fibonacci Levels
# By Prospectus @ https://readtheprospectus.wordpress.com
# Inspired by Trader-X @ http://traderx.blogspot.com
#
# This Thinkscript is designed to plot the OR high, low,
# 50% fib retrace, and fib extensions for the current day.
# This will only work correctly on time-based charts,
# where the OR timeframe is divisible by the bar period
# e.g. 30 minute OR, 10 min bars. An extra fib extension
# may be used if desired to create a target zone.
#
def na=double.nan;
#
# Define time that OR begins (in hhmm format,
# 0930 is the default):
#
input ORBegin = 0930;
#
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
#
input OREnd = 1000;
#
# Input first and second fib extension levels
# (default 1.382, 1.621):
#
Input FibExt1=1.382;
Input FibExt2=1.621;
#
# Show Today only? (Default Yes)
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
# Show Second fib extension? (Default No)
#
input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
#
# Create logic for OR definition:
#
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;
#
# Calculate fib levels:
#
Def fib_mid = (ORHigh+ORLow)/2;
Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);
Def fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);
Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);
Def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);
#
# Define all the plots:
#
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot FibMid=if ORActive OR today<1 then na else fib_mid;
Plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;
Plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;
Plot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;
Plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;
#
# Formatting:
#
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Long_DASH);
ORH.setlineweight(3);

#ORH.setPaintingStrategy(AggregationPeriod.TWO_DAYS);

#ORH.SetPaintingStrategy(paintingStrategy.HORIZONTAL);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Long_DASH);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setStyle(curve.SHORT_DASH);
FibMid.setlineweight(3);
FibExtUp1.setdefaultcolor(color.green);
FibExtUp1.setStyle(curve.SHORT_DASH);
FibExtUp1.setlineweight(2);
FibExtDown1.setdefaultcolor(color.red);
FibExtDown1.setStyle(curve.SHORT_DASH);
FibExtDown1.setlineweight(2);
FibExtUp2.setdefaultcolor(color.green);
FibExtUp2.setStyle(curve.SHORT_DASH);
FibExtUp2.setlineweight(1);
FibExtDown2.setdefaultcolor(color.red);
FibExtDown2.setStyle(curve.SHORT_DASH);
FibExtDown2.setlineweight(1);


NOTE: i cannot figure out how to post the screen shot as it asks for a url
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
297 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top