# Open and Last Price Lines

#### IHopeToLearn

##### New member
Hi guys,
I found these two scripts which I combined and altered. What I am missing and would like is to show the difference from the Opening Stock Price to the Last price in Percentage and Price displayed on both lines. Showing also if it went down or up using + or - symbols.

Also since I'm asking if possible, in Green for Up and Red for Down, and finally, the ability to see the previous days if wanted. Thanks

See screenshot here:

Here's the code:
#This is where I found the code for the opening price, thanks

#Plots a Horizontal Line for the opening price
declare upper;

def agg = AggregationPeriod.DAY;
plot OpenLine = open(period = agg);

OpenLine.setpaintingStrategy(paintingStrategy.LINE);
OpenLine.setlineWeight(1);
OpenLine.setdefaultColor(color.white);
OpenLine.hideBubble();

#This is where I found the below code, and a thank you for this

#Plots a Horizontal Line that follows the price value selected
input price=close;
input offset=0;
input length = 300;

def sma = SimpleMovingAvg(price, 1, length);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.POINTS);
priceline.setlineWeight(1);
priceline.setdefaultColor(color.white);
priceline.hideBubble();

Solution
Hi guys,
I found these two scripts which I combined and altered. What I am missing and would like is to show the difference from the Opening Stock Price to the Last price in Percentage and Price displayed on both lines. Showing also if it went down or up using + or - symbols.

Also since I'm asking if possible, in Green for Up and Red for Down, and finally, the ability to see the previous days if wanted. Thanks

See screenshot here:

Here's the code:
#This is where I found the code for the opening price, thanks

#Plots a Horizontal Line for the opening price
declare upper;

def agg = AggregationPeriod.DAY;
plot OpenLine =...
Hi guys,
I found these two scripts which I combined and altered. What I am missing and would like is to show the difference from the Opening Stock Price to the Last price in Percentage and Price displayed on both lines. Showing also if it went down or up using + or - symbols.

Also since I'm asking if possible, in Green for Up and Red for Down, and finally, the ability to see the previous days if wanted. Thanks

See screenshot here:

Here's the code:
#This is where I found the code for the opening price, thanks

#Plots a Horizontal Line for the opening price
declare upper;

def agg = AggregationPeriod.DAY;
plot OpenLine = open(period = agg);

OpenLine.setpaintingStrategy(paintingStrategy.LINE);
OpenLine.setlineWeight(1);
OpenLine.setdefaultColor(color.white);
OpenLine.hideBubble();

#This is where I found the below code, and a thank you for this

#Plots a Horizontal Line that follows the price value selected
input price=close;
input offset=0;
input length = 300;

def sma = SimpleMovingAvg(price, 1, length);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.POINTS);
priceline.setlineWeight(1);
priceline.setdefaultColor(color.white);
priceline.hideBubble();

the 2 links you included, are the same.
but you did provide the code so not a big deal.

that code for a price at the close, only works if there are more than 300 bars on the chart.
if there are less, then the line is drawn at 0.

#Plots a Horizontal Line that follows the price value selected
input length = 300;

this is a better code for drawing a priceline

it isn't clear what prices you want to compare. opening stock price? that could be the open price on every bar or the open at the start of a days regular trading hours.

if you want the option to also see the previous days price levels, then you don't want lines that extend across the whole chart. you want 2 horizontal lines for open and close, on each day.

Ruby:
``````# open_to_close_per_0

def na = double.nan;
def bn = barnumber();

def agg = AggregationPeriod.DAY;
def dayopn = open(period = agg);
def daycls = close(period = agg);

def day_updwn = if daycls > dayopn then 1 else if daycls < dayopn then -1 else 0;

# is last day the current day
def istoday = if GetLastDay() == GetDay() then 1 else 0;
input show_only_today = yes;
# draw only on current day  yes/no
def days_en = if show_only_today then istoday else 1;

plot OpenLine = if days_en then dayopn else na;
OpenLine.setpaintingStrategy(paintingStrategy.horizontal);
OpenLine.setdefaultColor(color.white);
OpenLine.setlineWeight(1);
#OpenLine.hideBubble();

plot closeline = if days_en then daycls else na;
closeLine.setpaintingStrategy(paintingStrategy.horizontal);
#closeLine.setdefaultColor(color.cyan);
closeLine.setlineWeight(1);
#closeLine.hideBubble();
closeline.AssignValueColor(if day_updwn > 0 then color.green else if day_updwn < 0 then color.red else color.gray);

# % bubble
def per = round(100 * (daycls - dayopn)/ dayopn, 1);

def n = 2;
def x = (!isnan(close[n]) and isnan(close[n-1]));
addchartbubble(x, closeline[n], per[n] + "%", color.yellow, (if day_updwn[n] > 0 then yes else no));

def cldtop = if shading_between_lines then closeline else na;
def cldbot = openline;
#``````

show_only_today = no

--------------------------

this might be of interest
Multi-TimeFrame Candles Overlay for ThinkOrSwim

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