Auto Plot DDR and IDR

Temper508

New member
HI everyone so Im wondering if its possible to auto plot the High and Low of a range within a certain time period as well as the highest body close or open and lowest body close or open. I have already done the High and Low of the range ( Which is 9:30 to 10:30) But im trying to figure how to plot the highest body close (green line) and the lowest body close (Red Line). Below will be the script I have so far and any help would be greatly appreciated.

Code:
############################# Inputs #############################
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

def Buying = if H == L then V else Round (V * (C - L) / (H - L), 0);
def Selling = if H == L then V else Round (V * (H - C) / (H - L), 0);

def na=double.nan;
input ORBegin = 0930;
input OREnd = 1031;
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;
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;
#
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;
#
ORH.setdefaultcolor(color.blue);
ORH.setpaintingStrategy(PaintingStrategy.line);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.plum);
ORL.setpaintingStrategy(PaintingStrategy.line);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setpaintingStrategy(PaintingStrategy.line);
FibMid.setlineweight(3);

#



https%3A//i.imgur.com/jEifYPF.png[/img]']
jEifYPF.png
 
Solution
The 50% is there
I think I figured out how to add the 50% to your code from post #15
Code from post #15 found here: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

I added :

Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;
# Formatting:
ORM.setdefaultcolor(color.magenta);
ORM.setStyle(curve.Short_DASH);
ORM.setlineweight(3);

Seems to work.

Code from post #15 Here is the link: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

CODE:
def na=double.nan;

input CloudOn = yes;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in...
HI everyone so Im wondering if its possible to auto plot the High and Low of a range within a certain time period as well as the highest body close or open and lowest body close or open. I have already done the High and Low of the range ( Which is 9:30 to 10:30) But im trying to figure how to plot the highest body close (green line) and the lowest body close (Red Line). Below will be the script I have so far and any help would be greatly appreciated.

Code:
############################# Inputs #############################
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

def Buying = if H == L then V else Round (V * (C - L) / (H - L), 0);
def Selling = if H == L then V else Round (V * (H - C) / (H - L), 0);

def na=double.nan;
input ORBegin = 0930;
input OREnd = 1031;
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;
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;
#
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;
#
ORH.setdefaultcolor(color.blue);
ORH.setpaintingStrategy(PaintingStrategy.line);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.plum);
ORL.setpaintingStrategy(PaintingStrategy.line);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setpaintingStrategy(PaintingStrategy.line);
FibMid.setlineweight(3);

#



https%3A//i.imgur.com/jEifYPF.png[/img]']
jEifYPF.png
Check out this thread and look for #15 post by @SleepyZ . The code is there however, it does not show the 50% retracement line, would be nice if you can add it.

Here is the link: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370
 

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

The 50% is there
I think I figured out how to add the 50% to your code from post #15
Code from post #15 found here: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

I added :

Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;
# Formatting:
ORM.setdefaultcolor(color.magenta);
ORM.setStyle(curve.Short_DASH);
ORM.setlineweight(3);

Seems to work.

Code from post #15 Here is the link: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

CODE:
def na=double.nan;

input CloudOn = yes;

# 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={"Yes", default "No"};
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];

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

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORH[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORO[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));


Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;
# Formatting:
ORM.setdefaultcolor(color.magenta);
ORM.setStyle(curve.Short_DASH);
ORM.setlineweight(3);
 
Solution
I think I figured out how to add the 50% to your code from post #15
Code from post #15 found here: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

I added :

Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;
# Formatting:
ORM.setdefaultcolor(color.magenta);
ORM.setStyle(curve.Short_DASH);
ORM.setlineweight(3);

Seems to work.

Code from post #15 Here is the link: https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/#post-113370

CODE:
def na=double.nan;

input CloudOn = yes;

# 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={"Yes", default "No"};
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];

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

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Firm);
ORH.setlineweight(1);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Firm);
ORL.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orl[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORH[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));

# Track OR Open:
Rec OROpen = if OROpen[1]==0 or ORActive[1]==0 AND ORActive==1 then open else if ORActive AND open>OROpen[1] then open else OROpen[1];

# Track OR Close:
Rec ORClose = if ORClose[1]==0 or ORActive[1]==0 AND ORActive==1 then close else if ORActive AND close<ORClose[1] then close else ORClose[1];

# Define all the plots:
Plot ORO=if ORActive OR today<1 then na else OROpen;
Plot ORC=if ORActive OR today<1 then na else ORClose;

