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 =...

halcyonguy

Well-known member
VIP
Lifetime
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);
#


S7twTsb.jpg
 
Solution

Similar threads

Top