line between two prices with bubble

shakib3585

Active member
VIP
Hello,

Draw straight line between two closing prices and add bubble showing percent change
I would like to connect two closing prices with a dashed, thick, straight line and add a bubble next to it mentioning the percent change between the closing prices. For example, I would like to see the percent change between the previous day's closing price and the 3-day back closing price and display the percentage as a bubble next to the straight line connecting the respective closing prices. Can anyone please help me with a script?

Many thanks
 
Last edited by a moderator:
Solution
Hello,

Draw straight line between two closing prices and add bubble showing percent change
I would like to connect two closing prices with a dashed, thick, straight line and add a bubble next to it mentioning the percent change between the closing prices. For example, I would like to see the percent change between the previous day's closing price and the 3-day back closing price and display the percentage as a bubble next to the straight line connecting the respective closing prices. Can anyone please help me with a script?

Many thanks

This will draw a line between start and back bars and the values at those bars using enableapproximation().
You can change these at the input screen.
A bubble is placed at start bar with the...
Hello,

Draw straight line between two closing prices and add bubble showing percent change
I would like to connect two closing prices with a dashed, thick, straight line and add a bubble next to it mentioning the percent change between the closing prices. For example, I would like to see the percent change between the previous day's closing price and the 3-day back closing price and display the percentage as a bubble next to the straight line connecting the respective closing prices. Can anyone please help me with a script?

Many thanks
till someone creates a code , study this,
https://usethinkscript.com/threads/...hart-between-2-points-and-after-point2.15491/
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello,

Draw straight line between two closing prices and add bubble showing percent change
I would like to connect two closing prices with a dashed, thick, straight line and add a bubble next to it mentioning the percent change between the closing prices. For example, I would like to see the percent change between the previous day's closing price and the 3-day back closing price and display the percentage as a bubble next to the straight line connecting the respective closing prices. Can anyone please help me with a script?

Many thanks

This will draw a line between start and back bars and the values at those bars using enableapproximation().
You can change these at the input screen.
A bubble is placed at start bar with the information you requested.

Screenshot 2024-01-21 094254.png
Code:
input start_day  = 0;
input back_days  = 3;
input price1 = close;
input price2 = close;
input time1  = 1600;
input time2  = 1600;

def ymd = GetYYYYMMDD();
def bn  = BarNumber();
def na  = Double.NaN;

#Day Count
def ct  = if !IsNaN(close) and ymd != ymd[1] then ct[1] + 1 else ct[1];
def tct = HighestAll(ct) - ct;

#Barnumber @ Back/Time
def pt1 = if tct == start_day and SecondsFromTime(time1)[1] < 0 and SecondsFromTime(time1) >= 0 then bn else 0;
def pt2 = if tct == back_days and SecondsFromTime(time2)[1] < 0 and SecondsFromTime(time2) >= 0 then bn else 0;

#Price @ back/Time
def pr1 = if tct == start_day and SecondsFromTime(time1)[1] < 0 and SecondsFromTime(time1) >= 0 then price1 else pr1[1];
def pr2 = if tct == back_days and SecondsFromTime(time2)[1] < 0 and SecondsFromTime(time2) >= 0 then price2 else pr2[1];

#Line from Pt2 to Pt1
plot ln1 = if bn == HighestAll(pt1) then pr1 else if bn == HighestAll(pt2) then pr2 else Double.NaN;
ln1.EnableApproximation();

##Bubble @Pt1/Pr1
input bubble  = yes;
def   pctchg  = (pr1 - pr2) / pr2;

AddChartBubble(
bubble and bn == HighestAll(pt1),
pr1,
back_days + " days ago\n" +
pr1 + " - " + pr2 + "\n" +
AsText((pr1) - pr2) + " | " + AsPercent(pctchg),
Color.YELLOW);
 
#
 
Last edited:
Solution
This will draw a line between start and back bars and the values at those bars using enableapproximation().
You can change these at the input screen.
A bubble is placed at start bar with the information you requested.
Thank you so much, @SleepyZ! I was wondering if it could be modified to include a choice of aggregation starting from days to years, please. Also, I would request that the plots be available at time periods higher than intraday aggregations. Thank you again!
 
This will draw a line between start and back bars and the values at those bars using enableapproximation().
You can change these at the input screen.
A bubble is placed at start bar with the information you requested.
I have attached the code and tried to integrate your code in this script but seems like I am off the actual price locations. The straight connecting lines are between c1[getback] and c1[c2]. Can you please help @SleepyZ

1705899055057.png



Code:
input agg = aggregationPeriod.WEEK;

input getback = 5;

input go_from_getback = 3;

def c1 = close(period = agg);

def c2 = getback + go_from_getback;

