ORB: First Bar High For ThinkOrSwim

SJP07

Member
I just took a few scripts and pieced them together, but I find this incredibly visually helpful. I notice that the first bar on a five minute chart typically served as a great support and resistance indicator. Here's what it looks like https://imgur.com/a/MEIygEz



declare Hide_On_Daily;
declare Once_per_bar;

input OrMeanS = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd = 0935.0; #hint OrEnd: End of Period of Opening Range Breakout.


input CloudOn = no; #hint CloudOn: Clouds Opening Range.
input AlertOn = no; #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"};
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.

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


def h = high;
def l = low;
def op = open;
def c = close;
def bar = barNumber();
def s = ShowTodayOnly;
def ORActive = if secondsTillTime(OrMeanE) > 0 and
secondsFromTime(OrMeanS) >= 0
then 1
else 0;
def today = if s == 0
or getDay() == getLastDay() and
secondsFromTime(OrMeanS) >= 0
then 1
else 0;
####################################################################
def ORHigh = if ORHigh[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then h
else if ORActive and
h > ORHigh[1]
then h
else ORHigh[1];

def ORLow = if ORLow[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then l
else if ORActive and
l < ORLow[1]
then l
else ORLow[1];

def OROpen = if OROpen[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then Op
else if ORActive and
Op > OROpen[1]
then Op
else OROpen[1];

def ORClose = if ORClose[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then C
else if ORActive and
C > ORClose[1]
then C
else ORClose[1];




####################################################################
def ORWidth = ORHigh - ORLow;
def na = double.nan;

def ORHA = if ORActive
or today < 1
then na
else ORHigh;



def ORLA = if ORActive
or today < 1
then na
else ORLow;

def OROP = if ORActive
or today < 1
then na
else OROpen;

def ORCL = if ORActive
or today < 1
then na
else ORClose;


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

def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
def ORActive2 = if secondsTillTime(OREnd) > 0 and
secondsFromTime(ORBegin) >= 0
then 1
else 0;
def ORHigh2 = if ORHigh2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then h
else if ORActive2 and
h > ORHigh2[1]
then h
else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then l
else if ORActive2 and
l < ORLow2[1]
then l
else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if secondsTillTime(OREnd) == 0
then 1
else 0;
def ORmeanBar = if !ORActive and ORActive[1]
then barNumber()
else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then barNumber()
else ORendBar[1];
def ORL = if (o == 0 , na, o);

####################################################################
plot OR_Open = if barNumber() >= highestAll(ORmeanBar)
then HighestAll(if isNaN(c[-1])
then OROpen[1]
else double.nan)
else double.nan;
OR_Open.SetDefaultColor(color.Yellow);
OR_Open.SetStyle(curve.Long_DASH);
OR_Open.SetLineWeight(3);
OR_Open.HideTitle();
def ORH2 = if ORActive2
or today < 1
then na
else ORHigh2;
####################################################################

plot OR_Close = if barNumber() >= highestAll(ORmeanBar)
then HighestAll(if isNaN(c[-1])
then ORClose[1]
else double.nan)
else double.nan;
OR_Close.SetDefaultColor(color.Yellow);
OR_Close.SetStyle(curve.Long_DASH);
OR_Close.SetLineWeight(3);
OR_Close.HideTitle();
def OR_CL = if ORActive2
or today < 1
then na
else ORHigh2;
####################################################################

plot OR_High = if barNumber() >= highestAll(ORendBar)
then HighestAll(if isNaN(c[-1])
then ORH2[1]
else double.nan)
else double.nan;
OR_High.SetDefaultColor(color.Green);
OR_High.SetStyle(curve.Long_DASH);
OR_High.SetLineWeight(3);
OR_High.HideTitle();
def ORL2 = if ORActive2
or today < 1
then na
else ORLow2;

####################################################################
plot OR_Low = if barNumber() >= highestAll(ORendBar)
then HighestAll(if isNaN(c[-1])
then ORL2[1]
else double.nan)
else double.nan;
OR_Low.SetDefaultColor(color.Red);
OR_Low.SetStyle(curve.Long_DASH);
OR_Low.SetLineWeight(3);
OR_Low.HideTitle();
def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5
then 5
else if RelDay < .5
then 6
else 4;
def pos = (ORH2 - ORL2)/10;

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

addCloud(if CloudOn == yes
then orl
else double.nan
#, orl2,createColor(244,83,66), createColor(244,83,66));
, orl2, color.Black, color.black);

addCloud(if CloudOn == yes
then orl
else double.nan
#, orh2,createColor(66,244,131), createColor(66,244,131));
, orh2, color.Black, color.black);

# Begin Risk Algorithm
# First Breakout or Breakdown bars
def Bubbleloc1 = isNaN(close[-1]);
def BreakoutBar = if ORActive
then double.nan
else if !ORActive and c crosses above ORH2
then bar
else if !isNaN(BreakoutBar[1]) and c crosses ORH2
then BreakoutBar[1]
else BreakoutBar[1];
def ATR = if ORActive2
then Round((Average(TrueRange(h, c, l), nATR)) / TickSize(), 0) * TickSize()
else ATR[1];
def cond1 = if h > ORH2 and
h[1] <= ORH2
then Round((ORH2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else cond1[1];

######################################
Input Five_Min_Cloud = yes;
def Bullish_Open = OR_Close is greater than OR_Open;

AddCloud(if Bullish_Open && Five_Min_Cloud then OR_High else Double.NaN, OR_Close, Color.Red, Color.Green);
AddCloud(if Bullish_Open && Five_Min_Cloud then OR_Low else Double.NaN, OR_Open, Color.Red, Color.Green);

def Bearish_Open = OR_Close is less than OR_Open;
AddCloud(if Bearish_Open && Five_Min_Cloud then OR_High else Double.NaN, OR_Open, Color.Red, Color.Green);
AddCloud(if Bearish_Open && Five_Min_Cloud then OR_Low else Double.NaN, OR_Close, Color.Red, Color.Green);


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

OR_Close.AssignValueColor(if OR_Close > OR_Open then color.Dark_Red else color.Dark_Green);


OR_Open.AssignValueColor(if OR_Close > OR_Open then color.Dark_Green else color.Dark_Red);
 
Last edited:

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
331 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