# bigvol_sr_horzlines_01
# 04/03 update
# chg price from close to open. use an input for user to change
# add color to lines
# https://usethinkscript.com/threads/volume-support-resistance-zones.10103/#post-90471
# Volume Support & Resistance Zones
declare upper;
def na = Double.NaN;
def bn = BarNumber();
def v = volume;
input volavg_len = 20;
def vavg = Average(v, volavg_len);
input volavg_factor = 1.5;
def volf = floor(vavg * volavg_factor);
def vxup = if v crosses above volf then 1 else 0;
#----------------------
# approx green and red vol, based on where the candle closes.
# cant read time-sales data.
# this is not accurate, won't match time and sales data.
def O = open;
def H = high;
def C = close;
def L = low;
#def V = volume;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);
def isvolgrn = ( buying > selling);
#----------------------
# if lmax Is increased > 15, then more formulas will have to be added, L# and plot commands.
def lmax = 15;
input qty_of_lines = 15;
def lqty = if qty_of_lines < 1 then 1
else if qty_of_lines > lmax then lmax
else qty_of_lines;
#----------------------
# incr line counter on each vol trigger
# counts 1 to qty_of_lines, then resets to 1
def linecnt = if bn == 1 then 0
else if vxup and linecnt[1] == qty_of_lines then 1
else if vxup then linecnt[1] + 1
else linecnt[1];
input show_wedge_on_vol_trigger = no;
plot w = if show_wedge_on_vol_trigger and vxup then 1 else 0;
w.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
w.SetDefaultColor(Color.WHITE);
#w.SetLineWeight(2);
#--------------------------------------
addlabel(1, "volavg_len " + volavg_len, color.yellow);
addlabel(1, "volavg_factor " + volavg_factor, color.yellow);
input show_line_count = no;
plot y1 = if vxup and show_line_count then linecnt else na;
y1.SetPaintingStrategy(PaintingStrategy.VALUES_below);
y1.SetDefaultColor(Color.white);
#y1.setlineweight(1);
y1.hidebubble();
input test1_labels = no;
addlabel( test1_labels, "vol cross up " + vxup, color.yellow);
addlabel( test1_labels, "qty_of_lines " + qty_of_lines, color.yellow);
addlabel( test1_labels, "linecnt " + linecnt, color.yellow);
input test2_linecnt_bubbles = no;
addchartbubble(test2_linecnt_bubbles, low*0.997,
bn + " bn\n" +
vxup + " x\n" +
linecnt + " cnt"
, ( if vxup then color.yellow else color.gray), no);
#----------------------
# def linelevel = low;
# chg line starting point
input linelevel = close;
#def init = na;
def init = 0;
def L1 = if bn == 1 then init else if (vxup and linecnt == 1) then linelevel else L1[1];
def L2 = if bn == 1 then init else if (vxup and linecnt == 2) then linelevel else L2[1];
def L3 = if bn == 1 then init else if (vxup and linecnt == 3) then linelevel else L3[1];
def L4 = if bn == 1 then init else if (vxup and linecnt == 4) then linelevel else L4[1];
def L5 = if bn == 1 then init else if (vxup and linecnt == 5) then linelevel else L5[1];
def L6 = if bn == 1 then init else if (vxup and linecnt == 6) then linelevel else L6[1];
def L7 = if bn == 1 then init else if (vxup and linecnt == 7) then linelevel else L7[1];
def L8 = if bn == 1 then init else if (vxup and linecnt == 8) then linelevel else L8[1];
def L9 = if bn == 1 then init else if (vxup and linecnt == 9) then linelevel else L9[1];
def L10 = if bn == 1 then init else if (vxup and linecnt == 10) then linelevel else L10[1];
def L11 = if bn == 1 then init else if (vxup and linecnt == 11) then linelevel else L11[1];
def L12 = if bn == 1 then init else if (vxup and linecnt == 12) then linelevel else L12[1];
def L13 = if bn == 1 then init else if (vxup and linecnt == 13) then linelevel else L13[1];
def L14 = if bn == 1 then init else if (vxup and linecnt == 14) then linelevel else L14[1];
def L15 = if bn == 1 then init else if (vxup and linecnt == 15) then linelevel else L15[1];
#----------------------
# line color , chg from gray ro red/green
input color_lines = yes;
def clr1 = 6;
def clr2 = 5;
def init2 = -1;
def c1 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 1 and isvolgrn) then clr1 else if (vxup and linecnt == 1 and !isvolgrn) then clr2 else c1[1];
def c2 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 2 and isvolgrn) then clr1 else if (vxup and linecnt == 2 and !isvolgrn) then clr2 else c2[1];
def c3 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 3 and isvolgrn) then clr1 else if (vxup and linecnt == 3 and !isvolgrn) then clr2 else c3[1];
def c4 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 4 and isvolgrn) then clr1 else if (vxup and linecnt == 4 and !isvolgrn) then clr2 else c4[1];
def c5 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 5 and isvolgrn) then clr1 else if (vxup and linecnt == 5 and !isvolgrn) then clr2 else c5[1];
def c6 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 6 and isvolgrn) then clr1 else if (vxup and linecnt == 6 and !isvolgrn) then clr2 else c6[1];
def c7 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 7 and isvolgrn) then clr1 else if (vxup and linecnt == 7 and !isvolgrn) then clr2 else c7[1];
def c8 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 8 and isvolgrn) then clr1 else if (vxup and linecnt == 8 and !isvolgrn) then clr2 else c8[1];
def c9 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 9 and isvolgrn) then clr1 else if (vxup and linecnt == 9 and !isvolgrn) then clr2 else c9[1];
def c10 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 10 and isvolgrn) then clr1 else if (vxup and linecnt == 10 and !isvolgrn) then clr2 else c10[1];
def c11 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 11 and isvolgrn) then clr1 else if (vxup and linecnt == 11 and !isvolgrn) then clr2 else c11[1];
def c12 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 12 and isvolgrn) then clr1 else if (vxup and linecnt == 12 and !isvolgrn) then clr2 else c12[1];
def c13 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 13 and isvolgrn) then clr1 else if (vxup and linecnt == 13 and !isvolgrn) then clr2 else c13[1];
def c14 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 14 and isvolgrn) then clr1 else if (vxup and linecnt == 14 and !isvolgrn) then clr2 else c14[1];
def c15 = if bn == 1 or !color_lines then init2 else if (vxup and linecnt == 15 and isvolgrn) then clr1 else if (vxup and linecnt == 15 and !isvolgrn) then clr2 else c15[1];
#----------------------
plot z1 = L1;
#z1.SetDefaultColor(Color.GRAY);
z1.AssignValueColor( if c1 == 6 then color.green else if c1 == 5 then color.red else color.gray);
# z1.SetDefaultColor(getcolor(c1));
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z2 = L2;
#z2.SetDefaultColor(Color.GRAY);
z2.AssignValueColor( if c2 == clr1 then color.green else if c2 == clr2 then color.red else color.gray);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z3 = L3;
#z3.SetDefaultColor(Color.GRAY);
z3.AssignValueColor( if c3 == clr1 then color.green else if c3 == clr2 then color.red else color.gray);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z4 = L4;
#z4.SetDefaultColor(Color.GRAY);
z4.AssignValueColor( if c4 == clr1 then color.green else if c4 == clr2 then color.red else color.gray);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z5 = L5;
#z5.SetDefaultColor(Color.GRAY);
z5.AssignValueColor( if c5 == clr1 then color.green else if c5 == clr2 then color.red else color.gray);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z6 = L6;
#z6.SetDefaultColor(Color.GRAY);
z6.AssignValueColor( if c6 == clr1 then color.green else if c6 == clr2 then color.red else color.gray);
z6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z7 = L7;
#z7.SetDefaultColor(Color.GRAY);
z7.AssignValueColor( if c7 == clr1 then color.green else if c7 == clr2 then color.red else color.gray);
z7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z8 = L8;
#z8.SetDefaultColor(Color.GRAY);
z8.AssignValueColor( if c8 == clr1 then color.green else if c8 == clr2 then color.red else color.gray);
z8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z9 = L9;
#z9.SetDefaultColor(Color.GRAY);
z9.AssignValueColor( if c9 == clr1 then color.green else if c9 == clr2 then color.red else color.gray);
z9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z10 = L10;
#z10.SetDefaultColor(Color.GRAY);
z10.AssignValueColor( if c10 == clr1 then color.green else if c10 == clr2 then color.red else color.gray);
z10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z11 = L11;
#z11.SetDefaultColor(Color.GRAY);
z11.AssignValueColor( if c11 == clr1 then color.green else if c11 == clr2 then color.red else color.gray);
z11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z12 = L12;
#z12.SetDefaultColor(Color.GRAY);
z12.AssignValueColor( if c12 == clr1 then color.green else if c12 == clr2 then color.red else color.gray);
z12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z13 = L13;
#z13.SetDefaultColor(Color.GRAY);
z13.AssignValueColor( if c13 == clr1 then color.green else if c13 == clr2 then color.red else color.gray);
z13.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z14 = L14;
#z14.SetDefaultColor(Color.GRAY);
z14.AssignValueColor( if c14 == clr1 then color.green else if c14 == clr2 then color.red else color.gray);
z14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot z15 = L15;
#z15.SetDefaultColor(Color.GRAY);
z15.AssignValueColor( if c15 == clr1 then color.green else if c15 == clr2 then color.red else color.gray);
z15.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#----------------------
input test3_line_values = no;
addchartbubble(test3_line_values, low*0.997,
l1 + " 1\n" +
l2 + " 2\n" +
l3 + " 3\n" +
l4 + " 4\n" +
l5 + " 5\n" +
l6 + " 6\n" +
l7 + " 7\n" +
l8 + " 8\n" +
l9 + " 9\n" +
l10 + " 10"
, ( if vxup then color.yellow else color.gray), no);
#
#