# Extend Price Level to the left towards the Respective Candles ?

#### AstroBoy

##### New member
Hey everyone! I'm trying to customize a Technical Indicator Study that plots the Previous Day's High, Previous Day's Close, and Present Day's Pre-Market High.
The study measures what I need it to do, but visually on the chart, how do I code the script so that the Previous Day's High Line and Previous Day's Close Line extends to the left to their respective candles?
The Pre-Market High Line is already on its respective candle, I just need the Day's High and Day's Close to do the same...Here's a visual example of what I am trying to accomplish:

And here is the script:

Code:
``````input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

def h = high;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
then h
else if Globex and
h > ONhigh[1]
then h
else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
then Bar
else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

plot PrevDayHigh;
if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1])
{
PrevDayHigh = Double.NaN;
}
else
{
PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
}

plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PrevDayClose = Double.NaN;
} else { PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

plot PreMarketHigh = if OverNightHigh > 0
then OverNightHigh
else Double.NaN;``````

Transparency: This script is an aggregation of several other scripts from here and Reddit that I edited to measure the correct price levels I needed it to and be displayed to my preferences

Last edited:
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high

# ==== EDIT 2 ======
i changed a line of code.
before , sometimes if the highest price existed on an earlier day, the line started on an earlier day.

Ruby:
``````# linefromprevhigh
def na = double.nan;
def bn = barnumber();

#if you want a line to start on the 2nd to last day, then you need to determine when that is.
input agg = AggregationPeriod.DAY;

# is the next day valid and the one after that invalid?
def day2= ( !isnan(close(period = agg)[-1]) and isnan(close(period = agg)[-2]) );

# find highest high of 2nd day
def hh = highestall( if day2 then high else 0);

#find the bar that matches the highest and keep value thru remaining bars

# ==== EDIT ======
#def lineh = if bn == 1 then na else if high == hh then hh else lineh[1];

def lineh = if bn == 1 then na else if (day2 and high == hh) then hh else lineh[1];
# ==== EDIT ======

plot x = lineh;
x.SetDefaultColor(Color.white);
x.SetStyle(Curve.MEDIUM_DASH);
x.setlineweight(3);
# x.hidebubble();

# last bar  ( most recent)
def lastbar = !isnan(close[0]) and isnan(close[-1]);
#
addchartbubble(lastbar, x, "prev HI", color.green, yes);
#``````

Last edited:
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high [...]
I appreciate your insight! The code below is what I currently have, and if I understood you correctly, the solution was to def the highest candlebar from yesterday to plot a line from?

This is the current code that is working for me, courtesy of the forum folks here that helped out with this code:
Code:
``````input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot PrevDayHigh;
if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1])
{
PrevDayHigh = Double.NaN;
}
else
{
PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
}``````

Last edited:
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high

# ==== EDIT 2 ======
i changed a line of code.
before , sometimes if the highest price existed on an earlier day, the line started on an earlier day.

Ruby:
``````# linefromprevhigh
def na = double.nan;
def bn = barnumber();

#if you want a line to start on the 2nd to last day, then you need to determine when that is.
input agg = AggregationPeriod.DAY;

# is the next day valid and the one after that invalid?
def day2= ( !isnan(close(period = agg)[-1]) and isnan(close(period = agg)[-2]) );

# find highest high of 2nd day
def hh = highestall( if day2 then high else 0);

#find the bar that matches the highest and keep value thru remaining bars

# ==== EDIT ======
#def lineh = if bn == 1 then na else if high == hh then hh else lineh[1];

def lineh = if bn == 1 then na else if (day2 and high == hh) then hh else lineh[1];
# ==== EDIT ======

plot x = lineh;
x.SetDefaultColor(Color.white);
x.SetStyle(Curve.MEDIUM_DASH);
x.setlineweight(3);
# x.hidebubble();

# last bar  ( most recent)
def lastbar = !isnan(close[0]) and isnan(close[-1]);
#
addchartbubble(lastbar, x, "prev HI", color.green, yes);
#``````

The code works! If I wanted to only have the line be plotted from the high of day of during normal trading hours of 9:30 AM to 4:00 PM EST, would I have to use
Code:
``RegularTradingStart(GetYYYYMMDD())``
?

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
253 Online

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