def c3 = ((c1[getback])*100/c1[c2])-100;

def ymd = GetYYYYMMDD();
def bn  = BarNumber();
def na  = Double.NaN;

def ct  = if !IsNaN(close) and ymd != ymd[1] then ct[1] + 1 else ct[1];
def tct = HighestAll(ct) - ct;

#Barnumber @ Back/Time
def pt1 = if tct == getback then bn else 0;
def pt2 = if tct == c2 then bn else 0;

#Price @ back/Time
def pr1 = if tct == getback then  c1[getback] else pr1[1];
def pr2 = if tct == c2  then c1[c2] else pr2[1];

#Line from Pt2 to Pt1
plot ln1 = if bn == HighestAll(pt1) then pr1 else if bn == HighestAll(pt2) then pr2 else Double.NaN;
ln1.EnableApproximation();



AddLabel( yes, "Getback closing price : "+c1[getback], color.DARK_ORANGE);

AddLabel( yes, "Go from Getback closing price : "+c1[c2], color.CYAN);

AddLabel( yes, "Getback price increase(%) : "+c3, color.VIOLET);
 
I have attached the code and tried to integrate your code in this script but seems like I am off the actual price locations. The straight connecting lines are between c1[getback] and c1[c2]. Can you please help @SleepyZ

View attachment 20762


Code:
input agg = aggregationPeriod.WEEK;

input getback = 5;

input go_from_getback = 3;

def c1 = close(period = agg);

def c2 = getback + go_from_getback;

def c3 = ((c1[getback])*100/c1[c2])-100;

def ymd = GetYYYYMMDD();
def bn  = BarNumber();
def na  = Double.NaN;

def ct  = if !IsNaN(close) and ymd != ymd[1] then ct[1] + 1 else ct[1];
def tct = HighestAll(ct) - ct;

#Barnumber @ Back/Time
def pt1 = if tct == getback then bn else 0;
def pt2 = if tct == c2 then bn else 0;

#Price @ back/Time
def pr1 = if tct == getback then  c1[getback] else pr1[1];
def pr2 = if tct == c2  then c1[c2] else pr2[1];

#Line from Pt2 to Pt1
plot ln1 = if bn == HighestAll(pt1) then pr1 else if bn == HighestAll(pt2) then pr2 else Double.NaN;
ln1.EnableApproximation();



AddLabel( yes, "Getback closing price : "+c1[getback], color.DARK_ORANGE);

AddLabel( yes, "Go from Getback closing price : "+c1[c2], color.CYAN);

AddLabel( yes, "Getback price increase(%) : "+c3, color.VIOLET);

Nice work!!

Here are some mods that should help.

Screenshot 2024-01-22 105803.png
Code:
input agg = AggregationPeriod.WEEK;
input showvertical = yes;
AddVerticalLine(showvertical and GetWeek() != GetWeek()[1], "", color = Color.LIGHT_GRAY);
input getback = 5;

input go_from_getback = 3;

def c1 = close(period = agg);

def c2 = getback + go_from_getback;

def c3 = ((c1[getback]) * 100 / c1[c2]) - 100;

def ymd = if agg <= AggregationPeriod.DAY
then GetYYYYMMDD()
else if agg == AggregationPeriod.WEEK
then GetWeek()
else if agg==aggregationPeriod.MONTH
then GetMonth()
else
getyear();
#def ymd = getyyyYMMDD();
def bn  = BarNumber();
def na  = Double.NaN;

def ct  = if !IsNaN(close) and ymd != ymd[1] then ct[1] + 1 else ct[1];
def tct = HighestAll(ct) - ct;

#Barnumber @ Back/Time
def pt1 = if tct == getback then bn else 0;
def pt2 = if tct == c2 then bn else 0;

#Price @ back/Time
def pr1 = if bn == HighestAll(pt1) then c1 else pr1[1];#if tct == getback then  c1[getback] else pr1[1];
def pr2 = if bn == HighestAll(pt2) then c1 else pr2[1];#if tct == c2  then c1[c2] else pr2[1];

#Line from Pt2 to Pt1
plot ln1 = if bn == HighestAll(pt2) then c1 else if bn == HighestAll(pt1) then c1 else Double.NaN;
ln1.EnableApproximation();


AddLabel( yes, "Getback closing price : " + pr1, Color.DARK_ORANGE);

AddLabel( yes, "Go from Getback closing price : " + pr2, Color.CYAN);

AddLabel( yes, "Getback price increase(%) : " + c3, Color.VIOLET);
 
This will draw a line between start and back bars and the values at those bars using enableapproximation().
You can change these at the input screen.
A bubble is placed at start bar with the information you requested.
Is there a way to simplify it just to draw a straight line from the current close to n bars back?
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
410 Online
Create Post

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