PB % on Daily Chart

DoQtorNo

Member
VIP
im attempting to create/modify a script that plots a line on a daily chart at 5% 10% 20% 25% respective pullbacks from both HOY and ATH (the option to switch between the two) so 4 lines on daily chart. im missing something and getting stuck here. I've attached screenshot of what the script should look like applied to chart.

input daily_percent_bubbles = yes;
input Move_bubble_left = 33; #hint Move_bubble_left: This will move the Weekly EM Bubbles left and right
input bubble_left = 15; #hint bubble_left: This will move the % Bubbles left and right
input ShowTodayOnly = yes;
input lite_chart = yes;
def showPlot = !ShowTodayOnly ;

def PH = high(period = AggregationPeriod.YEAR)[1];
def PL = low(period = AggregationPeriod.YEAR)[1];
def PC = close(period = AggregationPeriod.YEAR)[1];


def Dn_5 = close - ((close * 5.0)*0.01);
def Dn_10 = close - ((close * 10.0)*0.01);
def Dn_20 = close - ((close * 20.0)*0.01);
def Dn_25 = close - ((close * 25.0)*0.01);


plot percent_5;
plot neg_pct_10;
plot neg_pct_25;
plot neg_pct_10;

Thanks in Advance
IMG_0373.PNG


To follow up, this is what a finished version would look like via TOS, the above code was taken from pictured script.

thanks Again
1725492116452.png
 
Last edited by a moderator:
Solution
im attempting to create/modify a script that plots a line on a daily chart at 5% 10% 20% 25% respective pullbacks from both HOY and ATH (the option to switch between the two) so 4 lines on daily chart. im missing something and getting stuck here. I've attached screenshot of what the script should look like applied to chart.

input daily_percent_bubbles = yes;
input Move_bubble_left = 33; #hint Move_bubble_left: This will move the Weekly EM Bubbles left and right
input bubble_left = 15; #hint bubble_left: This will move the % Bubbles left and right
input ShowTodayOnly = yes;
input lite_chart = yes;
def showPlot = !ShowTodayOnly ;

def PH = high(period = AggregationPeriod.YEAR)[1];
def PL = low(period = AggregationPeriod.YEAR)[1]...
im attempting to create/modify a script that plots a line on a daily chart at 5% 10% 20% 25% respective pullbacks from both HOY and ATH (the option to switch between the two) so 4 lines on daily chart. im missing something and getting stuck here. I've attached screenshot of what the script should look like applied to chart.

input daily_percent_bubbles = yes;
input Move_bubble_left = 33; #hint Move_bubble_left: This will move the Weekly EM Bubbles left and right
input bubble_left = 15; #hint bubble_left: This will move the % Bubbles left and right
input ShowTodayOnly = yes;
input lite_chart = yes;
def showPlot = !ShowTodayOnly ;

def PH = high(period = AggregationPeriod.YEAR)[1];
def PL = low(period = AggregationPeriod.YEAR)[1];
def PC = close(period = AggregationPeriod.YEAR)[1];


def Dn_5 = close - ((close * 5.0)*0.01);
def Dn_10 = close - ((close * 10.0)*0.01);
def Dn_20 = close - ((close * 20.0)*0.01);
def Dn_25 = close - ((close * 25.0)*0.01);


plot percent_5;
plot neg_pct_10;
plot neg_pct_25;
plot neg_pct_10;

Thanks in Advance

here is my version of your question
find a high price level and draw 5 lines under it, at a % spacing
line levels are based off of values on last bar

enter a start percent ( 5% down ) from highest
enter a percent spacing ( 5% ) of highest

pick which highest high to use:
..ATH (highest on chart)
..HOY (high of current year)
..past 12 months

labels show,
..the 3 highest prices. chosen one is yellow
..start and spacing %

if some of the lines are below the lowest price, they are not drawn

bubbles with % number are drawn at 50 bars before the last bar. can be changed


day chart / 2 year
test symbols, that have diff highs for (ATH, HOY, 12month)
PFE
NKE
CVX , 3 lines because lines 4 and 5 would be lower than lowest price on chart, so are not drawn.

img-b.JPG


Code:
#lines_from_hoy_ath

#  test symbols , day chart / 2 year , diff highs for {ATH, HOY, 12month)
#   PFE
#   NKE
#   CVX , 3 lines


