# First two 4 hr bars on Sunday

#### TonXas

##### New member
Any way to make an indicator that draws out the highs and lows from the first two 4hr bars on Sunday for the week?
As of right now I just draw them by hand but it would be cool if the computer just did it for me

Code:
``````# inputs
input orStartTime = 1800;
input orEndTime = 0100;
input period = AggregationPeriod.four_hours;
input showOnlyToday = no;
input showCloud = yes;
input showMidpoint = yes;

# constants
def na = Double.NaN;
def hi = high(period = period);
def lo = low(period = period);
DefineGlobalColor("Cloud", Color.GRAY);

# opening range time logic
def overnight = orStartTime > orEndTime;
def pastORstart = SecondsFromTime(orStartTime) >= 0;
def beforeORend = SecondsTillTime(orEndTime) > 0;
def isOR =
(overnight and (pastORstart or beforeORend)) or (!overnight and (pastORstart and beforeORend));
#def isOr = SecondsTillTime(orEndTime) > 0 and SecondsFromTime(orStartTime) >= 0;
def today = (!showOnlyToday or GetDay() == GetLastDay()) and !IsNaN(close);

# opening range levels logic
def orhi =
if orhi[1] == 0
or !isOr[1]
and isOr
then hi
else if isOr
and hi > orhi[1]
then hi
else orhi[1];

def orlo =
if orlo[1] == 0
or !isOr[1]
and isOr
then lo
else if isOr
and lo < orlo[1]
then lo
else orlo[1];

# plots
plot orh = if today < 1 then na else orhi;
plot orl = if today < 1 then na else orlo;
plot orm = if !isOr then (orh + orl) / 2 else na;

orm.SetHiding(!showMidpoint);

def range = orhi - orlo;

AddCloud(if showCloud and isOR then orh else na, if showCloud and isOR then orl else na, GlobalColor("cloud"), GlobalColor("cloud"));

# look and feel
orh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
orl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
orm.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

orh.SetDefaultColor(Color.White);
orl.SetDefaultColor(Color.White);
orm.SetDefaultColor(Color.gray);

AddLabel(close > 0, Concat( "WT: ", (orhi - orlo)*10000), Color.cyan);

#AddChartBubble(close > 0, Concat( "WT: ", (orhi - orlo)*10000), Color.cyan);``````

Don’t know.

Nice avatar though.

87k+ Posts
395 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?