Highest High and Lowest Low of Previous N Days

C4men

Member
I am just looking for two horizontal lines to appear on my 15min timeframe chart:

Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart

For whatever reason, it does not seem to work no matter what I try and I am sure it is very simple.
Maybe something to do with a higher timeframe?

Any thoughts?
 
Solution
I am just looking for two horizontal lines to appear on my 15min timeframe chart:

Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart

For whatever reason, it does not seem to work no matter what I try and I am sure it is very simple.
Maybe something to do with a higher timeframe?

Any thoughts?
don't know if you are still around?
i came across this post and reread it a few times.
i think this is what you are after

goes back 1 day, then finds the high and low of the 5 days before


Code:
#hilo_agg_xdays_02...
I am just looking for two horizontal lines to appear on my 15min timeframe chart:

Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart

For whatever reason, it does not seem to work no matter what I try and I am sure it is very simple.
Maybe something to do with a higher timeframe?

Any thoughts?
post the code you tried
 
I am just looking for two horizontal lines to appear on my 15min timeframe chart:

Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart

For whatever reason, it does not seem to work no matter what I try and I am sure it is very simple.
Maybe something to do with a higher timeframe?

Any thoughts?

is this what you are thinking of ?

Code:
#hilo_agg_xdays

#https://usethinkscript.com/threads/highest-high-and-lowest-low-of-previous-n-days.17773/
#Highest High and Lowest Low of Previous N Days

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

def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);

input agg = AggregationPeriod.DAY;
input days = 5;

def hi = highest(high(period = agg), days);
def lo = lowest(low(period = agg), days);

plot zhi = hi;
plot zlo = lo;


#

C 15min
5 day high and low lines
sWGqY7g.jpg
 
is this what you are thinking of ?

Code:
#hilo_agg_xdays

#https://usethinkscript.com/threads/highest-high-and-lowest-low-of-previous-n-days.17773/
#Highest High and Lowest Low of Previous N Days

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

def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);

input agg = AggregationPeriod.DAY;
input days = 5;

def hi = highest(high(period = agg), days);
def lo = lowest(low(period = agg), days);

plot zhi = hi;
plot zlo = lo;


#

C 15min
5 day high and low lines
sWGqY7g.jpg

That's pretty close (and thank you).

The only thing is it looks like it is "counting" the current day high or low. I would always want it to start at "yesterday".
That way the line for today would represent the highest high (or lowest low) of the previous five days
 
That's pretty close (and thank you).

The only thing is it looks like it is "counting" the current day high or low. I would always want it to start at "yesterday".
That way the line for today would represent the highest high (or lowest low) of the previous five days
oops , i missed the previous part

here is another version that has an offset, default set to 1

Code:
#hilo_agg_prev_xdays

#https://usethinkscript.com/threads/highest-high-and-lowest-low-of-previous-n-days.17773/
#Highest High and Lowest Low of Previous N Days

#Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
#Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart


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

def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);
input bars_offset = 1;

input agg = AggregationPeriod.DAY;
input days = 5;

def hi = highest(high(period = agg)[bars_offset], days);
def lo = lowest(low(period = agg)[bars_offset], days);

plot zhi = hi;
plot zlo = lo;
#
 
I am just looking for two horizontal lines to appear on my 15min timeframe chart:

Line 1 - Finds the highest high of the previous five days (or X days) and plots it on my 15 min chart
Line 2 - Finds the lowest low of the previous five days (or X days) and plots it on my 15 min chart

For whatever reason, it does not seem to work no matter what I try and I am sure it is very simple.
Maybe something to do with a higher timeframe?

Any thoughts?
don't know if you are still around?
i came across this post and reread it a few times.
i think this is what you are after

goes back 1 day, then finds the high and low of the 5 days before


Code:
#hilo_agg_xdays_02

#https://usethinkscript.com/threads/highest-high-and-lowest-low-of-previous-n-days.17773/
#Highest High and Lowest Low of Previous N Days

def na = Double.NaN;
def bn = BarNumber();
def big = 99999;

def d = getday();
def newday = d != d[1];

def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);

def agg = AggregationPeriod.DAY;
input hilo_days_back = 5;
input read_from_x_days_back = 1;


addlabel(1, "hilo_days_back " + hilo_days_back , color.cyan);
addlabel(1, "read_from_x_days_back " + read_from_x_days_back, color.cyan);

def n = 800;

def hi;
def lo;
def daycnt;
if bn == 1 or isnan(close) then {
 hi = 0;
 lo = 0;
 daycnt = 0;
} else if newday and !isnan(close(period = agg)[-(hilo_days_back + read_from_x_days_back-1)])
   and isnan(close(period = agg)[-(hilo_days_back + read_from_x_days_back+0)]) then { 

daycnt = fold y = 0 to n
 with g
 while g <= hilo_days_back+1
 do if g > hilo_days_back then y
  else if getvalue(newday, -y) and g >= hilo_days_back then y
  else if getvalue(newday, -y) then g + 1
  else g;

 hi = fold a = 0 to daycnt
 with b
 do max(getvalue(high,-a),b);

 lo = fold e = 0 to daycnt
 with f = big
 do min(getvalue(low,-e),f);

} else {
 hi = hi[1];
 lo = lo[1];
 daycnt = daycnt[1];
}

plot zhi = if hi > 0 then hi else na;
plot zlo = if lo > 0 then lo else na;

addchartbubble(0,low,
bn + "\n" +
daycnt
,color.yellow,no);
#
 

Attachments

  • 00d.JPG
    00d.JPG
    70.2 KB · Views: 95
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
428 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