#https://usethinkscript.com/threads/pb-on-daily-chart.19586/
#PB % on Daily Chart
#DoQtorNo  9/4  #1


# daily chart
# pick  HOY or ATH
# plots 4 lines
# at 5% 10% 20% 25% , below the highest value

# pick start %  , 5%
# pick % spacing , 5
# draw 5 lines


def na = double.nan;
def bn = barnumber();
def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

input pick_start_percent = 5.0;
input pick_percent_spacing = 5.0;

def m = getmonth();
def y = getyear();
def isyear = y == getlastyear();
def lastyear = getlastyear();

def lastm = highestall(if lastbar then m else 0);
def prevm = if lastm == 1 then 12 else lastm - 1;
def nextm = if lastm == 12 then 1 else lastm + 1;

# bn of  12 months before last bar
def bn_12mo = if bn == 1 then 0
 else if ( (y[1] == lastyear-1 and m[1] == m) and (y == (lastyear - 1) and m == nextm) )
 then bn else 0;
# else bn_12mo[1];

# configure high values to be from current year
def hihi = highestall(high);
def lolo = lowestall(low);
def yrhi2 = if isyear then high(period = aggregationperiod.year) else 0;
def yrhi = highestall(yrhi2);

def month12_hi2 = highest(high(period = aggregationperiod.month), 12);
def month12_hi = highestall(if lastbar then month12_hi2 else 0);

input high_reference = { ATH , default HOY , past_12month_hi };

def hix;
def p;
switch (high_reference) {
case ATH:
 hix = hihi;
 p = 1;
case HOY:
 hix = yrhi;
 p = 2;
case past_12month_hi:
 hix = month12_hi;
 p = 3;
}

def startpr = round(hix * (100 - pick_start_percent)/100,2);
def incr = round(hix * pick_percent_spacing/100,2);

def l0 = hix;
def l1 = startpr;
def l2 = startpr - (incr * 1);
def l3 = startpr - (incr * 2);
def l4 = startpr - (incr * 3);
def l5 = startpr - (incr * 4);

plot z0 = l0;
plot z1 = if l1 < lolo then na else l1;
plot z2 = if l2 < lolo then na else l2;
plot z3 = if l3 < lolo then na else l3;
plot z4 = if l4 < lolo then na else l4;
plot z5 = if l5 < lolo then na else l5;

input bubble_bar_back = 50;
def bub = !isnan(close[-bubble_bar_back]) and isnan(close[-(bubble_bar_back+1)]);
addchartbubble(bub, z1, -pick_start_percent + "%", color.pink, yes);
addchartbubble(bub, z2, -(pick_start_percent + (1 * pick_percent_spacing)) + "%", color.pink, yes);
addchartbubble(bub, z3, -(pick_start_percent + (2 * pick_percent_spacing)) + "%", color.pink, yes);
addchartbubble(bub, z4, -(pick_start_percent + (3 * pick_percent_spacing)) + "%", color.pink, yes);
addchartbubble(bub, z5, -(pick_start_percent + (4 * pick_percent_spacing)) + "%", color.pink, yes);


#  ATH , HOY , 12mo   p= 1,2,3
addlabel(1, "        ", color.black);
addlabel(1, "hihi " + hihi, (if p == 1 then color.yellow else color.gray));
addlabel(1, "year hi " + yrhi, (if p==2 then color.yellow else color.gray));
addlabel(1, "12 month hi " +month12_hi, (if p==3 then color.yellow else color.gray));

addlabel(1, "        ", color.black);
#addlabel(1, "highest  $" + hix, color.cyan);
addlabel(1, "start % = " + pick_start_percent + "% :  $" + startpr , color.cyan);
addlabel(1, "increment % = " + pick_percent_spacing + "% :  $" + incr, color.cyan);

#-----------------------------

addchartbubble(0, low,
 bn + "\n" +
 bn_12mo
, (if bn_12mo > 0 then color.yellow else color.gray), no);

#
 
Last edited:
Solution

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

after installation, it is wonderful. again, thank you. beggars certainly cannot be choosers, if possible the one and only thing I would alter is the "length" of the line. is there a way to edit so it doesn't extend across the screen? im happy to play with the script if something I can do on my end.

I did notice I could also "not plot" the line and just keep the bubbles floating, willing to do that if need be.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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