#diag_line_hilox
#https://usethinkscript.com/threads/draw-a-lines-between-two-points.20658/
#Draw a lines between two points , highest(high,60) and Lowest(low,60).
def na = double.nan;
def bn = barnumber();
input len = 60;
# find bar x bars before last bar
def x = (!isnan(close[-(len-1)]) and isnan(close[-(len)]));
def n = 300;
# on the x bar before last bar, find the highest and lowest
# calc slope of diag line between highest and lowest
def hi;
def lo;
def hibn;
def lobn;
def barz;
def slope;
def first_pr;
if bn == 1 then {
hi = 0;
lo = 0;
hibn = 0;
lobn = 0;
barz = 0;
slope = 0;
first_pr = 0;
} else if x then {
hi = highest(high[-(len-1)],len);
lo = lowest(low[-(len-1)],len);
hibn = bn + (fold a = 0 to n
with b
while (getvalue(high,-a) != hi)
do b + 1);
lobn = bn + (fold c = 0 to n
with d
while (getvalue(low,-c) != lo)
do d + 1);
barz = (hibn - lobn) + 0;
slope = (hi-lo)/barz;
first_pr = if hibn < lobn then hi else lo;
} else {
hi = hi[1];
lo = lo[1];
hibn = hibn[1];
lobn = lobn[1];
slope = slope[1];
barz = barz[1];
first_pr = first_pr[1];
}
def maxx = max(hibn,lobn);
def minx = min(hibn,lobn);
# need to calc price at first hi/lo
def t = if bn < minx then 0
else if bn == minx then first_pr
else if bn > minx and bn <= maxx then t[1] + slope
else 0;
plot z = if t > 0 then t else na;
z.SetDefaultColor(Color.cyan);
z.setlineweight(2);
z.hidebubble();
#z.SetStyle(Curve.MEDIUM_DASH);
input test_vline = yes;
addverticalline(test_vline and x,"-");
input test_bubble = no;
addchartbubble(test_bubble , low*0.995,
bn + "\n" +
high + "\n" +
hi + " hi\n" +
hibn + " hbn\n" +
low + "\n" +
lo + " lo\n" +
lobn + " lbn\n" +
barz + " b\n" +
slope
, color.yellow, no);
#