Opening Range Indicator for ThinkorSwim with Fibonacci Levels

I found this study on a youtube video, you can just copy and paste the code into a new study script editor. Does this script also generate the line as time progresses? is there a way to, once the time frame is over, draw the line across the chart rather than it being outputted as time progresses?
 

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

@BenTen Can you please do a little explanation of the zones? Is the area between the bold green dashed line and the grey line = bullish zone? while the thin dashed green line is still in the bullish zone but likely to serve as resistance? Thanks
 
How to create a line High and Low line extending all throughout the page right after 5 minutes, presently it develops throughout the trading day. Thanks
 
Here is another version of the Opening Range Breakout indicator I mentioned in this post.



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
Hi Ben, I use this ORB indicator daily. Thank you for this! Question: is it possible to extend the lines to the left, through current day pre-market?

Much appreciated.

-Allison
 
Here is another version of the Opening Range Breakout indicator I mentioned in this post.



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
Is there a way to scan for this like when a candle closes above or below the breakout level
 
Can this be coded so that it only shows the upper fib levels if the price is above the opening range high and only shows the lower fibs if the price is below the opening range low?
 
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);
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);



Is there anyway to make the code extend the Opening range horizontal lines to the end of the day, instead of just developing as the day goes on?
Example of what currently happens.
As you can see, it only develops the horizontal lines as the day goes on, anyway to just make it extend to the end of the day? thanks in advance!
 
def na=double.nan;
input ORBegin = 0930;
input OREnd = 1600;
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

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];

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];

Def ORWidth = ORHigh - ORLow;

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);

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;

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);
 
def na=double.nan;
input ORBegin = 0930;
input OREnd = 1600;
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

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];

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];

Def ORWidth = ORHigh - ORLow;

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);

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;

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);
Hey thanks for the response. I am getting errors on this code. . Any idea how to fix it? Thanks in advance
I was trying to modify the code to extend to the end of the day. Do you know how to do that?
 
Last edited by a moderator:
I was trying to modify the code to extend to the end of the day. Do you know how to do that?
It's an "Opening Range" Breakout Indicator. The Opening Range is the guts of the indicator.
That would require a different script.
 
It's an "Opening Range" Breakout Indicator. The Opening Range is the guts of the indicator.
That would require a different script.
Yea I am aware. I just want the lines to extend towards end of day instead of developing every candle. Cause the opening range is already created during the open either way
 
Hey thanks for the response. I am getting errors on this code. . Any idea how to fix it? Thanks in advance
I was trying to modify the code to extend to the end of the day. Do you know how to do that?
def na=double.nan;
input ORBegin = 0930;
input OREnd = 1600;
Input FibExt1=1.382;
Input FibExt2=1.621;
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

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];

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];

def ORWidth = ORHigh - ORLow;

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);

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;

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);
 
@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.
Hey BenTen, resurrecting this post from over 3 years ago, LOL. Can you provide the code that will provide an audible alert when an arrow prints? Thanks in advance!
 
@SleepyZ
Could the right edge be added to this script? I tried but its not displaying the bubbles.

# https://usethinkscript.com/threads/...r-thinkorswim-with-fibonacci-levels.29/page-2

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 = 1030;
#

# Show Today only? (Default Yes)
#
input ShowTodayOnly = {"No", default "Yes"};
def s = ShowTodayOnly;


# 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;

# 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 OrbMid = if ORActive or today < 1 then na else fib_mid;


# Labels

input ShowLabel = YES;
input ShowLabelORH = YES;
input ShowLabelORL = YES;
input ShowLabelOR50 = YES;

#def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
#def barNumber = BarNumber();
#def barCount = HighestAll(If(IsNaN(close), 0, barNumber));


#Bubble
input locate_bubbles_at_time = 0930;
input ShowBubbles = yes;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
input bubble_placement = {default right_edge, timeopen};
def right_edge = barnumber() == highestall(barnumber() - 1);


#Bubble
input showbubble = yes;
input bubblemover = 3;
input showValuesInBubbles = yes;
def bm = bubblemover;
def bm1 = bm + 1;

DefineGlobalColor("IBH", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORH, "IBH: " + ORH, GlobalColor("IBH"));

DefineGlobalColor("IBM", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORBMid, "IBM: " + ORBMid, GlobalColor("IBM"));

DefineGlobalColor("IBL", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORL, "IBL: " + ORL, GlobalColor("IBL"));

ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetDefaultColor(Color.Yellow);
ORH.HideBubble();
ORH.HideTitle();

ORBMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORBMid.SetDefaultColor(Color.Yellow);
ORBMid.HideBubble();
ORBMid.HideTitle();

ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetDefaultColor(Color.Yellow);
ORL.HideBubble();
ORL.HideTitle();
 
Last edited by a moderator:
@SleepyZ
Could the right edge be added to this script? I tried but its not displaying the bubbles.

Sure, I added this to orlow and orhigh to extend the lines to the right edge where the bubbles where already to then plot there.

Rich (BB code):
rec ORHigh = if isnan(close) then orhigh[1] else if ...

Screenshot-2022-11-13-145114.png

Ruby:
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 = 1030;
#

# Show Today only? (Default Yes)
#
input ShowTodayOnly = {"No", default "Yes"};
def s = ShowTodayOnly;


# 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 isnan(close) then orhigh[1] else 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 isnan(close) then orlow[1] else 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;

# 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 OrbMid = if ORActive or today < 1 then na else fib_mid;


# Labels

input ShowLabel = YES;
input ShowLabelORH = YES;
input ShowLabelORL = YES;
input ShowLabelOR50 = YES;

#def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
#def barNumber = BarNumber();
#def barCount = HighestAll(If(IsNaN(close), 0, barNumber));


#Bubble
input locate_bubbles_at_time = 0930;
input ShowBubbles = yes;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
input bubble_placement = {default right_edge, timeopen};
def right_edge = barnumber() == highestall(barnumber() - 1);


#Bubble
input showbubble = yes;
input bubblemover = 3;
input showValuesInBubbles = yes;
def bm = bubblemover;
def bm1 = bm + 1;

DefineGlobalColor("IBH", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORH, "IBH: " + ORH, GlobalColor("IBH"));

DefineGlobalColor("IBM", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORBMid, "IBM: " + ORBMid, GlobalColor("IBM"));

DefineGlobalColor("IBL", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, ORL, "IBL: " + ORL, GlobalColor("IBL"));

ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetDefaultColor(Color.Yellow);
ORH.HideBubble();
ORH.HideTitle();

ORBMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORBMid.SetDefaultColor(Color.Yellow);
ORBMid.HideBubble();
ORBMid.HideTitle();

ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetDefaultColor(Color.Yellow);
ORL.HideBubble();
ORL.HideTitle();
 
Hi Ben, thanks for all that you do.

For the 30 minute OR in the central time zone, I need to change the ORBegin to 0830 and the OREnd to 0900. When I do that either via the inputs or actually changing the code, then all of the lines disappear except for the green, big dashed line. Can you tell me how to fix this?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
430 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