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
#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.614/post-8400

#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
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.614/post-8400

#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
#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.614/post-8400

#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
#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.614/post-8400

#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
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.614/post-8400

#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
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/


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

# shading
input shading_between_lines = yes;
def cldtop = if shading_between_lines then closeline else na;
def cldbot = openline;
addcloud( cldtop, cldbot, color.green, color.red);
#

show_only_today = no
shading_between_lines = yes
gRml7wK.jpg


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

this might be of interest
Multi-TimeFrame Candles Overlay for ThinkOrSwim
https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/
 
Solution

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