# test_highestbn_05e
# https://usethinkscript.com/threads/plot-only-the-high-from-the-last-65-most-recent-days.7483/
# find the highest high, in the most rect x bars
def na = Double.NaN;
def bn = BarNumber();
def lastbar = HighestAll(if !IsNaN(close) then bn else na);
input look_back_bars = 65;
# is the current bar within the lookback quantity of bars? true/false
def rng = (lastbar - bn <= look_back_bars);
def hi = fold i = 0 to look_back_bars
with p
do if !rng then 0 else if GetValue(high, (bn - (lastbar - i))) > p then GetValue(high, (bn - (lastbar - i))) else p;
plot hix = HighestAll(hi);
hix.SetDefaultColor(Color.yellow);
hix.SetStyle(Curve.MEDIUM_DASH);
# test code -------------------------
# identify the first bar in the lookback group
def firstbar = (!IsNaN(close[-look_back_bars]) and IsNaN(close[-(look_back_bars + 1)]));
plot f = firstbar;
f.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
f.SetDefaultColor(Color.yellow);
f.setlineweight(4);
AddVerticalLine(firstbar, "xx" , Color.CYAN );
input show_barnumber_bubbles = no;
addchartbubble(show_barnumber_bubbles, low * 0.995, bn + "\n" + "x", color.cyan, no);
#addchartbubble(1, high * 1.01, hi, color.cyan, yes);
#
#--------------------------------
# lowest from prev x bars
def lolo = lowestall(if rng then low else na);
plot lox = lolo;
lox.SetDefaultColor(Color.magenta);
lox.SetStyle(Curve.MEDIUM_DASH);
#