# Formatting:
ORO.setdefaultcolor(color.green);
ORO.setStyle(curve.Short_DASH);
ORO.setlineweight(1);
ORC.setdefaultcolor(color.red);
ORC.setStyle(curve.Short_DASH);
ORC.setlineweight(1);

addCloud(if CloudOn == yes and secondsfromTime(orbegin)>=0 and secondsfromTime(orend)<=0
then orc[-(orend-orbegin)/(getaggregationPeriod()/60000)]
else double.nan
, ORO[-(orend-orbegin)/(getaggregationPeriod()/60000)],createColor(41,98,255), createColor(41,98,255));


Plot ORM=if ORActive OR today<1 then na else (ORHigh + ORLow) / 2;
# Formatting:
ORM.setdefaultcolor(color.magenta);
ORM.setStyle(curve.Short_DASH);
ORM.setlineweight(3);
Thanks for sharing this script, I noticed that the paint on the first hour doesn’t show until after the second hour has begun and slowly paints the first hour as times goes on. Are you able to update it where it paints the first hour in real time? Thank you
 
Last edited:
Thanks for sharing this script, I noticed that the paint on the first hour doesn’t show until after the second hour has begun and slowly paints the first hour as times goes on. Are you able to update it where it paints the first hour in real time? Thank you

Here's another script that I recently found on TheMaster's Discord by Phillip Soria (@phil_soria). See if this is what you are looking for. It's adjustable.



Code:
#Opening Breakouts version 3 - to be used with DR/IDR Strategy

#Inputs
input entryType = {default IDRClose, DRClose};

input ExtendCloud = yes;

input ShowLabel = yes;

input ShowBubble = no;

input openingRangeStartTimeEST = 930;
input openingRangeEndTimeEST = 1030;

input tradeEntryStartTimeEST = 1030;
input tradeEntryEndTimeEST = 1545;


#Variables
def openingRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(openingRangeEndTimeEST) >= 0 then 1 else 0;

