# Percent (%) Difference Between Lowest Low and Highest High on Daily Chart

#### AstroBoy

##### New member
Hi Everyone!
I'm just trying to make a script to help measure Multi-Day Runners... On the daily chart, what's the highest high it's ever gotten in regular market hours in the past 10 days, compared to the lowest low in the past 10 days... And what Percent (%) higher is the highest high in comparison to the lowest low.
Problem: My script seems to be plotting out all the highs & lows each day on the daily chart, when really it should only be plotting a single line from the lowest low, and a single line from the highest high.
I was wondering if someone can take a look and help me?

Code:
``````input length = 0;
input aggregationPeriod = AggregationPeriod.DAY;

PLOT LowestPast10Days;
if !IsNaN (Lowest(low(period = aggregationPeriod)[-10])) {
LowestPast10Days = Double.NaN;
} else {
;
LowestPast10Days = Lowest(low(period = aggregationPeriod)[length]);
}
PLOT HighestPast10Days;
if !IsNaN (Highest(high(period = aggregationPeriod)[-10])) {
HighestPast10Days = Double.NaN;
} else {
;
HighestPast10Days = Highest(high(period = aggregationPeriod)[length]);
}

ADDLabel(yes, "%Higher: " + (((HighestPast10Days - LowestPast10Days) / LowestPast10Days) * 100), CreateColor(28, 168, 63));``````

Solution
Hi Everyone!
I'm just trying to make a script to help measure Multi-Day Runners... On the daily chart, what's the highest high it's ever gotten in regular market hours in the past 10 days, compared to the lowest low in the past 10 days... And what Percent (%) higher is the highest high in comparison to the lowest low.
Problem: My script seems to be plotting out all the highs & lows each day on the daily chart, when really it should only be plotting a single line from the lowest low, and a single line from the highest high.
I was wondering if someone can take a look and help me?

Code:
``````input length = 0;
input aggregationPeriod = AggregationPeriod.DAY;

