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.
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);
#