def tradeEntryRange = if SecondsTillTime(tradeEntryStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def extendTimeRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def DRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then high
else if openingRange and high > DRRangeHigh[1]
then high
else DRRangeHigh[1];

def DRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then low
else if openingRange and low < DRRangeLow[1]
then low
else DRRangeLow[1];

def IDRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close > open
then close
else open
else if openingRange
then
if close > open and
close > IDRRangeHigh[1]
then close
else if close <= open and
open > IDRRangeHigh[1]
then open
else IDRRangeHigh[1]
else IDRRangeHigh[1];

def IDRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close < open
then close
else open
else if openingRange
then
if close < open and
close < IDRRangeLow[1]
then close
else if close >= open and
open < IDRRangeLow[1]
then open
else IDRRangeLow[1]
else IDRRangeLow[1];

#Plots

#DR
plot DRhighCloud = if extendCloud then
if extendTimeRange
then DRRangeHigh else double.NaN
else if openingRange
then DRRangeHigh else double.NaN;
plot DRlowCloud = if extendCloud then
if extendTimeRange
then DRRangeLow else double.NaN
else if openingRange
then DRRangeLow else double.NaN;
DRhighCloud.SetdefaultColor(Color.Gray);
DRlowCloud.SetdefaultColor(Color.Gray);

AddCloud(DRlowCloud, DRhighCloud, color.GRAY, color.GRAY);

plot tradeEntryHighExtension = if tradeentryRange
then DRRangeHigh
else double.NaN;

plot tradeEntryLowExtension = if tradeentryRange
then DRRangeLow
else double.NaN;
tradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryHighExtension.setStyle(Curve.Short_DASH);
tradeEntryLowExtension.setStyle(Curve.Short_DASH);
tradeEntryHighExtension.SetdefaultColor(Color.Gray);
tradeEntryLowExtension.SetdefaultColor(Color.Gray);

#IDR
plot IDRhighCloud = if extendCloud then
if extendTimeRange
then IDRRangeHigh else double.NaN
else if openingRange
then IDRRangeHigh else double.NaN;
plot IDRlowCloud = if extendCloud then
if extendTimeRange
then IDRRangeLow else double.NaN
else if openingRange
then IDRRangeLow else double.Nan;
IDRhighCloud.SetdefaultColor(Color.Gray);
IDRlowCloud.SetdefaultColor(Color.LIGHT_GRAY);

AddCloud(IDRlowCloud, IDRhighCloud, color.GRAY, color.GRAY);

plot IDRtradeEntryHighExtension = if tradeentryRange
then IDRRangeHigh
else double.NaN;

plot IDRtradeEntryLowExtension = if tradeentryRange
then IDRRangeLow
else double.NaN;

IDRtradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryHighExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryLowExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryHighExtension.SetdefaultColor(Color.Gray);
IDRtradeEntryLowExtension.SetdefaultColor(Color.Gray);


#Entry Conditions
def bullentrycondition;
def bearentrycondition;
def bullexitcondition = 0;
def bearexitcondition = 0;

switch(entryType)
{case IDRClose:
bullentrycondition =
tradeEntryRange and
Close > IDRRangeHigh
and Close[1] <= IDRRangeHigh;
bearentrycondition =
tradeEntryRange and
Close < IDRRangeLow
and Close[1] >= IDRRangeLow;

case DRClose:
bullentrycondition =
tradeEntryRange and
close > DRRangeHigh
and close[1] <= DRRangeHigh;
bearentrycondition =
tradeEntryRange and
close < DRRangeLow
and close[1] >= DRRangeLow;
}

def bullishORB = if bullentrycondition then 1
else if !TradeEntryRange or close < IDRRangeLow
then 0
else bullishORB[1];

def bearishORB = if bearentrycondition then 1
else if !TradeEntryRange or Close > IDRRangeHigh
then 0
else bearishORB[1];

#Define opening range width
def range = DRRangeHigh - DRRangeLow;
def halfrange = range /2;
def midrange = DRrangeLow + halfrange;

plot midRangePlot = if tradeentryrange then midrange else double.NaN;
midRangePlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
midRangePlot.setStyle(Curve.LONG_DASH);
midrangePlot.SetdefaultColor(Color.GRAY);

#Projections
#For Bullish Projections
def halfwayUpsideProjection = DRRangeHigh + halfrange;
plot halfwayUpsideProjectionPlot = if bullishORB and tradeEntryRange then
halfwayUpsideProjection else double.NaN;
halfwayUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayUpsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayUpsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullUpsideProjection = DRRangeHigh + range;
plot fullUpsideProjectionPlot = if bullishORB and tradeEntryRange then
fullUpsideProjection else double.NaN;
fullUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullUpsideProjectionPlot.setStyle(Curve.Short_DASH);
fullUpsideProjectionPlot.SetdefaultColor(Color.GREEN);

#For Bearish Projections
def halfwayDownsideProjection = DRRangeLow - halfrange;
plot halfwayDownsideProjectionPlot = if bearishORB and tradeEntryRange then
halfwayDownsideProjection else double.NaN;
halfwayDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayDownsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayDownsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullDownsideProjection = DRRangeLow - range;
plot fullDownsideProjectionPlot = if bearishORB and tradeEntryRange then
fullDownsideProjection else double.NaN;
fullDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullDownsideProjectionPlot.setStyle(Curve.Short_DASH);
fullDownsideProjectionPlot.SetdefaultColor(Color.GREEN);


#Add Bubbles Or Labels
addchartbubble(if ShowBubble then bullishORB or bearishORB else 0, close, 1, if bullishORB then color.green else if bearishORB then color.red else color.yellow);

#For Labels

addLabel(ShowLabel,
if bullishORB then "Bullish"
else if bearishORB then "Bearish"
else "Neutral",

if bullishORB then Color.LIGHT_GREEN
else if bearishORB then color.LIGHT_RED
else color.WhITE);
 
Last edited:
Here's another script that I recently found on TheMaster's Discord by Phillip Soria (@phil_soria). See if this is what you are looking for. It's adjustable.



#Opening Breakouts version 3 - to be used with DR/IDR Strategy

#Inputs
input entryType = {default IDRClose, DRClose};

input ExtendCloud = yes;

input ShowLabel = yes;

input ShowBubble = no;

input openingRangeStartTimeEST = 930;
input openingRangeEndTimeEST = 1030;

input tradeEntryStartTimeEST = 1030;
input tradeEntryEndTimeEST = 1545;


#Variables
def openingRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(openingRangeEndTimeEST) >= 0 then 1 else 0;

def tradeEntryRange = if SecondsTillTime(tradeEntryStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def extendTimeRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def DRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then high
else if openingRange and high > DRRangeHigh[1]
then high
else DRRangeHigh[1];

def DRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then low
else if openingRange and low < DRRangeLow[1]
then low
else DRRangeLow[1];

def IDRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close > open
then close
else open
else if openingRange
then
if close > open and
close > IDRRangeHigh[1]
then close
else if close <= open and
open > IDRRangeHigh[1]
then open
else IDRRangeHigh[1]
else IDRRangeHigh[1];

def IDRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close < open
then close
else open
else if openingRange
then
if close < open and
close < IDRRangeLow[1]
then close
else if close >= open and
open < IDRRangeLow[1]
then open
else IDRRangeLow[1]
else IDRRangeLow[1];

#Plots

#DR
plot DRhighCloud = if extendCloud then
if extendTimeRange
then DRRangeHigh else double.NaN
else if openingRange
then DRRangeHigh else double.NaN;
plot DRlowCloud = if extendCloud then
if extendTimeRange
then DRRangeLow else double.NaN
else if openingRange
then DRRangeLow else double.NaN;
DRhighCloud.SetdefaultColor(Color.Gray);
DRlowCloud.SetdefaultColor(Color.Gray);

AddCloud(DRlowCloud, DRhighCloud, color.GRAY, color.GRAY);

plot tradeEntryHighExtension = if tradeentryRange
then DRRangeHigh
else double.NaN;

plot tradeEntryLowExtension = if tradeentryRange
then DRRangeLow
else double.NaN;
tradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryHighExtension.setStyle(Curve.Short_DASH);
tradeEntryLowExtension.setStyle(Curve.Short_DASH);
tradeEntryHighExtension.SetdefaultColor(Color.Gray);
tradeEntryLowExtension.SetdefaultColor(Color.Gray);

#IDR
plot IDRhighCloud = if extendCloud then
if extendTimeRange
then IDRRangeHigh else double.NaN
else if openingRange
then IDRRangeHigh else double.NaN;
plot IDRlowCloud = if extendCloud then
if extendTimeRange
then IDRRangeLow else double.NaN
else if openingRange
then IDRRangeLow else double.Nan;
IDRhighCloud.SetdefaultColor(Color.Gray);
IDRlowCloud.SetdefaultColor(Color.LIGHT_GRAY);

AddCloud(IDRlowCloud, IDRhighCloud, color.GRAY, color.GRAY);

plot IDRtradeEntryHighExtension = if tradeentryRange
then IDRRangeHigh
else double.NaN;

plot IDRtradeEntryLowExtension = if tradeentryRange
then IDRRangeLow
else double.NaN;

IDRtradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryHighExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryLowExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryHighExtension.SetdefaultColor(Color.Gray);
IDRtradeEntryLowExtension.SetdefaultColor(Color.Gray);


#Entry Conditions
def bullentrycondition;
def bearentrycondition;
def bullexitcondition = 0;
def bearexitcondition = 0;

switch(entryType)
{case IDRClose:
bullentrycondition =
tradeEntryRange and
Close > IDRRangeHigh
and Close[1] <= IDRRangeHigh;
bearentrycondition =
tradeEntryRange and
Close < IDRRangeLow
and Close[1] >= IDRRangeLow;

case DRClose:
bullentrycondition =
tradeEntryRange and
close > DRRangeHigh
and close[1] <= DRRangeHigh;
bearentrycondition =
tradeEntryRange and
close < DRRangeLow
and close[1] >= DRRangeLow;
}

def bullishORB = if bullentrycondition then 1
else if !TradeEntryRange or close < IDRRangeLow
then 0
else bullishORB[1];

def bearishORB = if bearentrycondition then 1
else if !TradeEntryRange or Close > IDRRangeHigh
then 0
else bearishORB[1];

#Define opening range width
def range = DRRangeHigh - DRRangeLow;
def halfrange = range /2;
def midrange = DRrangeLow + halfrange;

plot midRangePlot = if tradeentryrange then midrange else double.NaN;
midRangePlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
midRangePlot.setStyle(Curve.LONG_DASH);
midrangePlot.SetdefaultColor(Color.GRAY);

#Projections
#For Bullish Projections
def halfwayUpsideProjection = DRRangeHigh + halfrange;
plot halfwayUpsideProjectionPlot = if bullishORB and tradeEntryRange then
halfwayUpsideProjection else double.NaN;
halfwayUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayUpsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayUpsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullUpsideProjection = DRRangeHigh + range;
plot fullUpsideProjectionPlot = if bullishORB and tradeEntryRange then
fullUpsideProjection else double.NaN;
fullUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullUpsideProjectionPlot.setStyle(Curve.Short_DASH);
fullUpsideProjectionPlot.SetdefaultColor(Color.GREEN);

#For Bearish Projections
def halfwayDownsideProjection = DRRangeLow - halfrange;
plot halfwayDownsideProjectionPlot = if bearishORB and tradeEntryRange then
halfwayDownsideProjection else double.NaN;
halfwayDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayDownsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayDownsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullDownsideProjection = DRRangeLow - range;
plot fullDownsideProjectionPlot = if bearishORB and tradeEntryRange then
fullDownsideProjection else double.NaN;
fullDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullDownsideProjectionPlot.setStyle(Curve.Short_DASH);
fullDownsideProjectionPlot.SetdefaultColor(Color.GREEN);


#Add Bubbles Or Labels
addchartbubble(if ShowBubble then bullishORB or bearishORB else 0, close, 1, if bullishORB then color.green else if bearishORB then color.red else color.yellow);

#For Labels

addLabel(ShowLabel,
if bullishORB then "Bullish"
else if bearishORB then "Bearish"
else "Neutral",

if bullishORB then Color.LIGHT_GREEN
else if bearishORB then color.LIGHT_RED
else color.WhITE);
please post code in a code window
in the header, click on </> icon.
 
Here's another script that I recently found on TheMaster's Discord by Phillip Soria (@phil_soria). See if this is what you are looking for. It's adjustable.



Code:
#Opening Breakouts version 3 - to be used with DR/IDR Strategy

#Inputs
input entryType = {default IDRClose, DRClose};

input ExtendCloud = yes;

input ShowLabel = yes;

input ShowBubble = no;

input openingRangeStartTimeEST = 930;
input openingRangeEndTimeEST = 1030;

input tradeEntryStartTimeEST = 1030;
input tradeEntryEndTimeEST = 1545;


#Variables
def openingRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(openingRangeEndTimeEST) >= 0 then 1 else 0;

def tradeEntryRange = if SecondsTillTime(tradeEntryStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def extendTimeRange = if SecondsTillTime(openingRangeStartTimeEST) <= 0 and
secondsTillTime(tradeEntryEndTimeEST) >= 0 then 1 else 0;

def DRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then high
else if openingRange and high > DRRangeHigh[1]
then high
else DRRangeHigh[1];

def DRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then low
else if openingRange and low < DRRangeLow[1]
then low
else DRRangeLow[1];

def IDRRangeHigh = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close > open
then close
else open
else if openingRange
then
if close > open and
close > IDRRangeHigh[1]
then close
else if close <= open and
open > IDRRangeHigh[1]
then open
else IDRRangeHigh[1]
else IDRRangeHigh[1];

def IDRRangeLow = if secondsTillTime(openingRangeStartTimeEST) == 0
then if close < open
then close
else open
else if openingRange
then
if close < open and
close < IDRRangeLow[1]
then close
else if close >= open and
open < IDRRangeLow[1]
then open
else IDRRangeLow[1]
else IDRRangeLow[1];

#Plots

#DR
plot DRhighCloud = if extendCloud then
if extendTimeRange
then DRRangeHigh else double.NaN
else if openingRange
then DRRangeHigh else double.NaN;
plot DRlowCloud = if extendCloud then
if extendTimeRange
then DRRangeLow else double.NaN
else if openingRange
then DRRangeLow else double.NaN;
DRhighCloud.SetdefaultColor(Color.Gray);
DRlowCloud.SetdefaultColor(Color.Gray);

AddCloud(DRlowCloud, DRhighCloud, color.GRAY, color.GRAY);

plot tradeEntryHighExtension = if tradeentryRange
then DRRangeHigh
else double.NaN;

plot tradeEntryLowExtension = if tradeentryRange
then DRRangeLow
else double.NaN;
tradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
tradeEntryHighExtension.setStyle(Curve.Short_DASH);
tradeEntryLowExtension.setStyle(Curve.Short_DASH);
tradeEntryHighExtension.SetdefaultColor(Color.Gray);
tradeEntryLowExtension.SetdefaultColor(Color.Gray);

#IDR
plot IDRhighCloud = if extendCloud then
if extendTimeRange
then IDRRangeHigh else double.NaN
else if openingRange
then IDRRangeHigh else double.NaN;
plot IDRlowCloud = if extendCloud then
if extendTimeRange
then IDRRangeLow else double.NaN
else if openingRange
then IDRRangeLow else double.Nan;
IDRhighCloud.SetdefaultColor(Color.Gray);
IDRlowCloud.SetdefaultColor(Color.LIGHT_GRAY);

AddCloud(IDRlowCloud, IDRhighCloud, color.GRAY, color.GRAY);

plot IDRtradeEntryHighExtension = if tradeentryRange
then IDRRangeHigh
else double.NaN;

plot IDRtradeEntryLowExtension = if tradeentryRange
then IDRRangeLow
else double.NaN;

IDRtradeEntryHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
IDRtradeEntryHighExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryLowExtension.setStyle(Curve.Short_DASH);
IDRtradeEntryHighExtension.SetdefaultColor(Color.Gray);
IDRtradeEntryLowExtension.SetdefaultColor(Color.Gray);


#Entry Conditions
def bullentrycondition;
def bearentrycondition;
def bullexitcondition = 0;
def bearexitcondition = 0;

switch(entryType)
{case IDRClose:
bullentrycondition =
tradeEntryRange and
Close > IDRRangeHigh
and Close[1] <= IDRRangeHigh;
bearentrycondition =
tradeEntryRange and
Close < IDRRangeLow
and Close[1] >= IDRRangeLow;

case DRClose:
bullentrycondition =
tradeEntryRange and
close > DRRangeHigh
and close[1] <= DRRangeHigh;
bearentrycondition =
tradeEntryRange and
close < DRRangeLow
and close[1] >= DRRangeLow;
}

def bullishORB = if bullentrycondition then 1
else if !TradeEntryRange or close < IDRRangeLow
then 0
else bullishORB[1];

def bearishORB = if bearentrycondition then 1
else if !TradeEntryRange or Close > IDRRangeHigh
then 0
else bearishORB[1];

#Define opening range width
def range = DRRangeHigh - DRRangeLow;
def halfrange = range /2;
def midrange = DRrangeLow + halfrange;

plot midRangePlot = if tradeentryrange then midrange else double.NaN;
midRangePlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
midRangePlot.setStyle(Curve.LONG_DASH);
midrangePlot.SetdefaultColor(Color.GRAY);

#Projections
#For Bullish Projections
def halfwayUpsideProjection = DRRangeHigh + halfrange;
plot halfwayUpsideProjectionPlot = if bullishORB and tradeEntryRange then
halfwayUpsideProjection else double.NaN;
halfwayUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayUpsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayUpsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullUpsideProjection = DRRangeHigh + range;
plot fullUpsideProjectionPlot = if bullishORB and tradeEntryRange then
fullUpsideProjection else double.NaN;
fullUpsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullUpsideProjectionPlot.setStyle(Curve.Short_DASH);
fullUpsideProjectionPlot.SetdefaultColor(Color.GREEN);

#For Bearish Projections
def halfwayDownsideProjection = DRRangeLow - halfrange;
plot halfwayDownsideProjectionPlot = if bearishORB and tradeEntryRange then
halfwayDownsideProjection else double.NaN;
halfwayDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
halfwayDownsideProjectionPlot.setStyle(Curve.Short_DASH);
halfwayDownsideProjectionPlot.SetdefaultColor(Color.lIGHT_GREEN);

def fullDownsideProjection = DRRangeLow - range;
plot fullDownsideProjectionPlot = if bearishORB and tradeEntryRange then
fullDownsideProjection else double.NaN;
fullDownsideProjectionPlot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
fullDownsideProjectionPlot.setStyle(Curve.Short_DASH);
fullDownsideProjectionPlot.SetdefaultColor(Color.GREEN);


#Add Bubbles Or Labels
addchartbubble(if ShowBubble then bullishORB or bearishORB else 0, close, 1, if bullishORB then color.green else if bearishORB then color.red else color.yellow);

#For Labels

addLabel(ShowLabel,
if bullishORB then "Bullish"
else if bearishORB then "Bearish"
else "Neutral",

if bullishORB then Color.LIGHT_GREEN
else if bearishORB then color.LIGHT_RED
else color.WhITE);
I like the layout of the first one you made, its just the shading of the first hour is delayed. are you able to correct it to shade in real time in that first hour?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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