show the daily highest and lowest prices, from the last 5 days

halcyonguy

Moderator - Expert
VIP
Lifetime
use labels, to show the daily highest and lowest prices, from the current day to several previous days.
can pick quantity of days to show , 1 to 5.
shows first letter of the day, then high and low.

Code:
#hilo_5days_labels

#qty labels to show ,  1-5
# labels , show day high and day low, for up to 5 days

def na = double.nan;
def bn = barnumber();
def n = 2;

def dow = GetDayofWeek(GetYYYYMMDD());
# dow , 1 = monday, 5 = friday

def agg = AggregationPeriod.DAY;
input qty_of_days = 5;

# dow #s
def d0 = if !isnan(close(period = agg)[0]) and isnan(close(period = agg)[-1]) then dow else d0[1];
def d1 = if !isnan(close(period = agg)[-1]) and isnan(close(period = agg)[-2]) then dow else d1[1];
def d2 = if !isnan(close(period = agg)[-2]) and isnan(close(period = agg)[-3]) then dow else d2[1];
def d3 = if !isnan(close(period = agg)[-3]) and isnan(close(period = agg)[-4]) then dow else d3[1];
def d4 = if !isnan(close(period = agg)[-4]) and isnan(close(period = agg)[-5]) then dow else d4[1];

def d0hi = round(high(period = agg),n);
def d0lo = round(low(period = agg),n);
def d1hi = round(high(period = agg)[1],n);
def d1lo = round(low(period = agg)[1],n);
def d2hi = round(high(period = agg)[2],n);
def d2lo = round(low(period = agg)[2],n);
def d3hi = round(high(period = agg)[3],n);
def d3lo = round(low(period = agg)[3],n);
def d4hi = round(high(period = agg)[4],n);
def d4lo = round(low(period = agg)[4],n);

addlabel(1, " ", color.black);
addlabel(qty_of_days <1 or qty_of_days > 5, " <<<< change qty_of_days to be 1 to 5 >>>>", color.cyan);

addlabel(qty_of_days >=5,
(if d4 == 1 then "M" else if d4 == 2 then "T" else if d4 == 3 then "W" else if d4 == 4 then "TH" else if d4 == 5 then "F" else "-"), color.yellow);
addlabel(qty_of_days >=5, d4hi, color.cyan);
addlabel(qty_of_days >=5, d4lo, color.magenta);

addlabel(qty_of_days >=4,
(if d3 == 1 then "M" else if d3 == 2 then "T" else if d3 == 3 then "W" else if d3 == 4 then "TH" else if d3 == 5 then "F" else "-"), color.yellow);
addlabel(qty_of_days >=4, d3hi, color.cyan);
addlabel(qty_of_days >=4, d3lo, color.magenta);

addlabel(qty_of_days >=3,
(if d2 == 1 then "M" else if d2 == 2 then "T" else if d2 == 3 then "W" else if d2 == 4 then "TH" else if d2 == 5 then "F" else "-"), color.yellow);
addlabel(qty_of_days >=3, d2hi, color.cyan);
addlabel(qty_of_days >=3, d2lo, color.magenta);

addlabel(qty_of_days >=2,
(if d1 == 1 then "M" else if d1 == 2 then "T" else if d1 == 3 then "W" else if d1 == 4 then "TH" else if d1 == 5 then "F" else "-"), color.yellow);
addlabel(qty_of_days >=2, d1hi, color.cyan);
addlabel(qty_of_days >=2, d1lo, color.magenta);

addlabel(qty_of_days >=1,
(if d0 == 1 then "M" else if d0 == 2 then "T" else if d0 == 3 then "W" else if d0 == 4 then "TH" else if d0 == 5 then "F" else "-"), color.yellow);
addlabel(qty_of_days >=1, d0hi, color.cyan);
addlabel(qty_of_days >=1, d0lo, color.magenta);
#

da7HVpc.jpg
 

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

can we get the highest and lowest price (H and L) of the previous day and draw the HORIZONTAL line with this code. No matter what frame time we use

H.setpaintingStrategy(paintingStrategy.HORIZONTAL);
H.setdefaultColor(color.green);

L.setpaintingStrategy(paintingStrategy.HORIZONTAL);
L.setdefaultColor(color.red);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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