52 week high/low line on intraday charts

Xikar

New member
I thought I posted this already but maybe it didn’t go through.

What would be the script to draw a line showing the 52 week (or low, I want two different scans) that will do it but on a 5m intraday chart?
 
Solution
I thought I posted this already but maybe it didn’t go through.

What would be the script to draw a line showing the 52 week (or low, I want two different scans) that will do it but on a 5m intraday chart?

this will plot highest and lowest price lines, over some quantity of 2nd aggregation bars
but it won't cover 1 year at 5 minutes.
i set the default length to 25 periods, so it should display the lines.

a trading day has 390 , 1 minute bars.
a 5 min chart has 78 bars in a day.
a 5 minute chart has 19,656 bars in a year (252 days), probably more than will be displayed.

i can't make a chart timeframe of 5 minute / 1 year.
can make 5 minute / 180 days.

on 5min/180 days, can choose up to 36 weeks, to show up, maybe more, maybe...
I thought I posted this already but maybe it didn’t go through.

What would be the script to draw a line showing the 52 week (or low, I want two different scans) that will do it but on a 5m intraday chart?

this will plot highest and lowest price lines, over some quantity of 2nd aggregation bars
but it won't cover 1 year at 5 minutes.
i set the default length to 25 periods, so it should display the lines.

a trading day has 390 , 1 minute bars.
a 5 min chart has 78 bars in a day.
a 5 minute chart has 19,656 bars in a year (252 days), probably more than will be displayed.

i can't make a chart timeframe of 5 minute / 1 year.
can make 5 minute / 180 days.

on 5min/180 days, can choose up to 36 weeks, to show up, maybe more, maybe less. it takes a few seconds for the chart to load.


there are 2 labels, for the highest and lowest values.
at the start of the period, it draws,
. a vertical line
. an up arrow on 1st bar of the first period


Code:
# agg_hilo_lines_01

# find the hi and lo of some x qty of agg periods, before the last bar
#  find 1st agg period , len qty of periods before last bar
#   find 1st bar in each agg period
#    find 1st bar , in 1st agg period 

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 agg = AggregationPeriod.week;
input len = 52;

#diffday
# on a daily chart, this is always true
def diffday = if getday() != getday()[1] then 1 else 0;

# first bar in len series ?
def first_agg = (!isnan(close(period = agg)[-len]) and isnan(close(period = agg)[-(len+1)]));

# find first day of week,
def dow = GetDayofWeek(GetYYYYMMDD());
def firstdayofweek = 
     if dow[1] == 5 and dow == 1 then 1
else if dow[1] == 4 and dow == 1 then 1
else if dow[1] == 5 and dow == 2 then 1
else 0;


#def series_first_bar = if firstdayofweek and first_agg then 1 else na;
def series_first_bar = if firstdayofweek and first_agg then 1 else 0;


plot zz = series_first_bar;
zz.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
zz.SetDefaultColor(Color.white);
zz.setlineweight(1);
zz.hidebubble();

def t = if series_first_bar then 1 else 0;
addverticalline(t, "-", color.yellow);

def hi1;
def lo1;
if bn == 1 or isnan(close) then {
  hi1 = na;
  lo1 = na;
} else if t then {
hi1 = fold i = 0 to lastbn - bn + 1
with p = 0
do ( if getvalue(high, -i) > p then getvalue(high, -i) else p);

lo1 = fold j = 0 to lastbn - bn + 1
with q = 99999
do ( if getvalue(low, -j) < q then getvalue(low, -j) else q);
} else {
  hi1 = hi1[1];
  lo1 = lo1[1];
}

plot zhi = if !isnan(hi1) and hi1 > 0 then hi1 else na;
zhi.setdefaultcolor(color.cyan);
plot zlo = if !isnan(lo1) and lo1 > 0 then lo1 else na;
zlo.setdefaultcolor(color.cyan);

addlabel(1, "Highest " + round(hi1,2), color.green);
addlabel(1, "Lowest " + round(lo1,2), color.red);

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

addchartbubble(0, 35,
 diffday + " diffd\n" +
 dow + " dow\n" +
 firstdayofweek + " 1day/wk\n" +
 first_agg + "\n" +
 series_first_bar
, (#if series_first_bar then color.green else
 if firstdayofweek then color.yellow
else if diffday then color.magenta
 else color.gray), no);


addchartbubble(0 and bn < 20, 5,
hi1 + "\n" +
zhi + "\n" +
lo1 + "\n" +
zlo
, color.yellow, yes);


addchartbubble(0, low,
#a + "\n" +
first_agg + "\n" +
t
,(if first_agg then color.yellow else color.gray), no);
#


3QQmUFs.jpg
 
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
457 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