PLOT LowestPast10Days;
if !IsNaN (Lowest(low(period =...``````
Hi Everyone!
I'm just trying to make a script to help measure Multi-Day Runners... On the daily chart, what's the highest high it's ever gotten in regular market hours in the past 10 days, compared to the lowest low in the past 10 days... And what Percent (%) higher is the highest high in comparison to the lowest low.
Problem: My script seems to be plotting out all the highs & lows each day on the daily chart, when really it should only be plotting a single line from the lowest low, and a single line from the highest high.
I was wondering if someone can take a look and help me?

Code:
``````input length = 0;
input aggregationPeriod = AggregationPeriod.DAY;

PLOT LowestPast10Days;
if !IsNaN (Lowest(low(period = aggregationPeriod)[-10])) {
LowestPast10Days = Double.NaN;
} else {
;
LowestPast10Days = Lowest(low(period = aggregationPeriod)[length]);
}
PLOT HighestPast10Days;
if !IsNaN (Highest(high(period = aggregationPeriod)[-10])) {
HighestPast10Days = Double.NaN;
} else {
;
HighestPast10Days = Highest(high(period = aggregationPeriod)[length]);
}

ADDLabel(yes, "%Higher: " + (((HighestPast10Days - LowestPast10Days) / LowestPast10Days) * 100), CreateColor(28, 168, 63));``````

draw horizontal lines, for the last x days on a chart, of the highest and lowest prices, during that period.

this finds the first bar, on the x day before the last bar. then it finds the highest and lowest for the desired period, from that bar to the last bar.

you mentioned using a daily chart, but are using 2nd aggrregation (period=..day) to define DAY data. so i kept the 2nd aggregation parameters, so this will work on shorter time periods, from 1 minute to day.
i changed a couple of constants , 10, to length, so any day quantity can be entered.

can show 1 bubble on each day, with a day count.
there are several bubble code lines that can be turned on, to show variable values. i use them for testing when creating.

Ruby:
``````# prev_xdays_hiloper_00

def na = double.nan;
input length = 10;
input aggregationPeriod = AggregationPeriod.DAY;

# true during desired days
def dayz = ( !isnan(close(period = aggregationPeriod)) and isnan(close(period = aggregationPeriod)[-length] ));

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

# find a day x days before the last day on chart
def dayx = ( !isnan(close(period = aggregationPeriod)[-(length-1)] ) and isnan(close(period = aggregationPeriod)[-(length+0)] ));

# find first bar of a day
def dayofwk = GetDayofWeek(GetYYYYMMDD() );
def diffday = (dayofwk <> dayofwk[1] );

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

# find the lowest low for the last x days on the chart,
#   on 1st bar of the day that is x days from the last bar
def  LowestPastxDays =  if (dayx and diffday) then Lowest(low(period = aggregationPeriod)[-(length-1)], length) else na;

def lo = if !dayz then na else if (dayx and diffday) then LowestPastxDays else lo[1];
plot lo2 = lo;
lo2.setdefaultcolor(color.magenta);

# -------------------------------------
# find the highest high for the last x days on the chart,
#   on 1st bar of the day that is x days from the last bar
def  highestPastxDays =  if (dayx and diffday) then highest(high(period = aggregationPeriod)[-(length-1)], length) else na;

def hi = if !dayz then na else if (dayx and diffday) then highestPastxDays else hi[1];
plot hi2 = hi;
hi2.setdefaultcolor(color.magenta);

# -------------------------------------
# what % is the hi line above the lo line
def per = round(((hi - lo) / lo) * 100, 1);

ADDLabel(yes, "% Higher: " + per, CreateColor(28, 168, 63));

# -------------------------------------
# test data
input show_test_bubbles = no;
addchartbubble( show_test_bubbles and dayz , low, "--" , color.yellow, no);
addchartbubble( show_test_bubbles and dayx , high, "--" , color.white, yes);
addchartbubble(show_test_bubbles and dayz and diffday, low, lo, color.magenta, no);

def daycnt = if !dayz then na else if (dayx and diffday) then 1 else if diffday then daycnt[1] + 1 else daycnt[1];
input test_day_count = yes;
addchartbubble( test_day_count and dayz and diffday, low*0.99, daycnt, color.gray, no);
#``````

draw horizontal lines, for the last x days on a chart, of the highest and lowest prices, during that period.

this finds the first bar, on the x day before the last bar. then it finds the highest and lowest for the desired period, from that bar to the last bar.

you mentioned using a daily chart, but are using 2nd aggrregation (period=..day) to define DAY data. so i kept the 2nd aggregation parameters, so this will work on shorter time periods, from 1 minute to day.
i changed a couple of constants , 10, to length, so any day quantity can be entered.

can show 1 bubble on each day, with a day count.
there are several bubble code lines that can be turned on, to show variable values. i use them for testing when creating.

Ruby:
``````# prev_xdays_hiloper_00

def na = double.nan;
input length = 10;
input aggregationPeriod = AggregationPeriod.DAY;

# true during desired days
def dayz = ( !isnan(close(period = aggregationPeriod)) and isnan(close(period = aggregationPeriod)[-length] ));

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

# find a day x days before the last day on chart
def dayx = ( !isnan(close(period = aggregationPeriod)[-(length-1)] ) and isnan(close(period = aggregationPeriod)[-(length+0)] ));

# find first bar of a day
def dayofwk = GetDayofWeek(GetYYYYMMDD() );
def diffday = (dayofwk <> dayofwk[1] );

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

# find the lowest low for the last x days on the chart,
#   on 1st bar of the day that is x days from the last bar
def  LowestPastxDays =  if (dayx and diffday) then Lowest(low(period = aggregationPeriod)[-(length-1)], length) else na;

def lo = if !dayz then na else if (dayx and diffday) then LowestPastxDays else lo[1];
plot lo2 = lo;
lo2.setdefaultcolor(color.magenta);

# -------------------------------------
# find the highest high for the last x days on the chart,
#   on 1st bar of the day that is x days from the last bar
def  highestPastxDays =  if (dayx and diffday) then highest(high(period = aggregationPeriod)[-(length-1)], length) else na;

def hi = if !dayz then na else if (dayx and diffday) then highestPastxDays else hi[1];
plot hi2 = hi;
hi2.setdefaultcolor(color.magenta);

# -------------------------------------
# what % is the hi line above the lo line
def per = round(((hi - lo) / lo) * 100, 1);

ADDLabel(yes, "% Higher: " + per, CreateColor(28, 168, 63));

# -------------------------------------
# test data
input show_test_bubbles = no;
addchartbubble( show_test_bubbles and dayz , low, "--" , color.yellow, no);
addchartbubble( show_test_bubbles and dayx , high, "--" , color.white, yes);
addchartbubble(show_test_bubbles and dayz and diffday, low, lo, color.magenta, no);

def daycnt = if !dayz then na else if (dayx and diffday) then 1 else if diffday then daycnt[1] + 1 else daycnt[1];
input test_day_count = yes;
addchartbubble( test_day_count and dayz and diffday, low*0.99, daycnt, color.gray, no);
#``````

View attachment 12727
How to take away the counter away and show only High and Low lines?

How to take away the counter away and show only High and Low lines?

by changing this to no
input test_day_count = yes;

you can edit the code or change it in edt studies

studies, edit studies
find this study in your list of loaded studies and click on the gear symbol, to the right of the name.

a window will open that lists variables defined with input, that are changable.

by changing this to no
input test_day_count = yes;

you can edit the code or change it in edt studies

studies, edit studies
find this study in your list of loaded studies and click on the gear symbol, to the right of the name.

a window will open that lists variables defined with input, that are changable.
learn the magic! tks

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