Opening Range Indicator for ThinkorSwim with Fibonacci Levels

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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...


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
http://tos.mx/2PO45h

 
Last edited:
N

NathanJames

New member
Hello Ben,



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?



Thanks

Nathan

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@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.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@NathanJames Here you go:

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

Place it on the bottom of your script.

 
Last edited:
N

NathanJames

New member
Ben, thanks for the quick response, the code worked

 
Last edited:
G

ganq

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





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
http://tos.mx/2PO45h
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.
 
H

horserider

Well-known member
VIP
Warehouse
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.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@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.
 
H

horserider

Well-known member
VIP
Warehouse
Nope. It is the mid fib line. The 1.382 lines are above and below he opening range lines.
 
H

horserider

Well-known member
VIP
Warehouse
@ganq Better to just use ToS MACD Histogram and switch dark green to dark red and dark red to dark green.
 
T

tradetollive

New member
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

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 = 0945;

#

# 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);
here picture idea
 
Last edited by a moderator:
H

horserider

Well-known member
VIP
Warehouse
@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);
 

Top