Define Shapes in the Poor Man's Volume Profile

Glefdar

Active member
Modify "Poor Man's Volume Profile" to identify and label profile shapes

@halcyonguy and some assisting members converted a pinescript study that creates a volume profile here.

I think this is interesting because if I understand correcting, the "profile" generation function in thinkscript doesn't allow for much scripting interaction, whereas this "Poor Man's Volume Profile" is not using the "profile" function and should therefore offer more possibilities.

For example, with the Poor Man's Volume Profile, wouldn't it be possible to code signals that are conditional based on the shape of the profile? I think so if the profile shapes can be defined objectively enough. It seems like that would be possible.

In the code, each line is plotted as z0 through z39 for creating 40 horizontal profile bars total. Intuitively it seems like profile shapes could just be defined by creating ranges of these bars as quadrants of the profile and taking the percentage totals of the quadrants versus each other.

For example, I tried adding this code at the end of the study:

Code:
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

I can't find any charts that will show the labels and I think the reason is probably that the definitions of the profile shapes are too simplistic and therefore not capturing real profile shapes (only ideal ones).

Anyone have any suggestions or ideas about a better way to try to mathematically define the profile shapes? Or is it too subjective to be expressed as code in a practical way?

(Complete script is provided below: )

Code:
# Poorman_volume_profile_02b

#finished by rrm411
#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#post5


#  replace max()  at 500+  that find row max #s


#Poor man's volume profile
#https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/
#1100 lines
#// © Ildar Akhmetgaleev (AkhIL)
#// See https://github.com/akhilman/vol-poorofile
#// vim: shiftwidth=2 tabstop=2
#study("Poor man's volume profile", "PMVolProf", overlay=true, max_bars_back=500)


def na = double.nan;
def bn = BarNumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

#def lastbar = !isnan(close[0]) and isnan(close[-1]);

def minb = 10;
def maxb = 500;
input block_size2 = 200;
def block_size = if block_size2 < minb then minb else if block_size2 > maxb then maxb else block_size2;
input visual_row_width = 50;
input show_peaks = yes;

AddLabel(1, "look " + block_size + " bars back", Color.YELLOW);

input show_vert_line_range_start = yes;
def first = (!IsNaN(close[-block_size]) and IsNaN(close[-(block_size + 1)]));
AddVerticalLine(show_vert_line_range_start and first, "-", Color.CYAN);


#// Calculate profile

def block_high = Highest(high, block_size);
def block_low = Lowest(low, block_size);
def highest_row_value = 0;


# data to collect
# count bars in a range
#def data = 1;
# convert volume to millions
#def data = volume/1000000;
# convert volume to 1000s
def data = volume / 1000;


# do stuff on last bar

def row_qty = 40;
def block_height = block_high - block_low;
def row_height = block_height / row_qty;

# chg first values to 1, so no divide by 0 err
def k = 1;
def r00lo = if bn == 1 then k else if lastbar then (block_low + row_height * 0) else r00lo[1];
def r00hi = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r00hi[1];
def r01lo = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r01lo[1];
def r01hi = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r01hi[1];
def r02lo = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r02lo[1];
def r02hi = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r02hi[1];
def r03lo = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r03lo[1];
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
def r04lo = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r04lo[1];
def r04hi = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r04hi[1];
def r05lo = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r05lo[1];
def r05hi = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r05hi[1];
def r06lo = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r06lo[1];
def r06hi = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r06hi[1];
def r07lo = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r07lo[1];
def r07hi = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r07hi[1];
def r08lo = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r08lo[1];
def r08hi = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r08hi[1];
def r09lo = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r09lo[1];
def r09hi = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r09hi[1];
def r10lo = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r10lo[1];
def r10hi = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r10hi[1];
def r11lo = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r11lo[1];
def r11hi = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r11hi[1];
def r12lo = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r12lo[1];
def r12hi = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r12hi[1];
def r13lo = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r13lo[1];
def r13hi = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r13hi[1];
def r14lo = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r14lo[1];
def r14hi = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r14hi[1];
def r15lo = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r15lo[1];
def r15hi = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r15hi[1];
def r16lo = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r16lo[1];
def r16hi = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r16hi[1];
def r17lo = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r17lo[1];
def r17hi = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r17hi[1];
def r18lo = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r18lo[1];
def r18hi = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r18hi[1];
def r19lo = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r19lo[1];
def r19hi = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r19hi[1];
def r20lo = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r20lo[1];
def r20hi = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r20hi[1];
def r21lo = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r21lo[1];
def r21hi = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r21hi[1];
def r22lo = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r22lo[1];
def r22hi = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r22hi[1];
def r23lo = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r23lo[1];
def r23hi = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r23hi[1];
def r24lo = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r24lo[1];
def r24hi = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r24hi[1];
def r25lo = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r25lo[1];
def r25hi = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r25hi[1];
def r26lo = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r26lo[1];
def r26hi = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r26hi[1];
def r27lo = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r27lo[1];
def r27hi = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r27hi[1];
def r28lo = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r28lo[1];
def r28hi = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r28hi[1];
def r29lo = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r29lo[1];
def r29hi = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r29hi[1];
def r30lo = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r30lo[1];
def r30hi = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r30hi[1];
def r31lo = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r31lo[1];
def r31hi = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r31hi[1];
def r32lo = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r32lo[1];
def r32hi = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r32hi[1];
def r33lo = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r33lo[1];
def r33hi = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r33hi[1];
def r34lo = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r34lo[1];
def r34hi = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r34hi[1];
def r35lo = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r35lo[1];
def r35hi = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r35hi[1];
def r36lo = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r36lo[1];
def r36hi = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r36hi[1];
def r37lo = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r37lo[1];
def r37hi = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r37hi[1];
def r38lo = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r38lo[1];
def r38hi = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r38hi[1];
def r39lo = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r39lo[1];
def r39hi = if bn == 1 then k else if lastbar then (block_low + row_height * 40) else r39hi[1];



def r00mid = (r00hi + r00lo) / 2;
def r01mid = (r01hi + r01lo) / 2;
def r02mid = (r02hi + r02lo) / 2;
def r03mid = (r03hi + r03lo) / 2;
def r04mid = (r04hi + r04lo) / 2;
def r05mid = (r05hi + r05lo) / 2;
def r06mid = (r06hi + r06lo) / 2;
def r07mid = (r07hi + r07lo) / 2;
def r08mid = (r08hi + r08lo) / 2;
def r09mid = (r09hi + r09lo) / 2;
def r10mid = (r10hi + r10lo) / 2;
def r11mid = (r11hi + r11lo) / 2;
def r12mid = (r12hi + r12lo) / 2;
def r13mid = (r13hi + r13lo) / 2;
def r14mid = (r14hi + r14lo) / 2;
def r15mid = (r15hi + r15lo) / 2;
def r16mid = (r16hi + r16lo) / 2;
def r17mid = (r17hi + r17lo) / 2;
def r18mid = (r18hi + r18lo) / 2;
def r19mid = (r19hi + r19lo) / 2;
def r20mid = (r20hi + r20lo) / 2;
def r21mid = (r21hi + r21lo) / 2;
def r22mid = (r22hi + r22lo) / 2;
def r23mid = (r23hi + r23lo) / 2;
def r24mid = (r24hi + r24lo) / 2;
def r25mid = (r25hi + r25lo) / 2;
def r26mid = (r26hi + r26lo) / 2;
def r27mid = (r27hi + r27lo) / 2;
def r28mid = (r28hi + r28lo) / 2;
def r29mid = (r29hi + r29lo) / 2;
def r30mid = (r30hi + r30lo) / 2;
def r31mid = (r31hi + r31lo) / 2;
def r32mid = (r32hi + r32lo) / 2;
def r33mid = (r33hi + r33lo) / 2;
def r34mid = (r34hi + r34lo) / 2;
def r35mid = (r35hi + r35lo) / 2;
def r36mid = (r36hi + r36lo) / 2;
def r37mid = (r37hi + r37lo) / 2;
def r38mid = (r38hi + r38lo) / 2;
def r39mid = (r39hi + r39lo) / 2;


# on last bar,
# look back at prev bars, to see if part of them were within a price row range,
# if so, then add the data from that bar , volume

def m = 1;
def r00cnt = if bn == 1 then m else if lastbar then fold i0 = 0 to block_size
 with p0
 do p0 + (if GetValue(low, i0) < r00hi and GetValue(high, i0) > r00lo then GetValue(data, i0) else 0)
 else r00cnt[1];

def r01cnt = if bn == 1 then m else if lastbar then fold i1 = 0 to block_size
 with p1
 do p1 + (if GetValue(low, i1) < r01hi and GetValue(high, i1) > r01lo then GetValue(data, i1) else 0)
 else r01cnt[1];

def r02cnt = if bn == 1 then m else if lastbar then fold i2 = 0 to block_size
 with p2
 do p2 + (if GetValue(low, i2) < r02hi and GetValue(high, i2) > r02lo then GetValue(data, i2) else 0)
 else r02cnt[1];

def r03cnt = if bn == 1 then m else if lastbar then fold i3 = 0 to block_size
 with p3
 do p3 + (if GetValue(low, i3) < r03hi and GetValue(high, i3) > r03lo then GetValue(data, i3) else 0)
 else r03cnt[1];

def r04cnt = if bn == 1 then m else if lastbar then fold i4 = 0 to block_size
 with p4
 do p4 + (if GetValue(low, i4) < r04hi and GetValue(high, i4) > r04lo then GetValue(data, i4) else 0)
 else r04cnt[1];

def r05cnt = if bn == 1 then m else if lastbar then fold i5 = 0 to block_size
 with p5
 do p5 + (if GetValue(low, i5) < r05hi and GetValue(high, i5) > r05lo then GetValue(data, i5) else 0)
 else r05cnt[1];

def r06cnt = if bn == 1 then m else if lastbar then fold i6 = 0 to block_size
 with p6
 do p6 + (if GetValue(low, i6) < r06hi and GetValue(high, i6) > r06lo then GetValue(data, i6) else 0)
 else r06cnt[1];

def r07cnt = if bn == 1 then m else if lastbar then fold i7 = 0 to block_size
 with p7
 do p7 + (if GetValue(low, i7) < r07hi and GetValue(high, i7) > r07lo then GetValue(data, i7) else 0)
 else r07cnt[1];

def r08cnt = if bn == 1 then m else if lastbar then fold i8 = 0 to block_size
 with p8
 do p8 + (if GetValue(low, i8) < r08hi and GetValue(high, i8) > r08lo then GetValue(data, i8) else 0)
 else r08cnt[1];

def r09cnt = if bn == 1 then m else if lastbar then fold i9 = 0 to block_size
 with p9
 do p9 + (if GetValue(low, i9) < r09hi and GetValue(high, i9) > r09lo then GetValue(data, i9) else 0)
 else r09cnt[1];

def r10cnt = if bn == 1 then m else if lastbar then fold i10 = 0 to block_size
 with p10
 do p10 + (if GetValue(low, i10) < r10hi and GetValue(high, i10) > r10lo then GetValue(data, i10) else 0)
 else r10cnt[1];

def r11cnt = if bn == 1 then m else if lastbar then fold i11 = 0 to block_size
 with p11
 do p11 + (if GetValue(low, i11) < r11hi and GetValue(high, i11) > r11lo then GetValue(data, i11) else 0)
 else r11cnt[1];

def r12cnt = if bn == 1 then m else if lastbar then fold i12 = 0 to block_size
 with p12
 do p12 + (if GetValue(low, i12) < r12hi and GetValue(high, i12) > r12lo then GetValue(data, i12) else 0)
 else r12cnt[1];

def r13cnt = if bn == 1 then m else if lastbar then fold i13 = 0 to block_size
 with p13
 do p13 + (if GetValue(low, i13) < r13hi and GetValue(high, i13) > r13lo then GetValue(data, i13) else 0)
 else r13cnt[1];

def r14cnt = if bn == 1 then m else if lastbar then fold i14 = 0 to block_size
 with p14
 do p14 + (if GetValue(low, i14) < r14hi and GetValue(high, i14) > r14lo then GetValue(data, i14) else 0)
 else r14cnt[1];

def r15cnt = if bn == 1 then m else if lastbar then fold i15 = 0 to block_size
 with p15
 do p15 + (if GetValue(low, i15) < r15hi and GetValue(high, i15) > r15lo then GetValue(data, i15) else 0)
 else r15cnt[1];

def r16cnt = if bn == 1 then m else if lastbar then fold i16 = 0 to block_size
 with p16
 do p16 + (if GetValue(low, i16) < r16hi and GetValue(high, i16) > r16lo then GetValue(data, i16) else 0)
 else r16cnt[1];

def r17cnt = if bn == 1 then m else if lastbar then fold i17 = 0 to block_size
 with p17
 do p17 + (if GetValue(low, i17) < r17hi and GetValue(high, i17) > r17lo then GetValue(data, i17) else 0)
 else r17cnt[1];

def r18cnt = if bn == 1 then m else if lastbar then fold i18 = 0 to block_size
 with p18
 do p18 + (if GetValue(low, i18) < r18hi and GetValue(high, i18) > r18lo then GetValue(data, i18) else 0)
 else r18cnt[1];

def r19cnt = if bn == 1 then m else if lastbar then fold i19 = 0 to block_size
 with p19
 do p19 + (if GetValue(low, i19) < r19hi and GetValue(high, i19) > r19lo then GetValue(data, i19) else 0)
 else r19cnt[1];

def r20cnt = if bn == 1 then m else if lastbar then fold i20 = 0 to block_size
 with p20
 do p20 + (if GetValue(low, i20) < r20hi and GetValue(high, i20) > r20lo then GetValue(data, i20) else 0)
 else r20cnt[1];

def r21cnt = if bn == 1 then m else if lastbar then fold i21 = 0 to block_size
 with p21
 do p21 + (if GetValue(low, i21) < r21hi and GetValue(high, i21) > r21lo then GetValue(data, i21) else 0)
 else r21cnt[1];

def r22cnt = if bn == 1 then m else if lastbar then fold i22 = 0 to block_size
 with p22
 do p22 + (if GetValue(low, i22) < r22hi and GetValue(high, i22) > r22lo then GetValue(data, i22) else 0)
 else r22cnt[1];

def r23cnt = if bn == 1 then m else if lastbar then fold i23 = 0 to block_size
 with p23
 do p23 + (if GetValue(low, i23) < r23hi and GetValue(high, i23) > r23lo then GetValue(data, i23) else 0)
 else r23cnt[1];

def r24cnt = if bn == 1 then m else if lastbar then fold i24 = 0 to block_size
 with p24
 do p24 + (if GetValue(low, i24) < r24hi and GetValue(high, i24) > r24lo then GetValue(data, i24) else 0)
 else r24cnt[1];

def r25cnt = if bn == 1 then m else if lastbar then fold i25 = 0 to block_size
 with p25
 do p25 + (if GetValue(low, i25) < r25hi and GetValue(high, i25) > r25lo then GetValue(data, i25) else 0)
 else r25cnt[1];

def r26cnt = if bn == 1 then m else if lastbar then fold i26 = 0 to block_size
 with p26
 do p26 + (if GetValue(low, i26) < r26hi and GetValue(high, i26) > r26lo then GetValue(data, i26) else 0)
 else r26cnt[1];

def r27cnt = if bn == 1 then m else if lastbar then fold i27 = 0 to block_size
 with p27
 do p27 + (if GetValue(low, i27) < r27hi and GetValue(high, i27) > r27lo then GetValue(data, i27) else 0)
 else r27cnt[1];

def r28cnt = if bn == 1 then m else if lastbar then fold i28 = 0 to block_size
 with p28
 do p28 + (if GetValue(low, i28) < r28hi and GetValue(high, i28) > r28lo then GetValue(data, i28) else 0)
 else r28cnt[1];

def r29cnt = if bn == 1 then m else if lastbar then fold i29 = 0 to block_size
 with p29
 do p29 + (if GetValue(low, i29) < r29hi and GetValue(high, i29) > r29lo then GetValue(data, i29) else 0)
 else r29cnt[1];

def r30cnt = if bn == 1 then m else if lastbar then fold i30 = 0 to block_size
 with p30
 do p30 + (if GetValue(low, i30) < r30hi and GetValue(high, i30) > r30lo then GetValue(data, i30) else 0)
 else r30cnt[1];

def r31cnt = if bn == 1 then m else if lastbar then fold i31 = 0 to block_size
 with p31
 do p31 + (if GetValue(low, i31) < r31hi and GetValue(high, i31) > r31lo then GetValue(data, i31) else 0)
 else r31cnt[1];

def r32cnt = if bn == 1 then m else if lastbar then fold i32 = 0 to block_size
 with p32
 do p32 + (if GetValue(low, i32) < r32hi and GetValue(high, i32) > r32lo then GetValue(data, i32) else 0)
 else r32cnt[1];

def r33cnt = if bn == 1 then m else if lastbar then fold i33 = 0 to block_size
 with p33
 do p33 + (if GetValue(low, i33) < r33hi and GetValue(high, i33) > r33lo then GetValue(data, i33) else 0)
 else r33cnt[1];

def r34cnt = if bn == 1 then m else if lastbar then fold i34 = 0 to block_size
 with p34
 do p34 + (if GetValue(low, i34) < r34hi and GetValue(high, i34) > r34lo then GetValue(data, i34) else 0)
 else r34cnt[1];

def r35cnt = if bn == 1 then m else if lastbar then fold i35 = 0 to block_size
 with p35
 do p35 + (if GetValue(low, i35) < r35hi and GetValue(high, i35) > r35lo then GetValue(data, i35) else 0)
 else r35cnt[1];

def r36cnt = if bn == 1 then m else if lastbar then fold i36 = 0 to block_size
 with p36
 do p36 + (if GetValue(low, i36) < r36hi and GetValue(high, i36) > r36lo then GetValue(data, i36) else 0)
 else r36cnt[1];

def r37cnt = if bn == 1 then m else if lastbar then fold i37 = 0 to block_size
 with p37
 do p37 + (if GetValue(low, i37) < r37hi and GetValue(high, i37) > r37lo then GetValue(data, i37) else 0)
 else r37cnt[1];

def r38cnt = if bn == 1 then m else if lastbar then fold i38 = 0 to block_size
 with p38
 do p38 + (if GetValue(low, i38) < r38hi and GetValue(high, i38) > r38lo then GetValue(data, i38) else 0)
 else r38cnt[1];

def r39cnt = if bn == 1 then m else if lastbar then fold i39 = 0 to block_size
 with p39
 do p39 + (if GetValue(low, i39) < r39hi and GetValue(high, i39) > r39lo then GetValue(data, i39) else 0)
 else r39cnt[1];



# find max data sum
def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# calc ratio of cnt to highest cnt , a bar cnt , for the horz length of each row
def r00r = Floor(visual_row_width * r00cnt / maxdata);
def r01r = Floor(visual_row_width * r01cnt / maxdata);
def r02r = Floor(visual_row_width * r02cnt / maxdata);
def r03r = Floor(visual_row_width * r03cnt / maxdata);
def r04r = Floor(visual_row_width * r04cnt / maxdata);
def r05r = Floor(visual_row_width * r05cnt / maxdata);
def r06r = Floor(visual_row_width * r06cnt / maxdata);
def r07r = Floor(visual_row_width * r07cnt / maxdata);
def r08r = Floor(visual_row_width * r08cnt / maxdata);
def r09r = Floor(visual_row_width * r09cnt / maxdata);
def r10r = Floor(visual_row_width * r10cnt / maxdata);
def r11r = Floor(visual_row_width * r11cnt / maxdata);
def r12r = Floor(visual_row_width * r12cnt / maxdata);
def r13r = Floor(visual_row_width * r13cnt / maxdata);
def r14r = Floor(visual_row_width * r14cnt / maxdata);
def r15r = Floor(visual_row_width * r15cnt / maxdata);
def r16r = Floor(visual_row_width * r16cnt / maxdata);
def r17r = Floor(visual_row_width * r17cnt / maxdata);
def r18r = Floor(visual_row_width * r18cnt / maxdata);
def r19r = Floor(visual_row_width * r19cnt / maxdata);
def r20r = Floor(visual_row_width * r20cnt / maxdata);
def r21r = Floor(visual_row_width * r21cnt / maxdata);
def r22r = Floor(visual_row_width * r22cnt / maxdata);
def r23r = Floor(visual_row_width * r23cnt / maxdata);
def r24r = Floor(visual_row_width * r24cnt / maxdata);
def r25r = Floor(visual_row_width * r25cnt / maxdata);
def r26r = Floor(visual_row_width * r26cnt / maxdata);
def r27r = Floor(visual_row_width * r27cnt / maxdata);
def r28r = Floor(visual_row_width * r28cnt / maxdata);
def r29r = Floor(visual_row_width * r29cnt / maxdata);
def r30r = Floor(visual_row_width * r30cnt / maxdata);
def r31r = Floor(visual_row_width * r31cnt / maxdata);
def r32r = Floor(visual_row_width * r32cnt / maxdata);
def r33r = Floor(visual_row_width * r33cnt / maxdata);
def r34r = Floor(visual_row_width * r34cnt / maxdata);
def r35r = Floor(visual_row_width * r35cnt / maxdata);
def r36r = Floor(visual_row_width * r36cnt / maxdata);
def r37r = Floor(visual_row_width * r37cnt / maxdata);
def r38r = Floor(visual_row_width * r38cnt / maxdata);
def r39r = Floor(visual_row_width * r39cnt / maxdata);



#// Draw profile


# draw rows on bars after the last bar
# mark bars after lastbar as true, if the ratio cnt of bars .....
def x0 = (bn > lastbn and bn <= (lastbn + r00r));
def x1 = (bn > lastbn and bn <= (lastbn + r01r));
def x2 = (bn > lastbn and bn <= (lastbn + r02r));
def x3 = (bn > lastbn and bn <= (lastbn + r03r));
def x4 = (bn > lastbn and bn <= (lastbn + r04r));
def x5 = (bn > lastbn and bn <= (lastbn + r05r));
def x6 = (bn > lastbn and bn <= (lastbn + r06r));
def x7 = (bn > lastbn and bn <= (lastbn + r07r));
def x8 = (bn > lastbn and bn <= (lastbn + r08r));
def x9 = (bn > lastbn and bn <= (lastbn + r09r));
def x10 = (bn > lastbn and bn <= (lastbn + r10r));
def x11 = (bn > lastbn and bn <= (lastbn + r11r));
def x12 = (bn > lastbn and bn <= (lastbn + r12r));
def x13 = (bn > lastbn and bn <= (lastbn + r13r));
def x14 = (bn > lastbn and bn <= (lastbn + r14r));
def x15 = (bn > lastbn and bn <= (lastbn + r15r));
def x16 = (bn > lastbn and bn <= (lastbn + r16r));
def x17 = (bn > lastbn and bn <= (lastbn + r17r));
def x18 = (bn > lastbn and bn <= (lastbn + r18r));
def x19 = (bn > lastbn and bn <= (lastbn + r19r));
def x20 = (bn > lastbn and bn <= (lastbn + r20r));
def x21 = (bn > lastbn and bn <= (lastbn + r21r));
def x22 = (bn > lastbn and bn <= (lastbn + r22r));
def x23 = (bn > lastbn and bn <= (lastbn + r23r));
def x24 = (bn > lastbn and bn <= (lastbn + r24r));
def x25 = (bn > lastbn and bn <= (lastbn + r25r));
def x26 = (bn > lastbn and bn <= (lastbn + r26r));
def x27 = (bn > lastbn and bn <= (lastbn + r27r));
def x28 = (bn > lastbn and bn <= (lastbn + r28r));
def x29 = (bn > lastbn and bn <= (lastbn + r29r));
def x30 = (bn > lastbn and bn <= (lastbn + r30r));
def x31 = (bn > lastbn and bn <= (lastbn + r31r));
def x32 = (bn > lastbn and bn <= (lastbn + r32r));
def x33 = (bn > lastbn and bn <= (lastbn + r33r));
def x34 = (bn > lastbn and bn <= (lastbn + r34r));
def x35 = (bn > lastbn and bn <= (lastbn + r35r));
def x36 = (bn > lastbn and bn <= (lastbn + r36r));
def x37 = (bn > lastbn and bn <= (lastbn + r37r));
def x38 = (bn > lastbn and bn <= (lastbn + r38r));
def x39 = (bn > lastbn and bn <= (lastbn + r39r));


#---------------------------

# orig codes
# find max value , +-5 values , compare each row value to 10 other values
# if current is the max, then orange
#   if first , compare to 5 future
#   later , compare to 5 before and 5 after
#   last , compare to 5 prev

# ref - orig code
#if row0_value >= row1_value and row0_value >= row2_value and row0_value >= row3_value and row0_value >= row4_value and row0_value >= row5_value
#        row0_is_peak := true

#if row10_value >= row5_value and row10_value >= row6_value and row10_value >= row7_value and row10_value >= row8_value and row10_value >= row9_value and row10_value >= row11_value and row10_value >= row12_value and row10_value >= row13_value and row10_value >= row14_value and row10_value >= row15_value
#        row10_is_peak := true

#if row20_value >= row15_value and row20_value >= row16_value and row20_value >= row17_value and row20_value >= row18_value and row20_value >= row19_value and row20_value >= row21_value and row20_value >= row22_value and row20_value >= row23_value and row20_value >= row24_value and row20_value >= row25_value
#        row20_is_peak := true

#if row39_value >= row34_value and row39_value >= row35_value and row39_value >= row36_value and row39_value >= row37_value and row39_value >= row38_value
#        row39_is_peak := true

#------------------

# copied from line 394
#def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# compare current row to prev 5 rows and future 5 rows

def max00 = if r00cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, r05cnt)))))) then 1 else 0;
def max01 = if r01cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, r06cnt))))))) then 1 else 0;
def max02 = if r02cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, r07cnt)))))))) then 1 else 0;
def max03 = if r03cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, r08cnt))))))))) then 1 else 0;
def max04 = if r04cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, r09cnt)))))))))) then 1 else 0;

def max05 = if r05cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, r10cnt))))))))))) then 1 else 0;
def max06 = if r06cnt == (Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, r11cnt))))))))))) then 1 else 0;
def max07 = if r07cnt == (Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, r12cnt))))))))))) then 1 else 0;
def max08 = if r08cnt == (Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, r13cnt))))))))))) then 1 else 0;
def max09 = if r09cnt == (Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, r14cnt))))))))))) then 1 else 0;
def max10 = if r10cnt == (Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, r15cnt))))))))))) then 1 else 0;
def max11 = if r11cnt == (Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, r16cnt))))))))))) then 1 else 0;
def max12 = if r12cnt == (Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, r17cnt))))))))))) then 1 else 0;

def max13 = if r13cnt == (Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, r18cnt))))))))))) then 1 else 0;
def max14 = if r14cnt == (Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, r19cnt))))))))))) then 1 else 0;
def max15 = if r15cnt == (Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, r20cnt))))))))))) then 1 else 0;
def max16 = if r16cnt == (Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, r21cnt))))))))))) then 1 else 0;
def max17 = if r17cnt == (Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, r22cnt))))))))))) then 1 else 0;
def max18 = if r18cnt == (Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, r23cnt))))))))))) then 1 else 0;
def max19 = if r19cnt == (Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, r23cnt))))))))))) then 1 else 0;

def max20 = if r20cnt == (Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, r25cnt))))))))))) then 1 else 0;
def max21 = if r21cnt == (Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, r26cnt))))))))))) then 1 else 0;
def max22 = if r22cnt == (Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, r27cnt))))))))))) then 1 else 0;
def max23 = if r23cnt == (Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, r23cnt))))))))))) then 1 else 0;
def max24 = if r24cnt == (Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, r29cnt))))))))))) then 1 else 0;
def max25 = if r25cnt == (Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, r30cnt))))))))))) then 1 else 0;
def max26 = if r26cnt == (Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, r31cnt))))))))))) then 1 else 0;
def max27 = if r27cnt == (Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, r32cnt))))))))))) then 1 else 0;
def max28 = if r28cnt == (Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, r33cnt))))))))))) then 1 else 0;
def max29 = if r29cnt == (Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, r34cnt))))))))))) then 1 else 0;

def max30 = if r30cnt == (Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, r35cnt))))))))))) then 1 else 0;
def max31 = if r31cnt == (Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, r36cnt))))))))))) then 1 else 0;
def max32 = if r32cnt == (Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, r37cnt))))))))))) then 1 else 0;
def max33 = if r33cnt == (Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, r38cnt))))))))))) then 1 else 0;
def max34 = if r34cnt == (Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))))) then 1 else 0;

def max35 = if r35cnt == (Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))) then 1 else 0;
def max36 = if r36cnt == (Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))) then 1 else 0;
def max37 = if r37cnt == (Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))) then 1 else 0;
def max38 = if r38cnt == (Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))) then 1 else 0;
def max39 = if r39cnt == (Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))) then 1 else 0;

#---------------------------


#  replace max()  at 500+  that find row max #s
# hmm  diff vars , so cant just use highest()...

# def mx00 =


#-----------------------------

defineglobalcolor("colorhi", color.orange);

input line_thick = 2;
input show_lines_wsquares = yes;

plot z0 = if show_lines_wsquares and x0 then r00mid else na;
z0.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max00 then GlobalColor("colorhi") else color.gray);
#z0.SetDefaultColor(Color.GRAY);
z0.SetLineWeight(line_thick);
z0.HideBubble();

plot z1 = if show_lines_wsquares and x1 then r01mid else na;
z1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z1.AssignValueColor(if max01 then GlobalColor("colorhi") else color.gray);
#z1.SetDefaultColor(Color.GRAY);
z1.SetLineWeight(line_thick);
z1.HideBubble();

plot z2 = if show_lines_wsquares and x2 then r02mid else na;
z2.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z2.AssignValueColor(if max02 then GlobalColor("colorhi") else color.gray);
#z2.SetDefaultColor(Color.GRAY);
z2.SetLineWeight(line_thick);
z2.HideBubble();

plot z3 = if show_lines_wsquares and x3 then r03mid else na;
z3.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z3.AssignValueColor(if max03 then GlobalColor("colorhi") else color.gray);
#z3.SetDefaultColor(Color.GRAY);
z3.SetLineWeight(line_thick);
z3.HideBubble();

plot z4 = if show_lines_wsquares and x4 then r04mid else na;
z4.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z4.AssignValueColor(if max04 then GlobalColor("colorhi") else color.gray);
z4.SetDefaultColor(Color.GRAY);
z4.SetLineWeight(line_thick);
z4.HideBubble();

plot z5 = if show_lines_wsquares and x5 then r05mid else na;
z5.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z5.AssignValueColor(if max05 then GlobalColor("colorhi") else color.gray);
#z5.SetDefaultColor(Color.GRAY);
z5.SetLineWeight(line_thick);
z5.HideBubble();

plot z6 = if show_lines_wsquares and x6 then r06mid else na;
z6.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z6.AssignValueColor(if max06 then GlobalColor("colorhi") else color.gray);
z6.SetDefaultColor(Color.GRAY);
z6.SetLineWeight(line_thick);
z6.HideBubble();

plot z7 = if show_lines_wsquares and x7 then r07mid else na;
z7.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z7.AssignValueColor(if max07 then GlobalColor("colorhi") else color.gray);
#z7.SetDefaultColor(Color.GRAY);
z7.SetLineWeight(line_thick);
z7.HideBubble();

plot z8 = if show_lines_wsquares and x8 then r08mid else na;
z8.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z8.AssignValueColor(if max08 then GlobalColor("colorhi") else color.gray);
#z8.SetDefaultColor(Color.GRAY);
z8.SetLineWeight(line_thick);
z8.HideBubble();

plot z9 = if show_lines_wsquares and x9 then r09mid else na;
z9.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z9.AssignValueColor(if max09 then GlobalColor("colorhi") else color.gray);
#z9.SetDefaultColor(Color.GRAY);
z9.SetLineWeight(line_thick);
z9.HideBubble();

plot z10 = if show_lines_wsquares and x10 then r10mid else na;
z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z10.AssignValueColor(if max10 then GlobalColor("colorhi") else color.gray);
#z10.SetDefaultColor(Color.GRAY);
z10.SetLineWeight(line_thick);
z10.HideBubble();

plot z11 = if show_lines_wsquares and x11 then r11mid else na;
z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z11.AssignValueColor(if max11 then GlobalColor("colorhi") else color.gray);
#z11.SetDefaultColor(Color.GRAY);
z11.SetLineWeight(line_thick);
z11.HideBubble();

plot z12 = if show_lines_wsquares and x12 then r12mid else na;
z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z12.AssignValueColor(if max12 then GlobalColor("colorhi") else color.gray);
#z12.SetDefaultColor(Color.GRAY);
z12.SetLineWeight(line_thick);
z12.HideBubble();

plot z13 = if show_lines_wsquares and x13 then r13mid else na;
z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z13.AssignValueColor(if max13 then GlobalColor("colorhi") else color.gray);
z13.SetDefaultColor(Color.GRAY);
z13.SetLineWeight(line_thick);
z13.HideBubble();

plot z14 = if show_lines_wsquares and x14 then r14mid else na;
z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z14.AssignValueColor(if max14 then GlobalColor("colorhi") else color.gray);
#z14.SetDefaultColor(Color.GRAY);
z14.SetLineWeight(line_thick);
z14.HideBubble();

plot z15 = if show_lines_wsquares and x15 then r15mid else na;
z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z15.AssignValueColor(if max15 then GlobalColor("colorhi") else color.gray);
#z15.SetDefaultColor(Color.GRAY);
z15.SetLineWeight(line_thick);
z15.HideBubble();

plot z16 = if show_lines_wsquares and x16 then r16mid else na;
z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max16 then GlobalColor("colorhi") else color.gray);
z16.SetDefaultColor(Color.GRAY);
z16.SetLineWeight(line_thick);
z16.HideBubble();

plot z17 = if show_lines_wsquares and x17 then r17mid else na;
z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max17 then GlobalColor("colorhi") else color.gray);
z17.SetDefaultColor(Color.GRAY);
z17.SetLineWeight(line_thick);
z17.HideBubble();

plot z18 = if show_lines_wsquares and x18 then r18mid else na;
z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z18.AssignValueColor(if max18 then GlobalColor("colorhi") else color.gray);
z18.SetDefaultColor(Color.GRAY);
z18.SetLineWeight(line_thick);
z18.HideBubble();

plot z19 = if show_lines_wsquares and x19 then r19mid else na;
z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z19.AssignValueColor(if max19 then GlobalColor("colorhi") else color.gray);
z19.SetDefaultColor(Color.GRAY);
z19.SetLineWeight(line_thick);
z19.HideBubble();

plot z20 = if show_lines_wsquares and x20 then r20mid else na;
z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z20.AssignValueColor(if max20 then GlobalColor("colorhi") else color.gray);
z20.SetDefaultColor(Color.GRAY);
z20.SetLineWeight(line_thick);
z20.HideBubble();

plot z21 = if show_lines_wsquares and x21 then r21mid else na;
z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z21.AssignValueColor(if max21 then GlobalColor("colorhi") else color.gray);
z21.SetDefaultColor(Color.GRAY);
z21.SetLineWeight(line_thick);
z21.HideBubble();

plot z22 = if show_lines_wsquares and x22 then r22mid else na;
z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z22.AssignValueColor(if max22 then GlobalColor("colorhi") else color.gray);
z22.SetDefaultColor(Color.GRAY);
z22.SetLineWeight(line_thick);
z22.HideBubble();

plot z23 = if show_lines_wsquares and x23 then r23mid else na;
z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z23.AssignValueColor(if max23 then GlobalColor("colorhi") else color.gray);
z23.SetDefaultColor(Color.GRAY);
z23.SetLineWeight(line_thick);
z23.HideBubble();

plot z24 = if show_lines_wsquares and x24 then r24mid else na;
z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z24.AssignValueColor(if max24 then GlobalColor("colorhi") else color.gray);
z24.SetDefaultColor(Color.GRAY);
z24.SetLineWeight(line_thick);
z24.HideBubble();

plot z25 = if show_lines_wsquares and x25 then r25mid else na;
z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z25.AssignValueColor(if max25 then GlobalColor("colorhi") else color.gray);
z25.SetDefaultColor(Color.GRAY);
z25.SetLineWeight(line_thick);
z25.HideBubble();

plot z26 = if show_lines_wsquares and x26 then r26mid else na;
z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z26.AssignValueColor(if max26 then GlobalColor("colorhi") else color.gray);
z26.SetDefaultColor(Color.GRAY);
z26.SetLineWeight(line_thick);
z26.HideBubble();

plot z27 = if show_lines_wsquares and x27 then r27mid else na;
z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z27.AssignValueColor(if max27 then GlobalColor("colorhi") else color.gray);
z27.SetDefaultColor(Color.GRAY);
z27.SetLineWeight(line_thick);
z27.HideBubble();

plot z28 = if show_lines_wsquares and x28 then r28mid else na;
z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z28.AssignValueColor(if max28 then GlobalColor("colorhi") else color.gray);
z28.SetDefaultColor(Color.GRAY);
z28.SetLineWeight(line_thick);
z28.HideBubble();

plot z29 = if show_lines_wsquares and x29 then r29mid else na;
z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z29.AssignValueColor(if max29 then GlobalColor("colorhi") else color.gray);
z29.SetDefaultColor(Color.GRAY);
z29.SetLineWeight(line_thick);
z29.HideBubble();

plot z30 = if show_lines_wsquares and x30 then r30mid else na;
z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z30.AssignValueColor(if max30 then GlobalColor("colorhi") else color.gray);
z30.SetDefaultColor(Color.GRAY);
z30.SetLineWeight(line_thick);
z30.HideBubble();

plot z31 = if show_lines_wsquares and x31 then r31mid else na;
z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z31.AssignValueColor(if max31 then GlobalColor("colorhi") else color.gray);
z31.SetDefaultColor(Color.GRAY);
z31.SetLineWeight(line_thick);
z31.HideBubble();

plot z32 = if show_lines_wsquares and x32 then r32mid else na;
z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z32.AssignValueColor(if max32 then GlobalColor("colorhi") else color.gray);
z32.SetDefaultColor(Color.GRAY);
z32.SetLineWeight(line_thick);
z32.HideBubble();

plot z33 = if show_lines_wsquares and x33 then r33mid else na;
z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z33.AssignValueColor(if max33 then GlobalColor("colorhi") else color.gray);
z33.SetDefaultColor(Color.GRAY);
z33.SetLineWeight(line_thick);
z33.HideBubble();

plot z34 = if show_lines_wsquares and x34 then r34mid else na;
z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z34.AssignValueColor(if max34 then GlobalColor("colorhi") else color.gray);
z34.SetDefaultColor(Color.GRAY);
z34.SetLineWeight(line_thick);
z34.HideBubble();

plot z35 = if show_lines_wsquares and x35 then r35mid else na;
z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z35.AssignValueColor(if max35 then GlobalColor("colorhi") else color.gray);
z35.SetDefaultColor(Color.GRAY);
z35.SetLineWeight(line_thick);
z35.HideBubble();

plot z36 = if show_lines_wsquares and x36 then r36mid else na;
z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z36.AssignValueColor(if max36 then GlobalColor("colorhi") else color.gray);
z36.SetDefaultColor(Color.GRAY);
z36.SetLineWeight(line_thick);
z36.HideBubble();

plot z37 = if show_lines_wsquares and x37 then r37mid else na;
z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z37.AssignValueColor(if max37 then GlobalColor("colorhi") else color.gray);
#z37.SetDefaultColor(Color.GRAY);
z37.SetLineWeight(line_thick);
z37.HideBubble();

plot z38 = if show_lines_wsquares and x38 then r38mid else na;
z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z38.AssignValueColor(if max38 then GlobalColor("colorhi") else color.gray);
#z38.SetDefaultColor(Color.GRAY);
z38.SetLineWeight(line_thick);
z38.HideBubble();

plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z39.AssignValueColor(if max39 then GlobalColor("colorhi") else color.gray);
#z39.SetDefaultColor(Color.GRAY);
z39.SetLineWeight(line_thick);
z39.HideBubble();


#---------------------------
# test stuff

input test1 = no;
AddChartBubble(test1, 82,
bn + "\n" +
lastbn + "\n" +
maxdata + "\n" +
r00cnt + "\n" +
r00r + "\n" +
#visual_row_width + "\n" +
Floor(r00cnt / maxdata) + "\n" +
x0
, Color.YELLOW, no);
#
#
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);
 
Last edited by a moderator:
Modify "Poor Man's Volume Profile" to identify and label profile shapes

@halcyonguy and some assisting members converted a pinescript study that creates a volume profile here.

I think this is interesting because if I understand correcting, the "profile" generation function in thinkscript doesn't allow for much scripting interaction, whereas this "Poor Man's Volume Profile" is not using the "profile" function and should therefore offer more possibilities.

For example, with the Poor Man's Volume Profile, wouldn't it be possible to code signals that are conditional based on the shape of the profile? I think so if the profile shapes can be defined objectively enough. It seems like that would be possible.

In the code, each line is plotted as z0 through z39 for creating 40 horizontal profile bars total. Intuitively it seems like profile shapes could just be defined by creating ranges of these bars as quadrants of the profile and taking the percentage totals of the quadrants versus each other.

For example, I tried adding this code at the end of the study:

Code:
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

I can't find any charts that will show the labels and I think the reason is probably that the definitions of the profile shapes are too simplistic and therefore not capturing real profile shapes (only ideal ones).

Anyone have any suggestions or ideas about a better way to try to mathematically define the profile shapes? Or is it too subjective to be expressed as code in a practical way?

(Complete script is provided below: )

Code:
# Poorman_volume_profile_02b

#finished by rrm411
#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#post5


#  replace max()  at 500+  that find row max #s


#Poor man's volume profile
#https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/
#1100 lines
#// © Ildar Akhmetgaleev (AkhIL)
#// See https://github.com/akhilman/vol-poorofile
#// vim: shiftwidth=2 tabstop=2
#study("Poor man's volume profile", "PMVolProf", overlay=true, max_bars_back=500)


def na = double.nan;
def bn = BarNumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

#def lastbar = !isnan(close[0]) and isnan(close[-1]);

def minb = 10;
def maxb = 500;
input block_size2 = 200;
def block_size = if block_size2 < minb then minb else if block_size2 > maxb then maxb else block_size2;
input visual_row_width = 50;
input show_peaks = yes;

AddLabel(1, "look " + block_size + " bars back", Color.YELLOW);

input show_vert_line_range_start = yes;
def first = (!IsNaN(close[-block_size]) and IsNaN(close[-(block_size + 1)]));
AddVerticalLine(show_vert_line_range_start and first, "-", Color.CYAN);


#// Calculate profile

def block_high = Highest(high, block_size);
def block_low = Lowest(low, block_size);
def highest_row_value = 0;


# data to collect
# count bars in a range
#def data = 1;
# convert volume to millions
#def data = volume/1000000;
# convert volume to 1000s
def data = volume / 1000;


# do stuff on last bar

def row_qty = 40;
def block_height = block_high - block_low;
def row_height = block_height / row_qty;

# chg first values to 1, so no divide by 0 err
def k = 1;
def r00lo = if bn == 1 then k else if lastbar then (block_low + row_height * 0) else r00lo[1];
def r00hi = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r00hi[1];
def r01lo = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r01lo[1];
def r01hi = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r01hi[1];
def r02lo = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r02lo[1];
def r02hi = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r02hi[1];
def r03lo = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r03lo[1];
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
def r04lo = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r04lo[1];
def r04hi = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r04hi[1];
def r05lo = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r05lo[1];
def r05hi = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r05hi[1];
def r06lo = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r06lo[1];
def r06hi = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r06hi[1];
def r07lo = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r07lo[1];
def r07hi = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r07hi[1];
def r08lo = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r08lo[1];
def r08hi = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r08hi[1];
def r09lo = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r09lo[1];
def r09hi = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r09hi[1];
def r10lo = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r10lo[1];
def r10hi = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r10hi[1];
def r11lo = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r11lo[1];
def r11hi = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r11hi[1];
def r12lo = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r12lo[1];
def r12hi = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r12hi[1];
def r13lo = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r13lo[1];
def r13hi = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r13hi[1];
def r14lo = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r14lo[1];
def r14hi = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r14hi[1];
def r15lo = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r15lo[1];
def r15hi = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r15hi[1];
def r16lo = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r16lo[1];
def r16hi = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r16hi[1];
def r17lo = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r17lo[1];
def r17hi = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r17hi[1];
def r18lo = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r18lo[1];
def r18hi = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r18hi[1];
def r19lo = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r19lo[1];
def r19hi = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r19hi[1];
def r20lo = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r20lo[1];
def r20hi = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r20hi[1];
def r21lo = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r21lo[1];
def r21hi = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r21hi[1];
def r22lo = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r22lo[1];
def r22hi = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r22hi[1];
def r23lo = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r23lo[1];
def r23hi = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r23hi[1];
def r24lo = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r24lo[1];
def r24hi = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r24hi[1];
def r25lo = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r25lo[1];
def r25hi = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r25hi[1];
def r26lo = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r26lo[1];
def r26hi = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r26hi[1];
def r27lo = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r27lo[1];
def r27hi = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r27hi[1];
def r28lo = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r28lo[1];
def r28hi = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r28hi[1];
def r29lo = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r29lo[1];
def r29hi = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r29hi[1];
def r30lo = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r30lo[1];
def r30hi = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r30hi[1];
def r31lo = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r31lo[1];
def r31hi = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r31hi[1];
def r32lo = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r32lo[1];
def r32hi = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r32hi[1];
def r33lo = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r33lo[1];
def r33hi = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r33hi[1];
def r34lo = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r34lo[1];
def r34hi = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r34hi[1];
def r35lo = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r35lo[1];
def r35hi = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r35hi[1];
def r36lo = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r36lo[1];
def r36hi = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r36hi[1];
def r37lo = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r37lo[1];
def r37hi = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r37hi[1];
def r38lo = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r38lo[1];
def r38hi = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r38hi[1];
def r39lo = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r39lo[1];
def r39hi = if bn == 1 then k else if lastbar then (block_low + row_height * 40) else r39hi[1];



def r00mid = (r00hi + r00lo) / 2;
def r01mid = (r01hi + r01lo) / 2;
def r02mid = (r02hi + r02lo) / 2;
def r03mid = (r03hi + r03lo) / 2;
def r04mid = (r04hi + r04lo) / 2;
def r05mid = (r05hi + r05lo) / 2;
def r06mid = (r06hi + r06lo) / 2;
def r07mid = (r07hi + r07lo) / 2;
def r08mid = (r08hi + r08lo) / 2;
def r09mid = (r09hi + r09lo) / 2;
def r10mid = (r10hi + r10lo) / 2;
def r11mid = (r11hi + r11lo) / 2;
def r12mid = (r12hi + r12lo) / 2;
def r13mid = (r13hi + r13lo) / 2;
def r14mid = (r14hi + r14lo) / 2;
def r15mid = (r15hi + r15lo) / 2;
def r16mid = (r16hi + r16lo) / 2;
def r17mid = (r17hi + r17lo) / 2;
def r18mid = (r18hi + r18lo) / 2;
def r19mid = (r19hi + r19lo) / 2;
def r20mid = (r20hi + r20lo) / 2;
def r21mid = (r21hi + r21lo) / 2;
def r22mid = (r22hi + r22lo) / 2;
def r23mid = (r23hi + r23lo) / 2;
def r24mid = (r24hi + r24lo) / 2;
def r25mid = (r25hi + r25lo) / 2;
def r26mid = (r26hi + r26lo) / 2;
def r27mid = (r27hi + r27lo) / 2;
def r28mid = (r28hi + r28lo) / 2;
def r29mid = (r29hi + r29lo) / 2;
def r30mid = (r30hi + r30lo) / 2;
def r31mid = (r31hi + r31lo) / 2;
def r32mid = (r32hi + r32lo) / 2;
def r33mid = (r33hi + r33lo) / 2;
def r34mid = (r34hi + r34lo) / 2;
def r35mid = (r35hi + r35lo) / 2;
def r36mid = (r36hi + r36lo) / 2;
def r37mid = (r37hi + r37lo) / 2;
def r38mid = (r38hi + r38lo) / 2;
def r39mid = (r39hi + r39lo) / 2;


# on last bar,
# look back at prev bars, to see if part of them were within a price row range,
# if so, then add the data from that bar , volume

def m = 1;
def r00cnt = if bn == 1 then m else if lastbar then fold i0 = 0 to block_size
 with p0
 do p0 + (if GetValue(low, i0) < r00hi and GetValue(high, i0) > r00lo then GetValue(data, i0) else 0)
 else r00cnt[1];

def r01cnt = if bn == 1 then m else if lastbar then fold i1 = 0 to block_size
 with p1
 do p1 + (if GetValue(low, i1) < r01hi and GetValue(high, i1) > r01lo then GetValue(data, i1) else 0)
 else r01cnt[1];

def r02cnt = if bn == 1 then m else if lastbar then fold i2 = 0 to block_size
 with p2
 do p2 + (if GetValue(low, i2) < r02hi and GetValue(high, i2) > r02lo then GetValue(data, i2) else 0)
 else r02cnt[1];

def r03cnt = if bn == 1 then m else if lastbar then fold i3 = 0 to block_size
 with p3
 do p3 + (if GetValue(low, i3) < r03hi and GetValue(high, i3) > r03lo then GetValue(data, i3) else 0)
 else r03cnt[1];

def r04cnt = if bn == 1 then m else if lastbar then fold i4 = 0 to block_size
 with p4
 do p4 + (if GetValue(low, i4) < r04hi and GetValue(high, i4) > r04lo then GetValue(data, i4) else 0)
 else r04cnt[1];

def r05cnt = if bn == 1 then m else if lastbar then fold i5 = 0 to block_size
 with p5
 do p5 + (if GetValue(low, i5) < r05hi and GetValue(high, i5) > r05lo then GetValue(data, i5) else 0)
 else r05cnt[1];

def r06cnt = if bn == 1 then m else if lastbar then fold i6 = 0 to block_size
 with p6
 do p6 + (if GetValue(low, i6) < r06hi and GetValue(high, i6) > r06lo then GetValue(data, i6) else 0)
 else r06cnt[1];

def r07cnt = if bn == 1 then m else if lastbar then fold i7 = 0 to block_size
 with p7
 do p7 + (if GetValue(low, i7) < r07hi and GetValue(high, i7) > r07lo then GetValue(data, i7) else 0)
 else r07cnt[1];

def r08cnt = if bn == 1 then m else if lastbar then fold i8 = 0 to block_size
 with p8
 do p8 + (if GetValue(low, i8) < r08hi and GetValue(high, i8) > r08lo then GetValue(data, i8) else 0)
 else r08cnt[1];

def r09cnt = if bn == 1 then m else if lastbar then fold i9 = 0 to block_size
 with p9
 do p9 + (if GetValue(low, i9) < r09hi and GetValue(high, i9) > r09lo then GetValue(data, i9) else 0)
 else r09cnt[1];

def r10cnt = if bn == 1 then m else if lastbar then fold i10 = 0 to block_size
 with p10
 do p10 + (if GetValue(low, i10) < r10hi and GetValue(high, i10) > r10lo then GetValue(data, i10) else 0)
 else r10cnt[1];

def r11cnt = if bn == 1 then m else if lastbar then fold i11 = 0 to block_size
 with p11
 do p11 + (if GetValue(low, i11) < r11hi and GetValue(high, i11) > r11lo then GetValue(data, i11) else 0)
 else r11cnt[1];

def r12cnt = if bn == 1 then m else if lastbar then fold i12 = 0 to block_size
 with p12
 do p12 + (if GetValue(low, i12) < r12hi and GetValue(high, i12) > r12lo then GetValue(data, i12) else 0)
 else r12cnt[1];

def r13cnt = if bn == 1 then m else if lastbar then fold i13 = 0 to block_size
 with p13
 do p13 + (if GetValue(low, i13) < r13hi and GetValue(high, i13) > r13lo then GetValue(data, i13) else 0)
 else r13cnt[1];

def r14cnt = if bn == 1 then m else if lastbar then fold i14 = 0 to block_size
 with p14
 do p14 + (if GetValue(low, i14) < r14hi and GetValue(high, i14) > r14lo then GetValue(data, i14) else 0)
 else r14cnt[1];

def r15cnt = if bn == 1 then m else if lastbar then fold i15 = 0 to block_size
 with p15
 do p15 + (if GetValue(low, i15) < r15hi and GetValue(high, i15) > r15lo then GetValue(data, i15) else 0)
 else r15cnt[1];

def r16cnt = if bn == 1 then m else if lastbar then fold i16 = 0 to block_size
 with p16
 do p16 + (if GetValue(low, i16) < r16hi and GetValue(high, i16) > r16lo then GetValue(data, i16) else 0)
 else r16cnt[1];

def r17cnt = if bn == 1 then m else if lastbar then fold i17 = 0 to block_size
 with p17
 do p17 + (if GetValue(low, i17) < r17hi and GetValue(high, i17) > r17lo then GetValue(data, i17) else 0)
 else r17cnt[1];

def r18cnt = if bn == 1 then m else if lastbar then fold i18 = 0 to block_size
 with p18
 do p18 + (if GetValue(low, i18) < r18hi and GetValue(high, i18) > r18lo then GetValue(data, i18) else 0)
 else r18cnt[1];

def r19cnt = if bn == 1 then m else if lastbar then fold i19 = 0 to block_size
 with p19
 do p19 + (if GetValue(low, i19) < r19hi and GetValue(high, i19) > r19lo then GetValue(data, i19) else 0)
 else r19cnt[1];

def r20cnt = if bn == 1 then m else if lastbar then fold i20 = 0 to block_size
 with p20
 do p20 + (if GetValue(low, i20) < r20hi and GetValue(high, i20) > r20lo then GetValue(data, i20) else 0)
 else r20cnt[1];

def r21cnt = if bn == 1 then m else if lastbar then fold i21 = 0 to block_size
 with p21
 do p21 + (if GetValue(low, i21) < r21hi and GetValue(high, i21) > r21lo then GetValue(data, i21) else 0)
 else r21cnt[1];

def r22cnt = if bn == 1 then m else if lastbar then fold i22 = 0 to block_size
 with p22
 do p22 + (if GetValue(low, i22) < r22hi and GetValue(high, i22) > r22lo then GetValue(data, i22) else 0)
 else r22cnt[1];

def r23cnt = if bn == 1 then m else if lastbar then fold i23 = 0 to block_size
 with p23
 do p23 + (if GetValue(low, i23) < r23hi and GetValue(high, i23) > r23lo then GetValue(data, i23) else 0)
 else r23cnt[1];

def r24cnt = if bn == 1 then m else if lastbar then fold i24 = 0 to block_size
 with p24
 do p24 + (if GetValue(low, i24) < r24hi and GetValue(high, i24) > r24lo then GetValue(data, i24) else 0)
 else r24cnt[1];

def r25cnt = if bn == 1 then m else if lastbar then fold i25 = 0 to block_size
 with p25
 do p25 + (if GetValue(low, i25) < r25hi and GetValue(high, i25) > r25lo then GetValue(data, i25) else 0)
 else r25cnt[1];

def r26cnt = if bn == 1 then m else if lastbar then fold i26 = 0 to block_size
 with p26
 do p26 + (if GetValue(low, i26) < r26hi and GetValue(high, i26) > r26lo then GetValue(data, i26) else 0)
 else r26cnt[1];

def r27cnt = if bn == 1 then m else if lastbar then fold i27 = 0 to block_size
 with p27
 do p27 + (if GetValue(low, i27) < r27hi and GetValue(high, i27) > r27lo then GetValue(data, i27) else 0)
 else r27cnt[1];

def r28cnt = if bn == 1 then m else if lastbar then fold i28 = 0 to block_size
 with p28
 do p28 + (if GetValue(low, i28) < r28hi and GetValue(high, i28) > r28lo then GetValue(data, i28) else 0)
 else r28cnt[1];

def r29cnt = if bn == 1 then m else if lastbar then fold i29 = 0 to block_size
 with p29
 do p29 + (if GetValue(low, i29) < r29hi and GetValue(high, i29) > r29lo then GetValue(data, i29) else 0)
 else r29cnt[1];

def r30cnt = if bn == 1 then m else if lastbar then fold i30 = 0 to block_size
 with p30
 do p30 + (if GetValue(low, i30) < r30hi and GetValue(high, i30) > r30lo then GetValue(data, i30) else 0)
 else r30cnt[1];

def r31cnt = if bn == 1 then m else if lastbar then fold i31 = 0 to block_size
 with p31
 do p31 + (if GetValue(low, i31) < r31hi and GetValue(high, i31) > r31lo then GetValue(data, i31) else 0)
 else r31cnt[1];

def r32cnt = if bn == 1 then m else if lastbar then fold i32 = 0 to block_size
 with p32
 do p32 + (if GetValue(low, i32) < r32hi and GetValue(high, i32) > r32lo then GetValue(data, i32) else 0)
 else r32cnt[1];

def r33cnt = if bn == 1 then m else if lastbar then fold i33 = 0 to block_size
 with p33
 do p33 + (if GetValue(low, i33) < r33hi and GetValue(high, i33) > r33lo then GetValue(data, i33) else 0)
 else r33cnt[1];

def r34cnt = if bn == 1 then m else if lastbar then fold i34 = 0 to block_size
 with p34
 do p34 + (if GetValue(low, i34) < r34hi and GetValue(high, i34) > r34lo then GetValue(data, i34) else 0)
 else r34cnt[1];

def r35cnt = if bn == 1 then m else if lastbar then fold i35 = 0 to block_size
 with p35
 do p35 + (if GetValue(low, i35) < r35hi and GetValue(high, i35) > r35lo then GetValue(data, i35) else 0)
 else r35cnt[1];

def r36cnt = if bn == 1 then m else if lastbar then fold i36 = 0 to block_size
 with p36
 do p36 + (if GetValue(low, i36) < r36hi and GetValue(high, i36) > r36lo then GetValue(data, i36) else 0)
 else r36cnt[1];

def r37cnt = if bn == 1 then m else if lastbar then fold i37 = 0 to block_size
 with p37
 do p37 + (if GetValue(low, i37) < r37hi and GetValue(high, i37) > r37lo then GetValue(data, i37) else 0)
 else r37cnt[1];

def r38cnt = if bn == 1 then m else if lastbar then fold i38 = 0 to block_size
 with p38
 do p38 + (if GetValue(low, i38) < r38hi and GetValue(high, i38) > r38lo then GetValue(data, i38) else 0)
 else r38cnt[1];

def r39cnt = if bn == 1 then m else if lastbar then fold i39 = 0 to block_size
 with p39
 do p39 + (if GetValue(low, i39) < r39hi and GetValue(high, i39) > r39lo then GetValue(data, i39) else 0)
 else r39cnt[1];



# find max data sum
def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# calc ratio of cnt to highest cnt , a bar cnt , for the horz length of each row
def r00r = Floor(visual_row_width * r00cnt / maxdata);
def r01r = Floor(visual_row_width * r01cnt / maxdata);
def r02r = Floor(visual_row_width * r02cnt / maxdata);
def r03r = Floor(visual_row_width * r03cnt / maxdata);
def r04r = Floor(visual_row_width * r04cnt / maxdata);
def r05r = Floor(visual_row_width * r05cnt / maxdata);
def r06r = Floor(visual_row_width * r06cnt / maxdata);
def r07r = Floor(visual_row_width * r07cnt / maxdata);
def r08r = Floor(visual_row_width * r08cnt / maxdata);
def r09r = Floor(visual_row_width * r09cnt / maxdata);
def r10r = Floor(visual_row_width * r10cnt / maxdata);
def r11r = Floor(visual_row_width * r11cnt / maxdata);
def r12r = Floor(visual_row_width * r12cnt / maxdata);
def r13r = Floor(visual_row_width * r13cnt / maxdata);
def r14r = Floor(visual_row_width * r14cnt / maxdata);
def r15r = Floor(visual_row_width * r15cnt / maxdata);
def r16r = Floor(visual_row_width * r16cnt / maxdata);
def r17r = Floor(visual_row_width * r17cnt / maxdata);
def r18r = Floor(visual_row_width * r18cnt / maxdata);
def r19r = Floor(visual_row_width * r19cnt / maxdata);
def r20r = Floor(visual_row_width * r20cnt / maxdata);
def r21r = Floor(visual_row_width * r21cnt / maxdata);
def r22r = Floor(visual_row_width * r22cnt / maxdata);
def r23r = Floor(visual_row_width * r23cnt / maxdata);
def r24r = Floor(visual_row_width * r24cnt / maxdata);
def r25r = Floor(visual_row_width * r25cnt / maxdata);
def r26r = Floor(visual_row_width * r26cnt / maxdata);
def r27r = Floor(visual_row_width * r27cnt / maxdata);
def r28r = Floor(visual_row_width * r28cnt / maxdata);
def r29r = Floor(visual_row_width * r29cnt / maxdata);
def r30r = Floor(visual_row_width * r30cnt / maxdata);
def r31r = Floor(visual_row_width * r31cnt / maxdata);
def r32r = Floor(visual_row_width * r32cnt / maxdata);
def r33r = Floor(visual_row_width * r33cnt / maxdata);
def r34r = Floor(visual_row_width * r34cnt / maxdata);
def r35r = Floor(visual_row_width * r35cnt / maxdata);
def r36r = Floor(visual_row_width * r36cnt / maxdata);
def r37r = Floor(visual_row_width * r37cnt / maxdata);
def r38r = Floor(visual_row_width * r38cnt / maxdata);
def r39r = Floor(visual_row_width * r39cnt / maxdata);



#// Draw profile


# draw rows on bars after the last bar
# mark bars after lastbar as true, if the ratio cnt of bars .....
def x0 = (bn > lastbn and bn <= (lastbn + r00r));
def x1 = (bn > lastbn and bn <= (lastbn + r01r));
def x2 = (bn > lastbn and bn <= (lastbn + r02r));
def x3 = (bn > lastbn and bn <= (lastbn + r03r));
def x4 = (bn > lastbn and bn <= (lastbn + r04r));
def x5 = (bn > lastbn and bn <= (lastbn + r05r));
def x6 = (bn > lastbn and bn <= (lastbn + r06r));
def x7 = (bn > lastbn and bn <= (lastbn + r07r));
def x8 = (bn > lastbn and bn <= (lastbn + r08r));
def x9 = (bn > lastbn and bn <= (lastbn + r09r));
def x10 = (bn > lastbn and bn <= (lastbn + r10r));
def x11 = (bn > lastbn and bn <= (lastbn + r11r));
def x12 = (bn > lastbn and bn <= (lastbn + r12r));
def x13 = (bn > lastbn and bn <= (lastbn + r13r));
def x14 = (bn > lastbn and bn <= (lastbn + r14r));
def x15 = (bn > lastbn and bn <= (lastbn + r15r));
def x16 = (bn > lastbn and bn <= (lastbn + r16r));
def x17 = (bn > lastbn and bn <= (lastbn + r17r));
def x18 = (bn > lastbn and bn <= (lastbn + r18r));
def x19 = (bn > lastbn and bn <= (lastbn + r19r));
def x20 = (bn > lastbn and bn <= (lastbn + r20r));
def x21 = (bn > lastbn and bn <= (lastbn + r21r));
def x22 = (bn > lastbn and bn <= (lastbn + r22r));
def x23 = (bn > lastbn and bn <= (lastbn + r23r));
def x24 = (bn > lastbn and bn <= (lastbn + r24r));
def x25 = (bn > lastbn and bn <= (lastbn + r25r));
def x26 = (bn > lastbn and bn <= (lastbn + r26r));
def x27 = (bn > lastbn and bn <= (lastbn + r27r));
def x28 = (bn > lastbn and bn <= (lastbn + r28r));
def x29 = (bn > lastbn and bn <= (lastbn + r29r));
def x30 = (bn > lastbn and bn <= (lastbn + r30r));
def x31 = (bn > lastbn and bn <= (lastbn + r31r));
def x32 = (bn > lastbn and bn <= (lastbn + r32r));
def x33 = (bn > lastbn and bn <= (lastbn + r33r));
def x34 = (bn > lastbn and bn <= (lastbn + r34r));
def x35 = (bn > lastbn and bn <= (lastbn + r35r));
def x36 = (bn > lastbn and bn <= (lastbn + r36r));
def x37 = (bn > lastbn and bn <= (lastbn + r37r));
def x38 = (bn > lastbn and bn <= (lastbn + r38r));
def x39 = (bn > lastbn and bn <= (lastbn + r39r));


#---------------------------

# orig codes
# find max value , +-5 values , compare each row value to 10 other values
# if current is the max, then orange
#   if first , compare to 5 future
#   later , compare to 5 before and 5 after
#   last , compare to 5 prev

# ref - orig code
#if row0_value >= row1_value and row0_value >= row2_value and row0_value >= row3_value and row0_value >= row4_value and row0_value >= row5_value
#        row0_is_peak := true

#if row10_value >= row5_value and row10_value >= row6_value and row10_value >= row7_value and row10_value >= row8_value and row10_value >= row9_value and row10_value >= row11_value and row10_value >= row12_value and row10_value >= row13_value and row10_value >= row14_value and row10_value >= row15_value
#        row10_is_peak := true

#if row20_value >= row15_value and row20_value >= row16_value and row20_value >= row17_value and row20_value >= row18_value and row20_value >= row19_value and row20_value >= row21_value and row20_value >= row22_value and row20_value >= row23_value and row20_value >= row24_value and row20_value >= row25_value
#        row20_is_peak := true

#if row39_value >= row34_value and row39_value >= row35_value and row39_value >= row36_value and row39_value >= row37_value and row39_value >= row38_value
#        row39_is_peak := true

#------------------

# copied from line 394
#def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# compare current row to prev 5 rows and future 5 rows

def max00 = if r00cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, r05cnt)))))) then 1 else 0;
def max01 = if r01cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, r06cnt))))))) then 1 else 0;
def max02 = if r02cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, r07cnt)))))))) then 1 else 0;
def max03 = if r03cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, r08cnt))))))))) then 1 else 0;
def max04 = if r04cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, r09cnt)))))))))) then 1 else 0;

def max05 = if r05cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, r10cnt))))))))))) then 1 else 0;
def max06 = if r06cnt == (Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, r11cnt))))))))))) then 1 else 0;
def max07 = if r07cnt == (Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, r12cnt))))))))))) then 1 else 0;
def max08 = if r08cnt == (Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, r13cnt))))))))))) then 1 else 0;
def max09 = if r09cnt == (Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, r14cnt))))))))))) then 1 else 0;
def max10 = if r10cnt == (Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, r15cnt))))))))))) then 1 else 0;
def max11 = if r11cnt == (Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, r16cnt))))))))))) then 1 else 0;
def max12 = if r12cnt == (Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, r17cnt))))))))))) then 1 else 0;

def max13 = if r13cnt == (Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, r18cnt))))))))))) then 1 else 0;
def max14 = if r14cnt == (Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, r19cnt))))))))))) then 1 else 0;
def max15 = if r15cnt == (Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, r20cnt))))))))))) then 1 else 0;
def max16 = if r16cnt == (Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, r21cnt))))))))))) then 1 else 0;
def max17 = if r17cnt == (Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, r22cnt))))))))))) then 1 else 0;
def max18 = if r18cnt == (Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, r23cnt))))))))))) then 1 else 0;
def max19 = if r19cnt == (Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, r23cnt))))))))))) then 1 else 0;

def max20 = if r20cnt == (Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, r25cnt))))))))))) then 1 else 0;
def max21 = if r21cnt == (Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, r26cnt))))))))))) then 1 else 0;
def max22 = if r22cnt == (Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, r27cnt))))))))))) then 1 else 0;
def max23 = if r23cnt == (Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, r23cnt))))))))))) then 1 else 0;
def max24 = if r24cnt == (Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, r29cnt))))))))))) then 1 else 0;
def max25 = if r25cnt == (Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, r30cnt))))))))))) then 1 else 0;
def max26 = if r26cnt == (Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, r31cnt))))))))))) then 1 else 0;
def max27 = if r27cnt == (Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, r32cnt))))))))))) then 1 else 0;
def max28 = if r28cnt == (Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, r33cnt))))))))))) then 1 else 0;
def max29 = if r29cnt == (Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, r34cnt))))))))))) then 1 else 0;

def max30 = if r30cnt == (Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, r35cnt))))))))))) then 1 else 0;
def max31 = if r31cnt == (Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, r36cnt))))))))))) then 1 else 0;
def max32 = if r32cnt == (Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, r37cnt))))))))))) then 1 else 0;
def max33 = if r33cnt == (Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, r38cnt))))))))))) then 1 else 0;
def max34 = if r34cnt == (Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))))) then 1 else 0;

def max35 = if r35cnt == (Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))) then 1 else 0;
def max36 = if r36cnt == (Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))) then 1 else 0;
def max37 = if r37cnt == (Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))) then 1 else 0;
def max38 = if r38cnt == (Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))) then 1 else 0;
def max39 = if r39cnt == (Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))) then 1 else 0;

#---------------------------


#  replace max()  at 500+  that find row max #s
# hmm  diff vars , so cant just use highest()...

# def mx00 =


#-----------------------------

defineglobalcolor("colorhi", color.orange);

input line_thick = 2;
input show_lines_wsquares = yes;

plot z0 = if show_lines_wsquares and x0 then r00mid else na;
z0.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max00 then GlobalColor("colorhi") else color.gray);
#z0.SetDefaultColor(Color.GRAY);
z0.SetLineWeight(line_thick);
z0.HideBubble();

plot z1 = if show_lines_wsquares and x1 then r01mid else na;
z1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z1.AssignValueColor(if max01 then GlobalColor("colorhi") else color.gray);
#z1.SetDefaultColor(Color.GRAY);
z1.SetLineWeight(line_thick);
z1.HideBubble();

plot z2 = if show_lines_wsquares and x2 then r02mid else na;
z2.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z2.AssignValueColor(if max02 then GlobalColor("colorhi") else color.gray);
#z2.SetDefaultColor(Color.GRAY);
z2.SetLineWeight(line_thick);
z2.HideBubble();

plot z3 = if show_lines_wsquares and x3 then r03mid else na;
z3.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z3.AssignValueColor(if max03 then GlobalColor("colorhi") else color.gray);
#z3.SetDefaultColor(Color.GRAY);
z3.SetLineWeight(line_thick);
z3.HideBubble();

plot z4 = if show_lines_wsquares and x4 then r04mid else na;
z4.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z4.AssignValueColor(if max04 then GlobalColor("colorhi") else color.gray);
z4.SetDefaultColor(Color.GRAY);
z4.SetLineWeight(line_thick);
z4.HideBubble();

plot z5 = if show_lines_wsquares and x5 then r05mid else na;
z5.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z5.AssignValueColor(if max05 then GlobalColor("colorhi") else color.gray);
#z5.SetDefaultColor(Color.GRAY);
z5.SetLineWeight(line_thick);
z5.HideBubble();

plot z6 = if show_lines_wsquares and x6 then r06mid else na;
z6.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z6.AssignValueColor(if max06 then GlobalColor("colorhi") else color.gray);
z6.SetDefaultColor(Color.GRAY);
z6.SetLineWeight(line_thick);
z6.HideBubble();

plot z7 = if show_lines_wsquares and x7 then r07mid else na;
z7.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z7.AssignValueColor(if max07 then GlobalColor("colorhi") else color.gray);
#z7.SetDefaultColor(Color.GRAY);
z7.SetLineWeight(line_thick);
z7.HideBubble();

plot z8 = if show_lines_wsquares and x8 then r08mid else na;
z8.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z8.AssignValueColor(if max08 then GlobalColor("colorhi") else color.gray);
#z8.SetDefaultColor(Color.GRAY);
z8.SetLineWeight(line_thick);
z8.HideBubble();

plot z9 = if show_lines_wsquares and x9 then r09mid else na;
z9.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z9.AssignValueColor(if max09 then GlobalColor("colorhi") else color.gray);
#z9.SetDefaultColor(Color.GRAY);
z9.SetLineWeight(line_thick);
z9.HideBubble();

plot z10 = if show_lines_wsquares and x10 then r10mid else na;
z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z10.AssignValueColor(if max10 then GlobalColor("colorhi") else color.gray);
#z10.SetDefaultColor(Color.GRAY);
z10.SetLineWeight(line_thick);
z10.HideBubble();

plot z11 = if show_lines_wsquares and x11 then r11mid else na;
z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z11.AssignValueColor(if max11 then GlobalColor("colorhi") else color.gray);
#z11.SetDefaultColor(Color.GRAY);
z11.SetLineWeight(line_thick);
z11.HideBubble();

plot z12 = if show_lines_wsquares and x12 then r12mid else na;
z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z12.AssignValueColor(if max12 then GlobalColor("colorhi") else color.gray);
#z12.SetDefaultColor(Color.GRAY);
z12.SetLineWeight(line_thick);
z12.HideBubble();

plot z13 = if show_lines_wsquares and x13 then r13mid else na;
z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z13.AssignValueColor(if max13 then GlobalColor("colorhi") else color.gray);
z13.SetDefaultColor(Color.GRAY);
z13.SetLineWeight(line_thick);
z13.HideBubble();

plot z14 = if show_lines_wsquares and x14 then r14mid else na;
z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z14.AssignValueColor(if max14 then GlobalColor("colorhi") else color.gray);
#z14.SetDefaultColor(Color.GRAY);
z14.SetLineWeight(line_thick);
z14.HideBubble();

plot z15 = if show_lines_wsquares and x15 then r15mid else na;
z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z15.AssignValueColor(if max15 then GlobalColor("colorhi") else color.gray);
#z15.SetDefaultColor(Color.GRAY);
z15.SetLineWeight(line_thick);
z15.HideBubble();

plot z16 = if show_lines_wsquares and x16 then r16mid else na;
z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max16 then GlobalColor("colorhi") else color.gray);
z16.SetDefaultColor(Color.GRAY);
z16.SetLineWeight(line_thick);
z16.HideBubble();

plot z17 = if show_lines_wsquares and x17 then r17mid else na;
z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max17 then GlobalColor("colorhi") else color.gray);
z17.SetDefaultColor(Color.GRAY);
z17.SetLineWeight(line_thick);
z17.HideBubble();

plot z18 = if show_lines_wsquares and x18 then r18mid else na;
z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z18.AssignValueColor(if max18 then GlobalColor("colorhi") else color.gray);
z18.SetDefaultColor(Color.GRAY);
z18.SetLineWeight(line_thick);
z18.HideBubble();

plot z19 = if show_lines_wsquares and x19 then r19mid else na;
z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z19.AssignValueColor(if max19 then GlobalColor("colorhi") else color.gray);
z19.SetDefaultColor(Color.GRAY);
z19.SetLineWeight(line_thick);
z19.HideBubble();

plot z20 = if show_lines_wsquares and x20 then r20mid else na;
z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z20.AssignValueColor(if max20 then GlobalColor("colorhi") else color.gray);
z20.SetDefaultColor(Color.GRAY);
z20.SetLineWeight(line_thick);
z20.HideBubble();

plot z21 = if show_lines_wsquares and x21 then r21mid else na;
z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z21.AssignValueColor(if max21 then GlobalColor("colorhi") else color.gray);
z21.SetDefaultColor(Color.GRAY);
z21.SetLineWeight(line_thick);
z21.HideBubble();

plot z22 = if show_lines_wsquares and x22 then r22mid else na;
z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z22.AssignValueColor(if max22 then GlobalColor("colorhi") else color.gray);
z22.SetDefaultColor(Color.GRAY);
z22.SetLineWeight(line_thick);
z22.HideBubble();

plot z23 = if show_lines_wsquares and x23 then r23mid else na;
z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z23.AssignValueColor(if max23 then GlobalColor("colorhi") else color.gray);
z23.SetDefaultColor(Color.GRAY);
z23.SetLineWeight(line_thick);
z23.HideBubble();

plot z24 = if show_lines_wsquares and x24 then r24mid else na;
z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z24.AssignValueColor(if max24 then GlobalColor("colorhi") else color.gray);
z24.SetDefaultColor(Color.GRAY);
z24.SetLineWeight(line_thick);
z24.HideBubble();

plot z25 = if show_lines_wsquares and x25 then r25mid else na;
z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z25.AssignValueColor(if max25 then GlobalColor("colorhi") else color.gray);
z25.SetDefaultColor(Color.GRAY);
z25.SetLineWeight(line_thick);
z25.HideBubble();

plot z26 = if show_lines_wsquares and x26 then r26mid else na;
z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z26.AssignValueColor(if max26 then GlobalColor("colorhi") else color.gray);
z26.SetDefaultColor(Color.GRAY);
z26.SetLineWeight(line_thick);
z26.HideBubble();

plot z27 = if show_lines_wsquares and x27 then r27mid else na;
z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z27.AssignValueColor(if max27 then GlobalColor("colorhi") else color.gray);
z27.SetDefaultColor(Color.GRAY);
z27.SetLineWeight(line_thick);
z27.HideBubble();

plot z28 = if show_lines_wsquares and x28 then r28mid else na;
z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z28.AssignValueColor(if max28 then GlobalColor("colorhi") else color.gray);
z28.SetDefaultColor(Color.GRAY);
z28.SetLineWeight(line_thick);
z28.HideBubble();

plot z29 = if show_lines_wsquares and x29 then r29mid else na;
z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z29.AssignValueColor(if max29 then GlobalColor("colorhi") else color.gray);
z29.SetDefaultColor(Color.GRAY);
z29.SetLineWeight(line_thick);
z29.HideBubble();

plot z30 = if show_lines_wsquares and x30 then r30mid else na;
z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z30.AssignValueColor(if max30 then GlobalColor("colorhi") else color.gray);
z30.SetDefaultColor(Color.GRAY);
z30.SetLineWeight(line_thick);
z30.HideBubble();

plot z31 = if show_lines_wsquares and x31 then r31mid else na;
z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z31.AssignValueColor(if max31 then GlobalColor("colorhi") else color.gray);
z31.SetDefaultColor(Color.GRAY);
z31.SetLineWeight(line_thick);
z31.HideBubble();

plot z32 = if show_lines_wsquares and x32 then r32mid else na;
z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z32.AssignValueColor(if max32 then GlobalColor("colorhi") else color.gray);
z32.SetDefaultColor(Color.GRAY);
z32.SetLineWeight(line_thick);
z32.HideBubble();

plot z33 = if show_lines_wsquares and x33 then r33mid else na;
z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z33.AssignValueColor(if max33 then GlobalColor("colorhi") else color.gray);
z33.SetDefaultColor(Color.GRAY);
z33.SetLineWeight(line_thick);
z33.HideBubble();

plot z34 = if show_lines_wsquares and x34 then r34mid else na;
z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z34.AssignValueColor(if max34 then GlobalColor("colorhi") else color.gray);
z34.SetDefaultColor(Color.GRAY);
z34.SetLineWeight(line_thick);
z34.HideBubble();

plot z35 = if show_lines_wsquares and x35 then r35mid else na;
z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z35.AssignValueColor(if max35 then GlobalColor("colorhi") else color.gray);
z35.SetDefaultColor(Color.GRAY);
z35.SetLineWeight(line_thick);
z35.HideBubble();

plot z36 = if show_lines_wsquares and x36 then r36mid else na;
z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z36.AssignValueColor(if max36 then GlobalColor("colorhi") else color.gray);
z36.SetDefaultColor(Color.GRAY);
z36.SetLineWeight(line_thick);
z36.HideBubble();

plot z37 = if show_lines_wsquares and x37 then r37mid else na;
z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z37.AssignValueColor(if max37 then GlobalColor("colorhi") else color.gray);
#z37.SetDefaultColor(Color.GRAY);
z37.SetLineWeight(line_thick);
z37.HideBubble();

plot z38 = if show_lines_wsquares and x38 then r38mid else na;
z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z38.AssignValueColor(if max38 then GlobalColor("colorhi") else color.gray);
#z38.SetDefaultColor(Color.GRAY);
z38.SetLineWeight(line_thick);
z38.HideBubble();

plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z39.AssignValueColor(if max39 then GlobalColor("colorhi") else color.gray);
#z39.SetDefaultColor(Color.GRAY);
z39.SetLineWeight(line_thick);
z39.HideBubble();


#---------------------------
# test stuff

input test1 = no;
AddChartBubble(test1, 82,
bn + "\n" +
lastbn + "\n" +
maxdata + "\n" +
r00cnt + "\n" +
r00r + "\n" +
#visual_row_width + "\n" +
Floor(r00cnt / maxdata) + "\n" +
x0
, Color.YELLOW, no);
#
#
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

i usually don't ask why, but why?
what is the goal, what are you after?
what do you think you could do with this info?
it seems you want to find different groups of various quantities of volumes, spanning different price ranges.

maybe we could work backwards from the goal to come up with formulas and methods?

with 40x variables to work with, any mod to the original will be lengthly and time consuming.
 
i usually don't ask why, but why?
what is the goal, what are you after?
what do you think you could do with this info?
it seems you want to find different groups of various quantities of volumes, spanning different price ranges.

maybe we could work backwards from the goal to come up with formulas and methods?

with 40x variables to work with, any mod to the original will be lengthly and time consuming.

Thanks for asking for clarification. My thinking was that programmatically identifying the volume profile shape would allow for using the type of profile shape as a filtering condition for signals.

Example 1: mean reversion signals could be disabled from painting while the volume profile shape corresponds with a high probability of a trend day occurring (such as a P shape).

Example 2: trend following signals could be disabled (or adjusted to trigger on more stringent criteria) if the profile shape corresponds with a high probability of a chop day (such as a D-shape profile) while at the same time mean reversion signals could be boosted.
 
Modify "Poor Man's Volume Profile" to identify and label profile shapes

@halcyonguy and some assisting members converted a pinescript study that creates a volume profile here.

I think this is interesting because if I understand correcting, the "profile" generation function in thinkscript doesn't allow for much scripting interaction, whereas this "Poor Man's Volume Profile" is not using the "profile" function and should therefore offer more possibilities.

For example, with the Poor Man's Volume Profile, wouldn't it be possible to code signals that are conditional based on the shape of the profile? I think so if the profile shapes can be defined objectively enough. It seems like that would be possible.

In the code, each line is plotted as z0 through z39 for creating 40 horizontal profile bars total. Intuitively it seems like profile shapes could just be defined by creating ranges of these bars as quadrants of the profile and taking the percentage totals of the quadrants versus each other.

For example, I tried adding this code at the end of the study:

Code:
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

I can't find any charts that will show the labels and I think the reason is probably that the definitions of the profile shapes are too simplistic and therefore not capturing real profile shapes (only ideal ones).

Anyone have any suggestions or ideas about a better way to try to mathematically define the profile shapes? Or is it too subjective to be expressed as code in a practical way?

(Complete script is provided below: )

Code:
# Poorman_volume_profile_02b

#finished by rrm411
#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#post5


#  replace max()  at 500+  that find row max #s


#Poor man's volume profile
#https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/
#1100 lines
#// © Ildar Akhmetgaleev (AkhIL)
#// See https://github.com/akhilman/vol-poorofile
#// vim: shiftwidth=2 tabstop=2
#study("Poor man's volume profile", "PMVolProf", overlay=true, max_bars_back=500)


def na = double.nan;
def bn = BarNumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

#def lastbar = !isnan(close[0]) and isnan(close[-1]);

def minb = 10;
def maxb = 500;
input block_size2 = 200;
def block_size = if block_size2 < minb then minb else if block_size2 > maxb then maxb else block_size2;
input visual_row_width = 50;
input show_peaks = yes;

AddLabel(1, "look " + block_size + " bars back", Color.YELLOW);

input show_vert_line_range_start = yes;
def first = (!IsNaN(close[-block_size]) and IsNaN(close[-(block_size + 1)]));
AddVerticalLine(show_vert_line_range_start and first, "-", Color.CYAN);


#// Calculate profile

def block_high = Highest(high, block_size);
def block_low = Lowest(low, block_size);
def highest_row_value = 0;


# data to collect
# count bars in a range
#def data = 1;
# convert volume to millions
#def data = volume/1000000;
# convert volume to 1000s
def data = volume / 1000;


# do stuff on last bar

def row_qty = 40;
def block_height = block_high - block_low;
def row_height = block_height / row_qty;

# chg first values to 1, so no divide by 0 err
def k = 1;
def r00lo = if bn == 1 then k else if lastbar then (block_low + row_height * 0) else r00lo[1];
def r00hi = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r00hi[1];
def r01lo = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r01lo[1];
def r01hi = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r01hi[1];
def r02lo = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r02lo[1];
def r02hi = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r02hi[1];
def r03lo = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r03lo[1];
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
def r04lo = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r04lo[1];
def r04hi = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r04hi[1];
def r05lo = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r05lo[1];
def r05hi = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r05hi[1];
def r06lo = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r06lo[1];
def r06hi = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r06hi[1];
def r07lo = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r07lo[1];
def r07hi = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r07hi[1];
def r08lo = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r08lo[1];
def r08hi = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r08hi[1];
def r09lo = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r09lo[1];
def r09hi = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r09hi[1];
def r10lo = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r10lo[1];
def r10hi = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r10hi[1];
def r11lo = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r11lo[1];
def r11hi = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r11hi[1];
def r12lo = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r12lo[1];
def r12hi = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r12hi[1];
def r13lo = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r13lo[1];
def r13hi = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r13hi[1];
def r14lo = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r14lo[1];
def r14hi = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r14hi[1];
def r15lo = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r15lo[1];
def r15hi = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r15hi[1];
def r16lo = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r16lo[1];
def r16hi = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r16hi[1];
def r17lo = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r17lo[1];
def r17hi = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r17hi[1];
def r18lo = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r18lo[1];
def r18hi = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r18hi[1];
def r19lo = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r19lo[1];
def r19hi = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r19hi[1];
def r20lo = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r20lo[1];
def r20hi = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r20hi[1];
def r21lo = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r21lo[1];
def r21hi = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r21hi[1];
def r22lo = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r22lo[1];
def r22hi = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r22hi[1];
def r23lo = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r23lo[1];
def r23hi = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r23hi[1];
def r24lo = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r24lo[1];
def r24hi = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r24hi[1];
def r25lo = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r25lo[1];
def r25hi = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r25hi[1];
def r26lo = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r26lo[1];
def r26hi = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r26hi[1];
def r27lo = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r27lo[1];
def r27hi = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r27hi[1];
def r28lo = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r28lo[1];
def r28hi = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r28hi[1];
def r29lo = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r29lo[1];
def r29hi = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r29hi[1];
def r30lo = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r30lo[1];
def r30hi = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r30hi[1];
def r31lo = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r31lo[1];
def r31hi = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r31hi[1];
def r32lo = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r32lo[1];
def r32hi = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r32hi[1];
def r33lo = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r33lo[1];
def r33hi = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r33hi[1];
def r34lo = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r34lo[1];
def r34hi = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r34hi[1];
def r35lo = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r35lo[1];
def r35hi = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r35hi[1];
def r36lo = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r36lo[1];
def r36hi = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r36hi[1];
def r37lo = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r37lo[1];
def r37hi = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r37hi[1];
def r38lo = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r38lo[1];
def r38hi = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r38hi[1];
def r39lo = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r39lo[1];
def r39hi = if bn == 1 then k else if lastbar then (block_low + row_height * 40) else r39hi[1];



def r00mid = (r00hi + r00lo) / 2;
def r01mid = (r01hi + r01lo) / 2;
def r02mid = (r02hi + r02lo) / 2;
def r03mid = (r03hi + r03lo) / 2;
def r04mid = (r04hi + r04lo) / 2;
def r05mid = (r05hi + r05lo) / 2;
def r06mid = (r06hi + r06lo) / 2;
def r07mid = (r07hi + r07lo) / 2;
def r08mid = (r08hi + r08lo) / 2;
def r09mid = (r09hi + r09lo) / 2;
def r10mid = (r10hi + r10lo) / 2;
def r11mid = (r11hi + r11lo) / 2;
def r12mid = (r12hi + r12lo) / 2;
def r13mid = (r13hi + r13lo) / 2;
def r14mid = (r14hi + r14lo) / 2;
def r15mid = (r15hi + r15lo) / 2;
def r16mid = (r16hi + r16lo) / 2;
def r17mid = (r17hi + r17lo) / 2;
def r18mid = (r18hi + r18lo) / 2;
def r19mid = (r19hi + r19lo) / 2;
def r20mid = (r20hi + r20lo) / 2;
def r21mid = (r21hi + r21lo) / 2;
def r22mid = (r22hi + r22lo) / 2;
def r23mid = (r23hi + r23lo) / 2;
def r24mid = (r24hi + r24lo) / 2;
def r25mid = (r25hi + r25lo) / 2;
def r26mid = (r26hi + r26lo) / 2;
def r27mid = (r27hi + r27lo) / 2;
def r28mid = (r28hi + r28lo) / 2;
def r29mid = (r29hi + r29lo) / 2;
def r30mid = (r30hi + r30lo) / 2;
def r31mid = (r31hi + r31lo) / 2;
def r32mid = (r32hi + r32lo) / 2;
def r33mid = (r33hi + r33lo) / 2;
def r34mid = (r34hi + r34lo) / 2;
def r35mid = (r35hi + r35lo) / 2;
def r36mid = (r36hi + r36lo) / 2;
def r37mid = (r37hi + r37lo) / 2;
def r38mid = (r38hi + r38lo) / 2;
def r39mid = (r39hi + r39lo) / 2;


# on last bar,
# look back at prev bars, to see if part of them were within a price row range,
# if so, then add the data from that bar , volume

def m = 1;
def r00cnt = if bn == 1 then m else if lastbar then fold i0 = 0 to block_size
 with p0
 do p0 + (if GetValue(low, i0) < r00hi and GetValue(high, i0) > r00lo then GetValue(data, i0) else 0)
 else r00cnt[1];

def r01cnt = if bn == 1 then m else if lastbar then fold i1 = 0 to block_size
 with p1
 do p1 + (if GetValue(low, i1) < r01hi and GetValue(high, i1) > r01lo then GetValue(data, i1) else 0)
 else r01cnt[1];

def r02cnt = if bn == 1 then m else if lastbar then fold i2 = 0 to block_size
 with p2
 do p2 + (if GetValue(low, i2) < r02hi and GetValue(high, i2) > r02lo then GetValue(data, i2) else 0)
 else r02cnt[1];

def r03cnt = if bn == 1 then m else if lastbar then fold i3 = 0 to block_size
 with p3
 do p3 + (if GetValue(low, i3) < r03hi and GetValue(high, i3) > r03lo then GetValue(data, i3) else 0)
 else r03cnt[1];

def r04cnt = if bn == 1 then m else if lastbar then fold i4 = 0 to block_size
 with p4
 do p4 + (if GetValue(low, i4) < r04hi and GetValue(high, i4) > r04lo then GetValue(data, i4) else 0)
 else r04cnt[1];

def r05cnt = if bn == 1 then m else if lastbar then fold i5 = 0 to block_size
 with p5
 do p5 + (if GetValue(low, i5) < r05hi and GetValue(high, i5) > r05lo then GetValue(data, i5) else 0)
 else r05cnt[1];

def r06cnt = if bn == 1 then m else if lastbar then fold i6 = 0 to block_size
 with p6
 do p6 + (if GetValue(low, i6) < r06hi and GetValue(high, i6) > r06lo then GetValue(data, i6) else 0)
 else r06cnt[1];

def r07cnt = if bn == 1 then m else if lastbar then fold i7 = 0 to block_size
 with p7
 do p7 + (if GetValue(low, i7) < r07hi and GetValue(high, i7) > r07lo then GetValue(data, i7) else 0)
 else r07cnt[1];

def r08cnt = if bn == 1 then m else if lastbar then fold i8 = 0 to block_size
 with p8
 do p8 + (if GetValue(low, i8) < r08hi and GetValue(high, i8) > r08lo then GetValue(data, i8) else 0)
 else r08cnt[1];

def r09cnt = if bn == 1 then m else if lastbar then fold i9 = 0 to block_size
 with p9
 do p9 + (if GetValue(low, i9) < r09hi and GetValue(high, i9) > r09lo then GetValue(data, i9) else 0)
 else r09cnt[1];

def r10cnt = if bn == 1 then m else if lastbar then fold i10 = 0 to block_size
 with p10
 do p10 + (if GetValue(low, i10) < r10hi and GetValue(high, i10) > r10lo then GetValue(data, i10) else 0)
 else r10cnt[1];

def r11cnt = if bn == 1 then m else if lastbar then fold i11 = 0 to block_size
 with p11
 do p11 + (if GetValue(low, i11) < r11hi and GetValue(high, i11) > r11lo then GetValue(data, i11) else 0)
 else r11cnt[1];

def r12cnt = if bn == 1 then m else if lastbar then fold i12 = 0 to block_size
 with p12
 do p12 + (if GetValue(low, i12) < r12hi and GetValue(high, i12) > r12lo then GetValue(data, i12) else 0)
 else r12cnt[1];

def r13cnt = if bn == 1 then m else if lastbar then fold i13 = 0 to block_size
 with p13
 do p13 + (if GetValue(low, i13) < r13hi and GetValue(high, i13) > r13lo then GetValue(data, i13) else 0)
 else r13cnt[1];

def r14cnt = if bn == 1 then m else if lastbar then fold i14 = 0 to block_size
 with p14
 do p14 + (if GetValue(low, i14) < r14hi and GetValue(high, i14) > r14lo then GetValue(data, i14) else 0)
 else r14cnt[1];

def r15cnt = if bn == 1 then m else if lastbar then fold i15 = 0 to block_size
 with p15
 do p15 + (if GetValue(low, i15) < r15hi and GetValue(high, i15) > r15lo then GetValue(data, i15) else 0)
 else r15cnt[1];

def r16cnt = if bn == 1 then m else if lastbar then fold i16 = 0 to block_size
 with p16
 do p16 + (if GetValue(low, i16) < r16hi and GetValue(high, i16) > r16lo then GetValue(data, i16) else 0)
 else r16cnt[1];

def r17cnt = if bn == 1 then m else if lastbar then fold i17 = 0 to block_size
 with p17
 do p17 + (if GetValue(low, i17) < r17hi and GetValue(high, i17) > r17lo then GetValue(data, i17) else 0)
 else r17cnt[1];

def r18cnt = if bn == 1 then m else if lastbar then fold i18 = 0 to block_size
 with p18
 do p18 + (if GetValue(low, i18) < r18hi and GetValue(high, i18) > r18lo then GetValue(data, i18) else 0)
 else r18cnt[1];

def r19cnt = if bn == 1 then m else if lastbar then fold i19 = 0 to block_size
 with p19
 do p19 + (if GetValue(low, i19) < r19hi and GetValue(high, i19) > r19lo then GetValue(data, i19) else 0)
 else r19cnt[1];

def r20cnt = if bn == 1 then m else if lastbar then fold i20 = 0 to block_size
 with p20
 do p20 + (if GetValue(low, i20) < r20hi and GetValue(high, i20) > r20lo then GetValue(data, i20) else 0)
 else r20cnt[1];

def r21cnt = if bn == 1 then m else if lastbar then fold i21 = 0 to block_size
 with p21
 do p21 + (if GetValue(low, i21) < r21hi and GetValue(high, i21) > r21lo then GetValue(data, i21) else 0)
 else r21cnt[1];

def r22cnt = if bn == 1 then m else if lastbar then fold i22 = 0 to block_size
 with p22
 do p22 + (if GetValue(low, i22) < r22hi and GetValue(high, i22) > r22lo then GetValue(data, i22) else 0)
 else r22cnt[1];

def r23cnt = if bn == 1 then m else if lastbar then fold i23 = 0 to block_size
 with p23
 do p23 + (if GetValue(low, i23) < r23hi and GetValue(high, i23) > r23lo then GetValue(data, i23) else 0)
 else r23cnt[1];

def r24cnt = if bn == 1 then m else if lastbar then fold i24 = 0 to block_size
 with p24
 do p24 + (if GetValue(low, i24) < r24hi and GetValue(high, i24) > r24lo then GetValue(data, i24) else 0)
 else r24cnt[1];

def r25cnt = if bn == 1 then m else if lastbar then fold i25 = 0 to block_size
 with p25
 do p25 + (if GetValue(low, i25) < r25hi and GetValue(high, i25) > r25lo then GetValue(data, i25) else 0)
 else r25cnt[1];

def r26cnt = if bn == 1 then m else if lastbar then fold i26 = 0 to block_size
 with p26
 do p26 + (if GetValue(low, i26) < r26hi and GetValue(high, i26) > r26lo then GetValue(data, i26) else 0)
 else r26cnt[1];

def r27cnt = if bn == 1 then m else if lastbar then fold i27 = 0 to block_size
 with p27
 do p27 + (if GetValue(low, i27) < r27hi and GetValue(high, i27) > r27lo then GetValue(data, i27) else 0)
 else r27cnt[1];

def r28cnt = if bn == 1 then m else if lastbar then fold i28 = 0 to block_size
 with p28
 do p28 + (if GetValue(low, i28) < r28hi and GetValue(high, i28) > r28lo then GetValue(data, i28) else 0)
 else r28cnt[1];

def r29cnt = if bn == 1 then m else if lastbar then fold i29 = 0 to block_size
 with p29
 do p29 + (if GetValue(low, i29) < r29hi and GetValue(high, i29) > r29lo then GetValue(data, i29) else 0)
 else r29cnt[1];

def r30cnt = if bn == 1 then m else if lastbar then fold i30 = 0 to block_size
 with p30
 do p30 + (if GetValue(low, i30) < r30hi and GetValue(high, i30) > r30lo then GetValue(data, i30) else 0)
 else r30cnt[1];

def r31cnt = if bn == 1 then m else if lastbar then fold i31 = 0 to block_size
 with p31
 do p31 + (if GetValue(low, i31) < r31hi and GetValue(high, i31) > r31lo then GetValue(data, i31) else 0)
 else r31cnt[1];

def r32cnt = if bn == 1 then m else if lastbar then fold i32 = 0 to block_size
 with p32
 do p32 + (if GetValue(low, i32) < r32hi and GetValue(high, i32) > r32lo then GetValue(data, i32) else 0)
 else r32cnt[1];

def r33cnt = if bn == 1 then m else if lastbar then fold i33 = 0 to block_size
 with p33
 do p33 + (if GetValue(low, i33) < r33hi and GetValue(high, i33) > r33lo then GetValue(data, i33) else 0)
 else r33cnt[1];

def r34cnt = if bn == 1 then m else if lastbar then fold i34 = 0 to block_size
 with p34
 do p34 + (if GetValue(low, i34) < r34hi and GetValue(high, i34) > r34lo then GetValue(data, i34) else 0)
 else r34cnt[1];

def r35cnt = if bn == 1 then m else if lastbar then fold i35 = 0 to block_size
 with p35
 do p35 + (if GetValue(low, i35) < r35hi and GetValue(high, i35) > r35lo then GetValue(data, i35) else 0)
 else r35cnt[1];

def r36cnt = if bn == 1 then m else if lastbar then fold i36 = 0 to block_size
 with p36
 do p36 + (if GetValue(low, i36) < r36hi and GetValue(high, i36) > r36lo then GetValue(data, i36) else 0)
 else r36cnt[1];

def r37cnt = if bn == 1 then m else if lastbar then fold i37 = 0 to block_size
 with p37
 do p37 + (if GetValue(low, i37) < r37hi and GetValue(high, i37) > r37lo then GetValue(data, i37) else 0)
 else r37cnt[1];

def r38cnt = if bn == 1 then m else if lastbar then fold i38 = 0 to block_size
 with p38
 do p38 + (if GetValue(low, i38) < r38hi and GetValue(high, i38) > r38lo then GetValue(data, i38) else 0)
 else r38cnt[1];

def r39cnt = if bn == 1 then m else if lastbar then fold i39 = 0 to block_size
 with p39
 do p39 + (if GetValue(low, i39) < r39hi and GetValue(high, i39) > r39lo then GetValue(data, i39) else 0)
 else r39cnt[1];



# find max data sum
def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# calc ratio of cnt to highest cnt , a bar cnt , for the horz length of each row
def r00r = Floor(visual_row_width * r00cnt / maxdata);
def r01r = Floor(visual_row_width * r01cnt / maxdata);
def r02r = Floor(visual_row_width * r02cnt / maxdata);
def r03r = Floor(visual_row_width * r03cnt / maxdata);
def r04r = Floor(visual_row_width * r04cnt / maxdata);
def r05r = Floor(visual_row_width * r05cnt / maxdata);
def r06r = Floor(visual_row_width * r06cnt / maxdata);
def r07r = Floor(visual_row_width * r07cnt / maxdata);
def r08r = Floor(visual_row_width * r08cnt / maxdata);
def r09r = Floor(visual_row_width * r09cnt / maxdata);
def r10r = Floor(visual_row_width * r10cnt / maxdata);
def r11r = Floor(visual_row_width * r11cnt / maxdata);
def r12r = Floor(visual_row_width * r12cnt / maxdata);
def r13r = Floor(visual_row_width * r13cnt / maxdata);
def r14r = Floor(visual_row_width * r14cnt / maxdata);
def r15r = Floor(visual_row_width * r15cnt / maxdata);
def r16r = Floor(visual_row_width * r16cnt / maxdata);
def r17r = Floor(visual_row_width * r17cnt / maxdata);
def r18r = Floor(visual_row_width * r18cnt / maxdata);
def r19r = Floor(visual_row_width * r19cnt / maxdata);
def r20r = Floor(visual_row_width * r20cnt / maxdata);
def r21r = Floor(visual_row_width * r21cnt / maxdata);
def r22r = Floor(visual_row_width * r22cnt / maxdata);
def r23r = Floor(visual_row_width * r23cnt / maxdata);
def r24r = Floor(visual_row_width * r24cnt / maxdata);
def r25r = Floor(visual_row_width * r25cnt / maxdata);
def r26r = Floor(visual_row_width * r26cnt / maxdata);
def r27r = Floor(visual_row_width * r27cnt / maxdata);
def r28r = Floor(visual_row_width * r28cnt / maxdata);
def r29r = Floor(visual_row_width * r29cnt / maxdata);
def r30r = Floor(visual_row_width * r30cnt / maxdata);
def r31r = Floor(visual_row_width * r31cnt / maxdata);
def r32r = Floor(visual_row_width * r32cnt / maxdata);
def r33r = Floor(visual_row_width * r33cnt / maxdata);
def r34r = Floor(visual_row_width * r34cnt / maxdata);
def r35r = Floor(visual_row_width * r35cnt / maxdata);
def r36r = Floor(visual_row_width * r36cnt / maxdata);
def r37r = Floor(visual_row_width * r37cnt / maxdata);
def r38r = Floor(visual_row_width * r38cnt / maxdata);
def r39r = Floor(visual_row_width * r39cnt / maxdata);



#// Draw profile


# draw rows on bars after the last bar
# mark bars after lastbar as true, if the ratio cnt of bars .....
def x0 = (bn > lastbn and bn <= (lastbn + r00r));
def x1 = (bn > lastbn and bn <= (lastbn + r01r));
def x2 = (bn > lastbn and bn <= (lastbn + r02r));
def x3 = (bn > lastbn and bn <= (lastbn + r03r));
def x4 = (bn > lastbn and bn <= (lastbn + r04r));
def x5 = (bn > lastbn and bn <= (lastbn + r05r));
def x6 = (bn > lastbn and bn <= (lastbn + r06r));
def x7 = (bn > lastbn and bn <= (lastbn + r07r));
def x8 = (bn > lastbn and bn <= (lastbn + r08r));
def x9 = (bn > lastbn and bn <= (lastbn + r09r));
def x10 = (bn > lastbn and bn <= (lastbn + r10r));
def x11 = (bn > lastbn and bn <= (lastbn + r11r));
def x12 = (bn > lastbn and bn <= (lastbn + r12r));
def x13 = (bn > lastbn and bn <= (lastbn + r13r));
def x14 = (bn > lastbn and bn <= (lastbn + r14r));
def x15 = (bn > lastbn and bn <= (lastbn + r15r));
def x16 = (bn > lastbn and bn <= (lastbn + r16r));
def x17 = (bn > lastbn and bn <= (lastbn + r17r));
def x18 = (bn > lastbn and bn <= (lastbn + r18r));
def x19 = (bn > lastbn and bn <= (lastbn + r19r));
def x20 = (bn > lastbn and bn <= (lastbn + r20r));
def x21 = (bn > lastbn and bn <= (lastbn + r21r));
def x22 = (bn > lastbn and bn <= (lastbn + r22r));
def x23 = (bn > lastbn and bn <= (lastbn + r23r));
def x24 = (bn > lastbn and bn <= (lastbn + r24r));
def x25 = (bn > lastbn and bn <= (lastbn + r25r));
def x26 = (bn > lastbn and bn <= (lastbn + r26r));
def x27 = (bn > lastbn and bn <= (lastbn + r27r));
def x28 = (bn > lastbn and bn <= (lastbn + r28r));
def x29 = (bn > lastbn and bn <= (lastbn + r29r));
def x30 = (bn > lastbn and bn <= (lastbn + r30r));
def x31 = (bn > lastbn and bn <= (lastbn + r31r));
def x32 = (bn > lastbn and bn <= (lastbn + r32r));
def x33 = (bn > lastbn and bn <= (lastbn + r33r));
def x34 = (bn > lastbn and bn <= (lastbn + r34r));
def x35 = (bn > lastbn and bn <= (lastbn + r35r));
def x36 = (bn > lastbn and bn <= (lastbn + r36r));
def x37 = (bn > lastbn and bn <= (lastbn + r37r));
def x38 = (bn > lastbn and bn <= (lastbn + r38r));
def x39 = (bn > lastbn and bn <= (lastbn + r39r));


#---------------------------

# orig codes
# find max value , +-5 values , compare each row value to 10 other values
# if current is the max, then orange
#   if first , compare to 5 future
#   later , compare to 5 before and 5 after
#   last , compare to 5 prev

# ref - orig code
#if row0_value >= row1_value and row0_value >= row2_value and row0_value >= row3_value and row0_value >= row4_value and row0_value >= row5_value
#        row0_is_peak := true

#if row10_value >= row5_value and row10_value >= row6_value and row10_value >= row7_value and row10_value >= row8_value and row10_value >= row9_value and row10_value >= row11_value and row10_value >= row12_value and row10_value >= row13_value and row10_value >= row14_value and row10_value >= row15_value
#        row10_is_peak := true

#if row20_value >= row15_value and row20_value >= row16_value and row20_value >= row17_value and row20_value >= row18_value and row20_value >= row19_value and row20_value >= row21_value and row20_value >= row22_value and row20_value >= row23_value and row20_value >= row24_value and row20_value >= row25_value
#        row20_is_peak := true

#if row39_value >= row34_value and row39_value >= row35_value and row39_value >= row36_value and row39_value >= row37_value and row39_value >= row38_value
#        row39_is_peak := true

#------------------

# copied from line 394
#def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# compare current row to prev 5 rows and future 5 rows

def max00 = if r00cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, r05cnt)))))) then 1 else 0;
def max01 = if r01cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, r06cnt))))))) then 1 else 0;
def max02 = if r02cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, r07cnt)))))))) then 1 else 0;
def max03 = if r03cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, r08cnt))))))))) then 1 else 0;
def max04 = if r04cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, r09cnt)))))))))) then 1 else 0;

def max05 = if r05cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, r10cnt))))))))))) then 1 else 0;
def max06 = if r06cnt == (Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, r11cnt))))))))))) then 1 else 0;
def max07 = if r07cnt == (Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, r12cnt))))))))))) then 1 else 0;
def max08 = if r08cnt == (Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, r13cnt))))))))))) then 1 else 0;
def max09 = if r09cnt == (Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, r14cnt))))))))))) then 1 else 0;
def max10 = if r10cnt == (Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, r15cnt))))))))))) then 1 else 0;
def max11 = if r11cnt == (Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, r16cnt))))))))))) then 1 else 0;
def max12 = if r12cnt == (Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, r17cnt))))))))))) then 1 else 0;

def max13 = if r13cnt == (Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, r18cnt))))))))))) then 1 else 0;
def max14 = if r14cnt == (Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, r19cnt))))))))))) then 1 else 0;
def max15 = if r15cnt == (Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, r20cnt))))))))))) then 1 else 0;
def max16 = if r16cnt == (Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, r21cnt))))))))))) then 1 else 0;
def max17 = if r17cnt == (Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, r22cnt))))))))))) then 1 else 0;
def max18 = if r18cnt == (Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, r23cnt))))))))))) then 1 else 0;
def max19 = if r19cnt == (Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, r23cnt))))))))))) then 1 else 0;

def max20 = if r20cnt == (Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, r25cnt))))))))))) then 1 else 0;
def max21 = if r21cnt == (Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, r26cnt))))))))))) then 1 else 0;
def max22 = if r22cnt == (Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, r27cnt))))))))))) then 1 else 0;
def max23 = if r23cnt == (Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, r23cnt))))))))))) then 1 else 0;
def max24 = if r24cnt == (Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, r29cnt))))))))))) then 1 else 0;
def max25 = if r25cnt == (Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, r30cnt))))))))))) then 1 else 0;
def max26 = if r26cnt == (Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, r31cnt))))))))))) then 1 else 0;
def max27 = if r27cnt == (Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, r32cnt))))))))))) then 1 else 0;
def max28 = if r28cnt == (Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, r33cnt))))))))))) then 1 else 0;
def max29 = if r29cnt == (Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, r34cnt))))))))))) then 1 else 0;

def max30 = if r30cnt == (Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, r35cnt))))))))))) then 1 else 0;
def max31 = if r31cnt == (Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, r36cnt))))))))))) then 1 else 0;
def max32 = if r32cnt == (Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, r37cnt))))))))))) then 1 else 0;
def max33 = if r33cnt == (Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, r38cnt))))))))))) then 1 else 0;
def max34 = if r34cnt == (Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))))) then 1 else 0;

def max35 = if r35cnt == (Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))) then 1 else 0;
def max36 = if r36cnt == (Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))) then 1 else 0;
def max37 = if r37cnt == (Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))) then 1 else 0;
def max38 = if r38cnt == (Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))) then 1 else 0;
def max39 = if r39cnt == (Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))) then 1 else 0;

#---------------------------


#  replace max()  at 500+  that find row max #s
# hmm  diff vars , so cant just use highest()...

# def mx00 =


#-----------------------------

defineglobalcolor("colorhi", color.orange);

input line_thick = 2;
input show_lines_wsquares = yes;

plot z0 = if show_lines_wsquares and x0 then r00mid else na;
z0.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max00 then GlobalColor("colorhi") else color.gray);
#z0.SetDefaultColor(Color.GRAY);
z0.SetLineWeight(line_thick);
z0.HideBubble();

plot z1 = if show_lines_wsquares and x1 then r01mid else na;
z1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z1.AssignValueColor(if max01 then GlobalColor("colorhi") else color.gray);
#z1.SetDefaultColor(Color.GRAY);
z1.SetLineWeight(line_thick);
z1.HideBubble();

plot z2 = if show_lines_wsquares and x2 then r02mid else na;
z2.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z2.AssignValueColor(if max02 then GlobalColor("colorhi") else color.gray);
#z2.SetDefaultColor(Color.GRAY);
z2.SetLineWeight(line_thick);
z2.HideBubble();

plot z3 = if show_lines_wsquares and x3 then r03mid else na;
z3.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z3.AssignValueColor(if max03 then GlobalColor("colorhi") else color.gray);
#z3.SetDefaultColor(Color.GRAY);
z3.SetLineWeight(line_thick);
z3.HideBubble();

plot z4 = if show_lines_wsquares and x4 then r04mid else na;
z4.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z4.AssignValueColor(if max04 then GlobalColor("colorhi") else color.gray);
z4.SetDefaultColor(Color.GRAY);
z4.SetLineWeight(line_thick);
z4.HideBubble();

plot z5 = if show_lines_wsquares and x5 then r05mid else na;
z5.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z5.AssignValueColor(if max05 then GlobalColor("colorhi") else color.gray);
#z5.SetDefaultColor(Color.GRAY);
z5.SetLineWeight(line_thick);
z5.HideBubble();

plot z6 = if show_lines_wsquares and x6 then r06mid else na;
z6.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z6.AssignValueColor(if max06 then GlobalColor("colorhi") else color.gray);
z6.SetDefaultColor(Color.GRAY);
z6.SetLineWeight(line_thick);
z6.HideBubble();

plot z7 = if show_lines_wsquares and x7 then r07mid else na;
z7.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z7.AssignValueColor(if max07 then GlobalColor("colorhi") else color.gray);
#z7.SetDefaultColor(Color.GRAY);
z7.SetLineWeight(line_thick);
z7.HideBubble();

plot z8 = if show_lines_wsquares and x8 then r08mid else na;
z8.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z8.AssignValueColor(if max08 then GlobalColor("colorhi") else color.gray);
#z8.SetDefaultColor(Color.GRAY);
z8.SetLineWeight(line_thick);
z8.HideBubble();

plot z9 = if show_lines_wsquares and x9 then r09mid else na;
z9.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z9.AssignValueColor(if max09 then GlobalColor("colorhi") else color.gray);
#z9.SetDefaultColor(Color.GRAY);
z9.SetLineWeight(line_thick);
z9.HideBubble();

plot z10 = if show_lines_wsquares and x10 then r10mid else na;
z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z10.AssignValueColor(if max10 then GlobalColor("colorhi") else color.gray);
#z10.SetDefaultColor(Color.GRAY);
z10.SetLineWeight(line_thick);
z10.HideBubble();

plot z11 = if show_lines_wsquares and x11 then r11mid else na;
z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z11.AssignValueColor(if max11 then GlobalColor("colorhi") else color.gray);
#z11.SetDefaultColor(Color.GRAY);
z11.SetLineWeight(line_thick);
z11.HideBubble();

plot z12 = if show_lines_wsquares and x12 then r12mid else na;
z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z12.AssignValueColor(if max12 then GlobalColor("colorhi") else color.gray);
#z12.SetDefaultColor(Color.GRAY);
z12.SetLineWeight(line_thick);
z12.HideBubble();

plot z13 = if show_lines_wsquares and x13 then r13mid else na;
z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z13.AssignValueColor(if max13 then GlobalColor("colorhi") else color.gray);
z13.SetDefaultColor(Color.GRAY);
z13.SetLineWeight(line_thick);
z13.HideBubble();

plot z14 = if show_lines_wsquares and x14 then r14mid else na;
z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z14.AssignValueColor(if max14 then GlobalColor("colorhi") else color.gray);
#z14.SetDefaultColor(Color.GRAY);
z14.SetLineWeight(line_thick);
z14.HideBubble();

plot z15 = if show_lines_wsquares and x15 then r15mid else na;
z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z15.AssignValueColor(if max15 then GlobalColor("colorhi") else color.gray);
#z15.SetDefaultColor(Color.GRAY);
z15.SetLineWeight(line_thick);
z15.HideBubble();

plot z16 = if show_lines_wsquares and x16 then r16mid else na;
z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max16 then GlobalColor("colorhi") else color.gray);
z16.SetDefaultColor(Color.GRAY);
z16.SetLineWeight(line_thick);
z16.HideBubble();

plot z17 = if show_lines_wsquares and x17 then r17mid else na;
z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max17 then GlobalColor("colorhi") else color.gray);
z17.SetDefaultColor(Color.GRAY);
z17.SetLineWeight(line_thick);
z17.HideBubble();

plot z18 = if show_lines_wsquares and x18 then r18mid else na;
z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z18.AssignValueColor(if max18 then GlobalColor("colorhi") else color.gray);
z18.SetDefaultColor(Color.GRAY);
z18.SetLineWeight(line_thick);
z18.HideBubble();

plot z19 = if show_lines_wsquares and x19 then r19mid else na;
z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z19.AssignValueColor(if max19 then GlobalColor("colorhi") else color.gray);
z19.SetDefaultColor(Color.GRAY);
z19.SetLineWeight(line_thick);
z19.HideBubble();

plot z20 = if show_lines_wsquares and x20 then r20mid else na;
z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z20.AssignValueColor(if max20 then GlobalColor("colorhi") else color.gray);
z20.SetDefaultColor(Color.GRAY);
z20.SetLineWeight(line_thick);
z20.HideBubble();

plot z21 = if show_lines_wsquares and x21 then r21mid else na;
z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z21.AssignValueColor(if max21 then GlobalColor("colorhi") else color.gray);
z21.SetDefaultColor(Color.GRAY);
z21.SetLineWeight(line_thick);
z21.HideBubble();

plot z22 = if show_lines_wsquares and x22 then r22mid else na;
z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z22.AssignValueColor(if max22 then GlobalColor("colorhi") else color.gray);
z22.SetDefaultColor(Color.GRAY);
z22.SetLineWeight(line_thick);
z22.HideBubble();

plot z23 = if show_lines_wsquares and x23 then r23mid else na;
z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z23.AssignValueColor(if max23 then GlobalColor("colorhi") else color.gray);
z23.SetDefaultColor(Color.GRAY);
z23.SetLineWeight(line_thick);
z23.HideBubble();

plot z24 = if show_lines_wsquares and x24 then r24mid else na;
z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z24.AssignValueColor(if max24 then GlobalColor("colorhi") else color.gray);
z24.SetDefaultColor(Color.GRAY);
z24.SetLineWeight(line_thick);
z24.HideBubble();

plot z25 = if show_lines_wsquares and x25 then r25mid else na;
z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z25.AssignValueColor(if max25 then GlobalColor("colorhi") else color.gray);
z25.SetDefaultColor(Color.GRAY);
z25.SetLineWeight(line_thick);
z25.HideBubble();

plot z26 = if show_lines_wsquares and x26 then r26mid else na;
z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z26.AssignValueColor(if max26 then GlobalColor("colorhi") else color.gray);
z26.SetDefaultColor(Color.GRAY);
z26.SetLineWeight(line_thick);
z26.HideBubble();

plot z27 = if show_lines_wsquares and x27 then r27mid else na;
z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z27.AssignValueColor(if max27 then GlobalColor("colorhi") else color.gray);
z27.SetDefaultColor(Color.GRAY);
z27.SetLineWeight(line_thick);
z27.HideBubble();

plot z28 = if show_lines_wsquares and x28 then r28mid else na;
z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z28.AssignValueColor(if max28 then GlobalColor("colorhi") else color.gray);
z28.SetDefaultColor(Color.GRAY);
z28.SetLineWeight(line_thick);
z28.HideBubble();

plot z29 = if show_lines_wsquares and x29 then r29mid else na;
z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z29.AssignValueColor(if max29 then GlobalColor("colorhi") else color.gray);
z29.SetDefaultColor(Color.GRAY);
z29.SetLineWeight(line_thick);
z29.HideBubble();

plot z30 = if show_lines_wsquares and x30 then r30mid else na;
z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z30.AssignValueColor(if max30 then GlobalColor("colorhi") else color.gray);
z30.SetDefaultColor(Color.GRAY);
z30.SetLineWeight(line_thick);
z30.HideBubble();

plot z31 = if show_lines_wsquares and x31 then r31mid else na;
z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z31.AssignValueColor(if max31 then GlobalColor("colorhi") else color.gray);
z31.SetDefaultColor(Color.GRAY);
z31.SetLineWeight(line_thick);
z31.HideBubble();

plot z32 = if show_lines_wsquares and x32 then r32mid else na;
z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z32.AssignValueColor(if max32 then GlobalColor("colorhi") else color.gray);
z32.SetDefaultColor(Color.GRAY);
z32.SetLineWeight(line_thick);
z32.HideBubble();

plot z33 = if show_lines_wsquares and x33 then r33mid else na;
z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z33.AssignValueColor(if max33 then GlobalColor("colorhi") else color.gray);
z33.SetDefaultColor(Color.GRAY);
z33.SetLineWeight(line_thick);
z33.HideBubble();

plot z34 = if show_lines_wsquares and x34 then r34mid else na;
z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z34.AssignValueColor(if max34 then GlobalColor("colorhi") else color.gray);
z34.SetDefaultColor(Color.GRAY);
z34.SetLineWeight(line_thick);
z34.HideBubble();

plot z35 = if show_lines_wsquares and x35 then r35mid else na;
z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z35.AssignValueColor(if max35 then GlobalColor("colorhi") else color.gray);
z35.SetDefaultColor(Color.GRAY);
z35.SetLineWeight(line_thick);
z35.HideBubble();

plot z36 = if show_lines_wsquares and x36 then r36mid else na;
z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z36.AssignValueColor(if max36 then GlobalColor("colorhi") else color.gray);
z36.SetDefaultColor(Color.GRAY);
z36.SetLineWeight(line_thick);
z36.HideBubble();

plot z37 = if show_lines_wsquares and x37 then r37mid else na;
z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z37.AssignValueColor(if max37 then GlobalColor("colorhi") else color.gray);
#z37.SetDefaultColor(Color.GRAY);
z37.SetLineWeight(line_thick);
z37.HideBubble();

plot z38 = if show_lines_wsquares and x38 then r38mid else na;
z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z38.AssignValueColor(if max38 then GlobalColor("colorhi") else color.gray);
#z38.SetDefaultColor(Color.GRAY);
z38.SetLineWeight(line_thick);
z38.HideBubble();

plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z39.AssignValueColor(if max39 then GlobalColor("colorhi") else color.gray);
#z39.SetDefaultColor(Color.GRAY);
z39.SetLineWeight(line_thick);
z39.HideBubble();


#---------------------------
# test stuff

input test1 = no;
AddChartBubble(test1, 82,
bn + "\n" +
lastbn + "\n" +
maxdata + "\n" +
r00cnt + "\n" +
r00r + "\n" +
#visual_row_width + "\n" +
Floor(r00cnt / maxdata) + "\n" +
x0
, Color.YELLOW, no);
#
#
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

here are some thoughts to get started

determine if volume profile resembers a shape, like letter P

40 rows
make 8 sub groups of 5 rows

r00r , is a horz % of longest row
use r00r instead of z0
find max and min of ea group
then compare the min n max to some #s

q1max = max(r00r, max(r01r, max(r02r, max(r03r,r04r)))));
q1min = min(r00r, min(r01r, min(r02r, min(r03r,r04r)))));

add 7 more sets of formulas, 2 - 8


come up with pattern formulas

P pattern
def pat_p = if lastbar
and q1max < 40
and q2max < 70 and q2min > 40
and q3max > 80
and q4max > 80
and q5max < 70 and q5min > 40
and q6max < 40
and q7max < 20
and q8max < 20
then 1 else 0;
 
here are some thoughts to get started

determine if volume profile resembers a shape, like letter P

40 rows
make 8 sub groups of 5 rows

r00r , is a horz % of longest row
use r00r instead of z0
find max and min of ea group
then compare the min n max to some #s

q1max = max(r00r, max(r01r, max(r02r, max(r03r,r04r)))));
q1min = min(r00r, min(r01r, min(r02r, min(r03r,r04r)))));

add 7 more sets of formulas, 2 - 8


come up with pattern formulas

P pattern
def pat_p = if lastbar
and q1max < 40
and q2max < 70 and q2min > 40
and q3max > 80
and q4max > 80
and q5max < 70 and q5min > 40
and q6max < 40
and q7max < 20
and q8max < 20
then 1 else 0;

Thank you. I just had some interesting thoughts about it this morning as well. There might be a way to simplify the problem based on how the script already identifies the HVNs as orange bars:

Capture.PNG


What I was thinking is that one could just identify which zone the HVN(s) are in and specify that the primary HVN(s) have to be x% larger than the minor ones in cases of an imbalanced profile shape like the b shape above. For a B-shape on the other hand, which is what it had during today's premarket, there were only two HVN bars and they were spaced apart where the two curves of the B peaked.

I think it's possible that defining the shapes only using the HVN bars (their location and their relative sizes compared with each other) might end up matching well with reality most of the time or might even be more flexible and useful than trying to define the shapes based on all 40 bars.
 
Thank you. I just had some interesting thoughts about it this morning as well. There might be a way to simplify the problem based on how the script already identifies the HVNs as orange bars:

View attachment 20313

What I was thinking is that one could just identify which zone the HVN(s) are in and specify that the primary HVN(s) have to be x% larger than the minor ones in cases of an imbalanced profile shape like the b shape above. For a B-shape on the other hand, which is what it had during today's premarket, there were only two HVN bars and they were spaced apart where the two curves of the B peaked.

I think it's possible that defining the shapes only using the HVN bars (their location and their relative sizes compared with each other) might end up matching well with reality most of the time or might even be more flexible and useful than trying to define the shapes based on all 40 bars.
This is an interesting idea, I certainly wouldn't call it a "poor mans" technique but that is ear-catching.
I have heard other look at the sequences of P-shaped and D-shaped profiles as a long term bull trend begins. Experts who use Volume profile have concepts they consider such as the strong rejection or weak rejections or market rotations.
Do you have any concepts or techniques you wish to practice with this technique... One thought that comes to mind for me is to make the clocks that start and stop the Volume-Profiles controlled by defined events, this is an idea inspired by @shakib3585

We might also wish to compare the data from the "Volume-Profile" with the "Time spent on a price Profile" I wonder if this could tell us how much of a volume in an area is "mobile" and on a trending order-flow vrs. how much of a Volume is in a stagnate traffic jam at specific prices.
 
Hello
Modify "Poor Man's Volume Profile" to identify and label profile shapes

@halcyonguy and some assisting members converted a pinescript study that creates a volume profile here.

I think this is interesting because if I understand correcting, the "profile" generation function in thinkscript doesn't allow for much scripting interaction, whereas this "Poor Man's Volume Profile" is not using the "profile" function and should therefore offer more possibilities.

For example, with the Poor Man's Volume Profile, wouldn't it be possible to code signals that are conditional based on the shape of the profile? I think so if the profile shapes can be defined objectively enough. It seems like that would be possible.

In the code, each line is plotted as z0 through z39 for creating 40 horizontal profile bars total. Intuitively it seems like profile shapes could just be defined by creating ranges of these bars as quadrants of the profile and taking the percentage totals of the quadrants versus each other.

For example, I tried adding this code at the end of the study:

Code:
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);

I can't find any charts that will show the labels and I think the reason is probably that the definitions of the profile shapes are too simplistic and therefore not capturing real profile shapes (only ideal ones).

Anyone have any suggestions or ideas about a better way to try to mathematically define the profile shapes? Or is it too subjective to be expressed as code in a practical way?

(Complete script is provided below: )

Code:
# Poorman_volume_profile_02b

#finished by rrm411
#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#post5


#  replace max()  at 500+  that find row max #s


#Poor man's volume profile
#https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/
#1100 lines
#// © Ildar Akhmetgaleev (AkhIL)
#// See https://github.com/akhilman/vol-poorofile
#// vim: shiftwidth=2 tabstop=2
#study("Poor man's volume profile", "PMVolProf", overlay=true, max_bars_back=500)


def na = double.nan;
def bn = BarNumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

#def lastbar = !isnan(close[0]) and isnan(close[-1]);

def minb = 10;
def maxb = 500;
input block_size2 = 200;
def block_size = if block_size2 < minb then minb else if block_size2 > maxb then maxb else block_size2;
input visual_row_width = 50;
input show_peaks = yes;

AddLabel(1, "look " + block_size + " bars back", Color.YELLOW);

input show_vert_line_range_start = yes;
def first = (!IsNaN(close[-block_size]) and IsNaN(close[-(block_size + 1)]));
AddVerticalLine(show_vert_line_range_start and first, "-", Color.CYAN);


#// Calculate profile

def block_high = Highest(high, block_size);
def block_low = Lowest(low, block_size);
def highest_row_value = 0;


# data to collect
# count bars in a range
#def data = 1;
# convert volume to millions
#def data = volume/1000000;
# convert volume to 1000s
def data = volume / 1000;


# do stuff on last bar

def row_qty = 40;
def block_height = block_high - block_low;
def row_height = block_height / row_qty;

# chg first values to 1, so no divide by 0 err
def k = 1;
def r00lo = if bn == 1 then k else if lastbar then (block_low + row_height * 0) else r00lo[1];
def r00hi = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r00hi[1];
def r01lo = if bn == 1 then k else if lastbar then (block_low + row_height * 1) else r01lo[1];
def r01hi = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r01hi[1];
def r02lo = if bn == 1 then k else if lastbar then (block_low + row_height * 2) else r02lo[1];
def r02hi = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r02hi[1];
def r03lo = if bn == 1 then k else if lastbar then (block_low + row_height * 3) else r03lo[1];
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
def r04lo = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r04lo[1];
def r04hi = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r04hi[1];
def r05lo = if bn == 1 then k else if lastbar then (block_low + row_height * 5) else r05lo[1];
def r05hi = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r05hi[1];
def r06lo = if bn == 1 then k else if lastbar then (block_low + row_height * 6) else r06lo[1];
def r06hi = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r06hi[1];
def r07lo = if bn == 1 then k else if lastbar then (block_low + row_height * 7) else r07lo[1];
def r07hi = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r07hi[1];
def r08lo = if bn == 1 then k else if lastbar then (block_low + row_height * 8) else r08lo[1];
def r08hi = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r08hi[1];
def r09lo = if bn == 1 then k else if lastbar then (block_low + row_height * 9) else r09lo[1];
def r09hi = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r09hi[1];
def r10lo = if bn == 1 then k else if lastbar then (block_low + row_height * 10) else r10lo[1];
def r10hi = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r10hi[1];
def r11lo = if bn == 1 then k else if lastbar then (block_low + row_height * 11) else r11lo[1];
def r11hi = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r11hi[1];
def r12lo = if bn == 1 then k else if lastbar then (block_low + row_height * 12) else r12lo[1];
def r12hi = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r12hi[1];
def r13lo = if bn == 1 then k else if lastbar then (block_low + row_height * 13) else r13lo[1];
def r13hi = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r13hi[1];
def r14lo = if bn == 1 then k else if lastbar then (block_low + row_height * 14) else r14lo[1];
def r14hi = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r14hi[1];
def r15lo = if bn == 1 then k else if lastbar then (block_low + row_height * 15) else r15lo[1];
def r15hi = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r15hi[1];
def r16lo = if bn == 1 then k else if lastbar then (block_low + row_height * 16) else r16lo[1];
def r16hi = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r16hi[1];
def r17lo = if bn == 1 then k else if lastbar then (block_low + row_height * 17) else r17lo[1];
def r17hi = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r17hi[1];
def r18lo = if bn == 1 then k else if lastbar then (block_low + row_height * 18) else r18lo[1];
def r18hi = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r18hi[1];
def r19lo = if bn == 1 then k else if lastbar then (block_low + row_height * 19) else r19lo[1];
def r19hi = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r19hi[1];
def r20lo = if bn == 1 then k else if lastbar then (block_low + row_height * 20) else r20lo[1];
def r20hi = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r20hi[1];
def r21lo = if bn == 1 then k else if lastbar then (block_low + row_height * 21) else r21lo[1];
def r21hi = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r21hi[1];
def r22lo = if bn == 1 then k else if lastbar then (block_low + row_height * 22) else r22lo[1];
def r22hi = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r22hi[1];
def r23lo = if bn == 1 then k else if lastbar then (block_low + row_height * 23) else r23lo[1];
def r23hi = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r23hi[1];
def r24lo = if bn == 1 then k else if lastbar then (block_low + row_height * 24) else r24lo[1];
def r24hi = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r24hi[1];
def r25lo = if bn == 1 then k else if lastbar then (block_low + row_height * 25) else r25lo[1];
def r25hi = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r25hi[1];
def r26lo = if bn == 1 then k else if lastbar then (block_low + row_height * 26) else r26lo[1];
def r26hi = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r26hi[1];
def r27lo = if bn == 1 then k else if lastbar then (block_low + row_height * 27) else r27lo[1];
def r27hi = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r27hi[1];
def r28lo = if bn == 1 then k else if lastbar then (block_low + row_height * 28) else r28lo[1];
def r28hi = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r28hi[1];
def r29lo = if bn == 1 then k else if lastbar then (block_low + row_height * 29) else r29lo[1];
def r29hi = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r29hi[1];
def r30lo = if bn == 1 then k else if lastbar then (block_low + row_height * 30) else r30lo[1];
def r30hi = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r30hi[1];
def r31lo = if bn == 1 then k else if lastbar then (block_low + row_height * 31) else r31lo[1];
def r31hi = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r31hi[1];
def r32lo = if bn == 1 then k else if lastbar then (block_low + row_height * 32) else r32lo[1];
def r32hi = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r32hi[1];
def r33lo = if bn == 1 then k else if lastbar then (block_low + row_height * 33) else r33lo[1];
def r33hi = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r33hi[1];
def r34lo = if bn == 1 then k else if lastbar then (block_low + row_height * 34) else r34lo[1];
def r34hi = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r34hi[1];
def r35lo = if bn == 1 then k else if lastbar then (block_low + row_height * 35) else r35lo[1];
def r35hi = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r35hi[1];
def r36lo = if bn == 1 then k else if lastbar then (block_low + row_height * 36) else r36lo[1];
def r36hi = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r36hi[1];
def r37lo = if bn == 1 then k else if lastbar then (block_low + row_height * 37) else r37lo[1];
def r37hi = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r37hi[1];
def r38lo = if bn == 1 then k else if lastbar then (block_low + row_height * 38) else r38lo[1];
def r38hi = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r38hi[1];
def r39lo = if bn == 1 then k else if lastbar then (block_low + row_height * 39) else r39lo[1];
def r39hi = if bn == 1 then k else if lastbar then (block_low + row_height * 40) else r39hi[1];



def r00mid = (r00hi + r00lo) / 2;
def r01mid = (r01hi + r01lo) / 2;
def r02mid = (r02hi + r02lo) / 2;
def r03mid = (r03hi + r03lo) / 2;
def r04mid = (r04hi + r04lo) / 2;
def r05mid = (r05hi + r05lo) / 2;
def r06mid = (r06hi + r06lo) / 2;
def r07mid = (r07hi + r07lo) / 2;
def r08mid = (r08hi + r08lo) / 2;
def r09mid = (r09hi + r09lo) / 2;
def r10mid = (r10hi + r10lo) / 2;
def r11mid = (r11hi + r11lo) / 2;
def r12mid = (r12hi + r12lo) / 2;
def r13mid = (r13hi + r13lo) / 2;
def r14mid = (r14hi + r14lo) / 2;
def r15mid = (r15hi + r15lo) / 2;
def r16mid = (r16hi + r16lo) / 2;
def r17mid = (r17hi + r17lo) / 2;
def r18mid = (r18hi + r18lo) / 2;
def r19mid = (r19hi + r19lo) / 2;
def r20mid = (r20hi + r20lo) / 2;
def r21mid = (r21hi + r21lo) / 2;
def r22mid = (r22hi + r22lo) / 2;
def r23mid = (r23hi + r23lo) / 2;
def r24mid = (r24hi + r24lo) / 2;
def r25mid = (r25hi + r25lo) / 2;
def r26mid = (r26hi + r26lo) / 2;
def r27mid = (r27hi + r27lo) / 2;
def r28mid = (r28hi + r28lo) / 2;
def r29mid = (r29hi + r29lo) / 2;
def r30mid = (r30hi + r30lo) / 2;
def r31mid = (r31hi + r31lo) / 2;
def r32mid = (r32hi + r32lo) / 2;
def r33mid = (r33hi + r33lo) / 2;
def r34mid = (r34hi + r34lo) / 2;
def r35mid = (r35hi + r35lo) / 2;
def r36mid = (r36hi + r36lo) / 2;
def r37mid = (r37hi + r37lo) / 2;
def r38mid = (r38hi + r38lo) / 2;
def r39mid = (r39hi + r39lo) / 2;


# on last bar,
# look back at prev bars, to see if part of them were within a price row range,
# if so, then add the data from that bar , volume

def m = 1;
def r00cnt = if bn == 1 then m else if lastbar then fold i0 = 0 to block_size
 with p0
 do p0 + (if GetValue(low, i0) < r00hi and GetValue(high, i0) > r00lo then GetValue(data, i0) else 0)
 else r00cnt[1];

def r01cnt = if bn == 1 then m else if lastbar then fold i1 = 0 to block_size
 with p1
 do p1 + (if GetValue(low, i1) < r01hi and GetValue(high, i1) > r01lo then GetValue(data, i1) else 0)
 else r01cnt[1];

def r02cnt = if bn == 1 then m else if lastbar then fold i2 = 0 to block_size
 with p2
 do p2 + (if GetValue(low, i2) < r02hi and GetValue(high, i2) > r02lo then GetValue(data, i2) else 0)
 else r02cnt[1];

def r03cnt = if bn == 1 then m else if lastbar then fold i3 = 0 to block_size
 with p3
 do p3 + (if GetValue(low, i3) < r03hi and GetValue(high, i3) > r03lo then GetValue(data, i3) else 0)
 else r03cnt[1];

def r04cnt = if bn == 1 then m else if lastbar then fold i4 = 0 to block_size
 with p4
 do p4 + (if GetValue(low, i4) < r04hi and GetValue(high, i4) > r04lo then GetValue(data, i4) else 0)
 else r04cnt[1];

def r05cnt = if bn == 1 then m else if lastbar then fold i5 = 0 to block_size
 with p5
 do p5 + (if GetValue(low, i5) < r05hi and GetValue(high, i5) > r05lo then GetValue(data, i5) else 0)
 else r05cnt[1];

def r06cnt = if bn == 1 then m else if lastbar then fold i6 = 0 to block_size
 with p6
 do p6 + (if GetValue(low, i6) < r06hi and GetValue(high, i6) > r06lo then GetValue(data, i6) else 0)
 else r06cnt[1];

def r07cnt = if bn == 1 then m else if lastbar then fold i7 = 0 to block_size
 with p7
 do p7 + (if GetValue(low, i7) < r07hi and GetValue(high, i7) > r07lo then GetValue(data, i7) else 0)
 else r07cnt[1];

def r08cnt = if bn == 1 then m else if lastbar then fold i8 = 0 to block_size
 with p8
 do p8 + (if GetValue(low, i8) < r08hi and GetValue(high, i8) > r08lo then GetValue(data, i8) else 0)
 else r08cnt[1];

def r09cnt = if bn == 1 then m else if lastbar then fold i9 = 0 to block_size
 with p9
 do p9 + (if GetValue(low, i9) < r09hi and GetValue(high, i9) > r09lo then GetValue(data, i9) else 0)
 else r09cnt[1];

def r10cnt = if bn == 1 then m else if lastbar then fold i10 = 0 to block_size
 with p10
 do p10 + (if GetValue(low, i10) < r10hi and GetValue(high, i10) > r10lo then GetValue(data, i10) else 0)
 else r10cnt[1];

def r11cnt = if bn == 1 then m else if lastbar then fold i11 = 0 to block_size
 with p11
 do p11 + (if GetValue(low, i11) < r11hi and GetValue(high, i11) > r11lo then GetValue(data, i11) else 0)
 else r11cnt[1];

def r12cnt = if bn == 1 then m else if lastbar then fold i12 = 0 to block_size
 with p12
 do p12 + (if GetValue(low, i12) < r12hi and GetValue(high, i12) > r12lo then GetValue(data, i12) else 0)
 else r12cnt[1];

def r13cnt = if bn == 1 then m else if lastbar then fold i13 = 0 to block_size
 with p13
 do p13 + (if GetValue(low, i13) < r13hi and GetValue(high, i13) > r13lo then GetValue(data, i13) else 0)
 else r13cnt[1];

def r14cnt = if bn == 1 then m else if lastbar then fold i14 = 0 to block_size
 with p14
 do p14 + (if GetValue(low, i14) < r14hi and GetValue(high, i14) > r14lo then GetValue(data, i14) else 0)
 else r14cnt[1];

def r15cnt = if bn == 1 then m else if lastbar then fold i15 = 0 to block_size
 with p15
 do p15 + (if GetValue(low, i15) < r15hi and GetValue(high, i15) > r15lo then GetValue(data, i15) else 0)
 else r15cnt[1];

def r16cnt = if bn == 1 then m else if lastbar then fold i16 = 0 to block_size
 with p16
 do p16 + (if GetValue(low, i16) < r16hi and GetValue(high, i16) > r16lo then GetValue(data, i16) else 0)
 else r16cnt[1];

def r17cnt = if bn == 1 then m else if lastbar then fold i17 = 0 to block_size
 with p17
 do p17 + (if GetValue(low, i17) < r17hi and GetValue(high, i17) > r17lo then GetValue(data, i17) else 0)
 else r17cnt[1];

def r18cnt = if bn == 1 then m else if lastbar then fold i18 = 0 to block_size
 with p18
 do p18 + (if GetValue(low, i18) < r18hi and GetValue(high, i18) > r18lo then GetValue(data, i18) else 0)
 else r18cnt[1];

def r19cnt = if bn == 1 then m else if lastbar then fold i19 = 0 to block_size
 with p19
 do p19 + (if GetValue(low, i19) < r19hi and GetValue(high, i19) > r19lo then GetValue(data, i19) else 0)
 else r19cnt[1];

def r20cnt = if bn == 1 then m else if lastbar then fold i20 = 0 to block_size
 with p20
 do p20 + (if GetValue(low, i20) < r20hi and GetValue(high, i20) > r20lo then GetValue(data, i20) else 0)
 else r20cnt[1];

def r21cnt = if bn == 1 then m else if lastbar then fold i21 = 0 to block_size
 with p21
 do p21 + (if GetValue(low, i21) < r21hi and GetValue(high, i21) > r21lo then GetValue(data, i21) else 0)
 else r21cnt[1];

def r22cnt = if bn == 1 then m else if lastbar then fold i22 = 0 to block_size
 with p22
 do p22 + (if GetValue(low, i22) < r22hi and GetValue(high, i22) > r22lo then GetValue(data, i22) else 0)
 else r22cnt[1];

def r23cnt = if bn == 1 then m else if lastbar then fold i23 = 0 to block_size
 with p23
 do p23 + (if GetValue(low, i23) < r23hi and GetValue(high, i23) > r23lo then GetValue(data, i23) else 0)
 else r23cnt[1];

def r24cnt = if bn == 1 then m else if lastbar then fold i24 = 0 to block_size
 with p24
 do p24 + (if GetValue(low, i24) < r24hi and GetValue(high, i24) > r24lo then GetValue(data, i24) else 0)
 else r24cnt[1];

def r25cnt = if bn == 1 then m else if lastbar then fold i25 = 0 to block_size
 with p25
 do p25 + (if GetValue(low, i25) < r25hi and GetValue(high, i25) > r25lo then GetValue(data, i25) else 0)
 else r25cnt[1];

def r26cnt = if bn == 1 then m else if lastbar then fold i26 = 0 to block_size
 with p26
 do p26 + (if GetValue(low, i26) < r26hi and GetValue(high, i26) > r26lo then GetValue(data, i26) else 0)
 else r26cnt[1];

def r27cnt = if bn == 1 then m else if lastbar then fold i27 = 0 to block_size
 with p27
 do p27 + (if GetValue(low, i27) < r27hi and GetValue(high, i27) > r27lo then GetValue(data, i27) else 0)
 else r27cnt[1];

def r28cnt = if bn == 1 then m else if lastbar then fold i28 = 0 to block_size
 with p28
 do p28 + (if GetValue(low, i28) < r28hi and GetValue(high, i28) > r28lo then GetValue(data, i28) else 0)
 else r28cnt[1];

def r29cnt = if bn == 1 then m else if lastbar then fold i29 = 0 to block_size
 with p29
 do p29 + (if GetValue(low, i29) < r29hi and GetValue(high, i29) > r29lo then GetValue(data, i29) else 0)
 else r29cnt[1];

def r30cnt = if bn == 1 then m else if lastbar then fold i30 = 0 to block_size
 with p30
 do p30 + (if GetValue(low, i30) < r30hi and GetValue(high, i30) > r30lo then GetValue(data, i30) else 0)
 else r30cnt[1];

def r31cnt = if bn == 1 then m else if lastbar then fold i31 = 0 to block_size
 with p31
 do p31 + (if GetValue(low, i31) < r31hi and GetValue(high, i31) > r31lo then GetValue(data, i31) else 0)
 else r31cnt[1];

def r32cnt = if bn == 1 then m else if lastbar then fold i32 = 0 to block_size
 with p32
 do p32 + (if GetValue(low, i32) < r32hi and GetValue(high, i32) > r32lo then GetValue(data, i32) else 0)
 else r32cnt[1];

def r33cnt = if bn == 1 then m else if lastbar then fold i33 = 0 to block_size
 with p33
 do p33 + (if GetValue(low, i33) < r33hi and GetValue(high, i33) > r33lo then GetValue(data, i33) else 0)
 else r33cnt[1];

def r34cnt = if bn == 1 then m else if lastbar then fold i34 = 0 to block_size
 with p34
 do p34 + (if GetValue(low, i34) < r34hi and GetValue(high, i34) > r34lo then GetValue(data, i34) else 0)
 else r34cnt[1];

def r35cnt = if bn == 1 then m else if lastbar then fold i35 = 0 to block_size
 with p35
 do p35 + (if GetValue(low, i35) < r35hi and GetValue(high, i35) > r35lo then GetValue(data, i35) else 0)
 else r35cnt[1];

def r36cnt = if bn == 1 then m else if lastbar then fold i36 = 0 to block_size
 with p36
 do p36 + (if GetValue(low, i36) < r36hi and GetValue(high, i36) > r36lo then GetValue(data, i36) else 0)
 else r36cnt[1];

def r37cnt = if bn == 1 then m else if lastbar then fold i37 = 0 to block_size
 with p37
 do p37 + (if GetValue(low, i37) < r37hi and GetValue(high, i37) > r37lo then GetValue(data, i37) else 0)
 else r37cnt[1];

def r38cnt = if bn == 1 then m else if lastbar then fold i38 = 0 to block_size
 with p38
 do p38 + (if GetValue(low, i38) < r38hi and GetValue(high, i38) > r38lo then GetValue(data, i38) else 0)
 else r38cnt[1];

def r39cnt = if bn == 1 then m else if lastbar then fold i39 = 0 to block_size
 with p39
 do p39 + (if GetValue(low, i39) < r39hi and GetValue(high, i39) > r39lo then GetValue(data, i39) else 0)
 else r39cnt[1];



# find max data sum
def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# calc ratio of cnt to highest cnt , a bar cnt , for the horz length of each row
def r00r = Floor(visual_row_width * r00cnt / maxdata);
def r01r = Floor(visual_row_width * r01cnt / maxdata);
def r02r = Floor(visual_row_width * r02cnt / maxdata);
def r03r = Floor(visual_row_width * r03cnt / maxdata);
def r04r = Floor(visual_row_width * r04cnt / maxdata);
def r05r = Floor(visual_row_width * r05cnt / maxdata);
def r06r = Floor(visual_row_width * r06cnt / maxdata);
def r07r = Floor(visual_row_width * r07cnt / maxdata);
def r08r = Floor(visual_row_width * r08cnt / maxdata);
def r09r = Floor(visual_row_width * r09cnt / maxdata);
def r10r = Floor(visual_row_width * r10cnt / maxdata);
def r11r = Floor(visual_row_width * r11cnt / maxdata);
def r12r = Floor(visual_row_width * r12cnt / maxdata);
def r13r = Floor(visual_row_width * r13cnt / maxdata);
def r14r = Floor(visual_row_width * r14cnt / maxdata);
def r15r = Floor(visual_row_width * r15cnt / maxdata);
def r16r = Floor(visual_row_width * r16cnt / maxdata);
def r17r = Floor(visual_row_width * r17cnt / maxdata);
def r18r = Floor(visual_row_width * r18cnt / maxdata);
def r19r = Floor(visual_row_width * r19cnt / maxdata);
def r20r = Floor(visual_row_width * r20cnt / maxdata);
def r21r = Floor(visual_row_width * r21cnt / maxdata);
def r22r = Floor(visual_row_width * r22cnt / maxdata);
def r23r = Floor(visual_row_width * r23cnt / maxdata);
def r24r = Floor(visual_row_width * r24cnt / maxdata);
def r25r = Floor(visual_row_width * r25cnt / maxdata);
def r26r = Floor(visual_row_width * r26cnt / maxdata);
def r27r = Floor(visual_row_width * r27cnt / maxdata);
def r28r = Floor(visual_row_width * r28cnt / maxdata);
def r29r = Floor(visual_row_width * r29cnt / maxdata);
def r30r = Floor(visual_row_width * r30cnt / maxdata);
def r31r = Floor(visual_row_width * r31cnt / maxdata);
def r32r = Floor(visual_row_width * r32cnt / maxdata);
def r33r = Floor(visual_row_width * r33cnt / maxdata);
def r34r = Floor(visual_row_width * r34cnt / maxdata);
def r35r = Floor(visual_row_width * r35cnt / maxdata);
def r36r = Floor(visual_row_width * r36cnt / maxdata);
def r37r = Floor(visual_row_width * r37cnt / maxdata);
def r38r = Floor(visual_row_width * r38cnt / maxdata);
def r39r = Floor(visual_row_width * r39cnt / maxdata);



#// Draw profile


# draw rows on bars after the last bar
# mark bars after lastbar as true, if the ratio cnt of bars .....
def x0 = (bn > lastbn and bn <= (lastbn + r00r));
def x1 = (bn > lastbn and bn <= (lastbn + r01r));
def x2 = (bn > lastbn and bn <= (lastbn + r02r));
def x3 = (bn > lastbn and bn <= (lastbn + r03r));
def x4 = (bn > lastbn and bn <= (lastbn + r04r));
def x5 = (bn > lastbn and bn <= (lastbn + r05r));
def x6 = (bn > lastbn and bn <= (lastbn + r06r));
def x7 = (bn > lastbn and bn <= (lastbn + r07r));
def x8 = (bn > lastbn and bn <= (lastbn + r08r));
def x9 = (bn > lastbn and bn <= (lastbn + r09r));
def x10 = (bn > lastbn and bn <= (lastbn + r10r));
def x11 = (bn > lastbn and bn <= (lastbn + r11r));
def x12 = (bn > lastbn and bn <= (lastbn + r12r));
def x13 = (bn > lastbn and bn <= (lastbn + r13r));
def x14 = (bn > lastbn and bn <= (lastbn + r14r));
def x15 = (bn > lastbn and bn <= (lastbn + r15r));
def x16 = (bn > lastbn and bn <= (lastbn + r16r));
def x17 = (bn > lastbn and bn <= (lastbn + r17r));
def x18 = (bn > lastbn and bn <= (lastbn + r18r));
def x19 = (bn > lastbn and bn <= (lastbn + r19r));
def x20 = (bn > lastbn and bn <= (lastbn + r20r));
def x21 = (bn > lastbn and bn <= (lastbn + r21r));
def x22 = (bn > lastbn and bn <= (lastbn + r22r));
def x23 = (bn > lastbn and bn <= (lastbn + r23r));
def x24 = (bn > lastbn and bn <= (lastbn + r24r));
def x25 = (bn > lastbn and bn <= (lastbn + r25r));
def x26 = (bn > lastbn and bn <= (lastbn + r26r));
def x27 = (bn > lastbn and bn <= (lastbn + r27r));
def x28 = (bn > lastbn and bn <= (lastbn + r28r));
def x29 = (bn > lastbn and bn <= (lastbn + r29r));
def x30 = (bn > lastbn and bn <= (lastbn + r30r));
def x31 = (bn > lastbn and bn <= (lastbn + r31r));
def x32 = (bn > lastbn and bn <= (lastbn + r32r));
def x33 = (bn > lastbn and bn <= (lastbn + r33r));
def x34 = (bn > lastbn and bn <= (lastbn + r34r));
def x35 = (bn > lastbn and bn <= (lastbn + r35r));
def x36 = (bn > lastbn and bn <= (lastbn + r36r));
def x37 = (bn > lastbn and bn <= (lastbn + r37r));
def x38 = (bn > lastbn and bn <= (lastbn + r38r));
def x39 = (bn > lastbn and bn <= (lastbn + r39r));


#---------------------------

# orig codes
# find max value , +-5 values , compare each row value to 10 other values
# if current is the max, then orange
#   if first , compare to 5 future
#   later , compare to 5 before and 5 after
#   last , compare to 5 prev

# ref - orig code
#if row0_value >= row1_value and row0_value >= row2_value and row0_value >= row3_value and row0_value >= row4_value and row0_value >= row5_value
#        row0_is_peak := true

#if row10_value >= row5_value and row10_value >= row6_value and row10_value >= row7_value and row10_value >= row8_value and row10_value >= row9_value and row10_value >= row11_value and row10_value >= row12_value and row10_value >= row13_value and row10_value >= row14_value and row10_value >= row15_value
#        row10_is_peak := true

#if row20_value >= row15_value and row20_value >= row16_value and row20_value >= row17_value and row20_value >= row18_value and row20_value >= row19_value and row20_value >= row21_value and row20_value >= row22_value and row20_value >= row23_value and row20_value >= row24_value and row20_value >= row25_value
#        row20_is_peak := true

#if row39_value >= row34_value and row39_value >= row35_value and row39_value >= row36_value and row39_value >= row37_value and row39_value >= row38_value
#        row39_is_peak := true

#------------------

# copied from line 394
#def maxdata = Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))))))))))))))))))))))))))))))));


# compare current row to prev 5 rows and future 5 rows

def max00 = if r00cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, r05cnt)))))) then 1 else 0;
def max01 = if r01cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, r06cnt))))))) then 1 else 0;
def max02 = if r02cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, r07cnt)))))))) then 1 else 0;
def max03 = if r03cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, r08cnt))))))))) then 1 else 0;
def max04 = if r04cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, r09cnt)))))))))) then 1 else 0;

def max05 = if r05cnt == (Max(r00cnt, Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, r10cnt))))))))))) then 1 else 0;
def max06 = if r06cnt == (Max(r01cnt, Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, r11cnt))))))))))) then 1 else 0;
def max07 = if r07cnt == (Max(r02cnt, Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, r12cnt))))))))))) then 1 else 0;
def max08 = if r08cnt == (Max(r03cnt, Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, r13cnt))))))))))) then 1 else 0;
def max09 = if r09cnt == (Max(r04cnt, Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, r14cnt))))))))))) then 1 else 0;
def max10 = if r10cnt == (Max(r05cnt, Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, r15cnt))))))))))) then 1 else 0;
def max11 = if r11cnt == (Max(r06cnt, Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, r16cnt))))))))))) then 1 else 0;
def max12 = if r12cnt == (Max(r07cnt, Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, r17cnt))))))))))) then 1 else 0;

def max13 = if r13cnt == (Max(r08cnt, Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, r18cnt))))))))))) then 1 else 0;
def max14 = if r14cnt == (Max(r09cnt, Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, r19cnt))))))))))) then 1 else 0;
def max15 = if r15cnt == (Max(r10cnt, Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, r20cnt))))))))))) then 1 else 0;
def max16 = if r16cnt == (Max(r11cnt, Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, r21cnt))))))))))) then 1 else 0;
def max17 = if r17cnt == (Max(r12cnt, Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, r22cnt))))))))))) then 1 else 0;
def max18 = if r18cnt == (Max(r13cnt, Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, r23cnt))))))))))) then 1 else 0;
def max19 = if r19cnt == (Max(r14cnt, Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, r23cnt))))))))))) then 1 else 0;

def max20 = if r20cnt == (Max(r15cnt, Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, r25cnt))))))))))) then 1 else 0;
def max21 = if r21cnt == (Max(r16cnt, Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, r26cnt))))))))))) then 1 else 0;
def max22 = if r22cnt == (Max(r17cnt, Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, r27cnt))))))))))) then 1 else 0;
def max23 = if r23cnt == (Max(r18cnt, Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, r23cnt))))))))))) then 1 else 0;
def max24 = if r24cnt == (Max(r19cnt, Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, r29cnt))))))))))) then 1 else 0;
def max25 = if r25cnt == (Max(r20cnt, Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, r30cnt))))))))))) then 1 else 0;
def max26 = if r26cnt == (Max(r21cnt, Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, r31cnt))))))))))) then 1 else 0;
def max27 = if r27cnt == (Max(r22cnt, Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, r32cnt))))))))))) then 1 else 0;
def max28 = if r28cnt == (Max(r23cnt, Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, r33cnt))))))))))) then 1 else 0;
def max29 = if r29cnt == (Max(r24cnt, Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, r34cnt))))))))))) then 1 else 0;

def max30 = if r30cnt == (Max(r25cnt, Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, r35cnt))))))))))) then 1 else 0;
def max31 = if r31cnt == (Max(r26cnt, Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, r36cnt))))))))))) then 1 else 0;
def max32 = if r32cnt == (Max(r27cnt, Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, r37cnt))))))))))) then 1 else 0;
def max33 = if r33cnt == (Max(r28cnt, Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, r38cnt))))))))))) then 1 else 0;
def max34 = if r34cnt == (Max(r29cnt, Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))))) then 1 else 0;

def max35 = if r35cnt == (Max(r30cnt, Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))))) then 1 else 0;
def max36 = if r36cnt == (Max(r31cnt, Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))))) then 1 else 0;
def max37 = if r37cnt == (Max(r32cnt, Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))))) then 1 else 0;
def max38 = if r38cnt == (Max(r33cnt, Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt))))))) then 1 else 0;
def max39 = if r39cnt == (Max(r34cnt, Max(r35cnt, Max(r36cnt, Max(r37cnt, Max(r38cnt, r39cnt)))))) then 1 else 0;

#---------------------------


#  replace max()  at 500+  that find row max #s
# hmm  diff vars , so cant just use highest()...

# def mx00 =


#-----------------------------

defineglobalcolor("colorhi", color.orange);

input line_thick = 2;
input show_lines_wsquares = yes;

plot z0 = if show_lines_wsquares and x0 then r00mid else na;
z0.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max00 then GlobalColor("colorhi") else color.gray);
#z0.SetDefaultColor(Color.GRAY);
z0.SetLineWeight(line_thick);
z0.HideBubble();

plot z1 = if show_lines_wsquares and x1 then r01mid else na;
z1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z1.AssignValueColor(if max01 then GlobalColor("colorhi") else color.gray);
#z1.SetDefaultColor(Color.GRAY);
z1.SetLineWeight(line_thick);
z1.HideBubble();

plot z2 = if show_lines_wsquares and x2 then r02mid else na;
z2.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z2.AssignValueColor(if max02 then GlobalColor("colorhi") else color.gray);
#z2.SetDefaultColor(Color.GRAY);
z2.SetLineWeight(line_thick);
z2.HideBubble();

plot z3 = if show_lines_wsquares and x3 then r03mid else na;
z3.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z3.AssignValueColor(if max03 then GlobalColor("colorhi") else color.gray);
#z3.SetDefaultColor(Color.GRAY);
z3.SetLineWeight(line_thick);
z3.HideBubble();

plot z4 = if show_lines_wsquares and x4 then r04mid else na;
z4.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z4.AssignValueColor(if max04 then GlobalColor("colorhi") else color.gray);
z4.SetDefaultColor(Color.GRAY);
z4.SetLineWeight(line_thick);
z4.HideBubble();

plot z5 = if show_lines_wsquares and x5 then r05mid else na;
z5.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z5.AssignValueColor(if max05 then GlobalColor("colorhi") else color.gray);
#z5.SetDefaultColor(Color.GRAY);
z5.SetLineWeight(line_thick);
z5.HideBubble();

plot z6 = if show_lines_wsquares and x6 then r06mid else na;
z6.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z6.AssignValueColor(if max06 then GlobalColor("colorhi") else color.gray);
z6.SetDefaultColor(Color.GRAY);
z6.SetLineWeight(line_thick);
z6.HideBubble();

plot z7 = if show_lines_wsquares and x7 then r07mid else na;
z7.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z7.AssignValueColor(if max07 then GlobalColor("colorhi") else color.gray);
#z7.SetDefaultColor(Color.GRAY);
z7.SetLineWeight(line_thick);
z7.HideBubble();

plot z8 = if show_lines_wsquares and x8 then r08mid else na;
z8.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z8.AssignValueColor(if max08 then GlobalColor("colorhi") else color.gray);
#z8.SetDefaultColor(Color.GRAY);
z8.SetLineWeight(line_thick);
z8.HideBubble();

plot z9 = if show_lines_wsquares and x9 then r09mid else na;
z9.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z9.AssignValueColor(if max09 then GlobalColor("colorhi") else color.gray);
#z9.SetDefaultColor(Color.GRAY);
z9.SetLineWeight(line_thick);
z9.HideBubble();

plot z10 = if show_lines_wsquares and x10 then r10mid else na;
z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z10.AssignValueColor(if max10 then GlobalColor("colorhi") else color.gray);
#z10.SetDefaultColor(Color.GRAY);
z10.SetLineWeight(line_thick);
z10.HideBubble();

plot z11 = if show_lines_wsquares and x11 then r11mid else na;
z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z11.AssignValueColor(if max11 then GlobalColor("colorhi") else color.gray);
#z11.SetDefaultColor(Color.GRAY);
z11.SetLineWeight(line_thick);
z11.HideBubble();

plot z12 = if show_lines_wsquares and x12 then r12mid else na;
z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z12.AssignValueColor(if max12 then GlobalColor("colorhi") else color.gray);
#z12.SetDefaultColor(Color.GRAY);
z12.SetLineWeight(line_thick);
z12.HideBubble();

plot z13 = if show_lines_wsquares and x13 then r13mid else na;
z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z13.AssignValueColor(if max13 then GlobalColor("colorhi") else color.gray);
z13.SetDefaultColor(Color.GRAY);
z13.SetLineWeight(line_thick);
z13.HideBubble();

plot z14 = if show_lines_wsquares and x14 then r14mid else na;
z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z14.AssignValueColor(if max14 then GlobalColor("colorhi") else color.gray);
#z14.SetDefaultColor(Color.GRAY);
z14.SetLineWeight(line_thick);
z14.HideBubble();

plot z15 = if show_lines_wsquares and x15 then r15mid else na;
z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z15.AssignValueColor(if max15 then GlobalColor("colorhi") else color.gray);
#z15.SetDefaultColor(Color.GRAY);
z15.SetLineWeight(line_thick);
z15.HideBubble();

plot z16 = if show_lines_wsquares and x16 then r16mid else na;
z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max16 then GlobalColor("colorhi") else color.gray);
z16.SetDefaultColor(Color.GRAY);
z16.SetLineWeight(line_thick);
z16.HideBubble();

plot z17 = if show_lines_wsquares and x17 then r17mid else na;
z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z0.AssignValueColor(if max17 then GlobalColor("colorhi") else color.gray);
z17.SetDefaultColor(Color.GRAY);
z17.SetLineWeight(line_thick);
z17.HideBubble();

plot z18 = if show_lines_wsquares and x18 then r18mid else na;
z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z18.AssignValueColor(if max18 then GlobalColor("colorhi") else color.gray);
z18.SetDefaultColor(Color.GRAY);
z18.SetLineWeight(line_thick);
z18.HideBubble();

plot z19 = if show_lines_wsquares and x19 then r19mid else na;
z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z19.AssignValueColor(if max19 then GlobalColor("colorhi") else color.gray);
z19.SetDefaultColor(Color.GRAY);
z19.SetLineWeight(line_thick);
z19.HideBubble();

plot z20 = if show_lines_wsquares and x20 then r20mid else na;
z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z20.AssignValueColor(if max20 then GlobalColor("colorhi") else color.gray);
z20.SetDefaultColor(Color.GRAY);
z20.SetLineWeight(line_thick);
z20.HideBubble();

plot z21 = if show_lines_wsquares and x21 then r21mid else na;
z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z21.AssignValueColor(if max21 then GlobalColor("colorhi") else color.gray);
z21.SetDefaultColor(Color.GRAY);
z21.SetLineWeight(line_thick);
z21.HideBubble();

plot z22 = if show_lines_wsquares and x22 then r22mid else na;
z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z22.AssignValueColor(if max22 then GlobalColor("colorhi") else color.gray);
z22.SetDefaultColor(Color.GRAY);
z22.SetLineWeight(line_thick);
z22.HideBubble();

plot z23 = if show_lines_wsquares and x23 then r23mid else na;
z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z23.AssignValueColor(if max23 then GlobalColor("colorhi") else color.gray);
z23.SetDefaultColor(Color.GRAY);
z23.SetLineWeight(line_thick);
z23.HideBubble();

plot z24 = if show_lines_wsquares and x24 then r24mid else na;
z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z24.AssignValueColor(if max24 then GlobalColor("colorhi") else color.gray);
z24.SetDefaultColor(Color.GRAY);
z24.SetLineWeight(line_thick);
z24.HideBubble();

plot z25 = if show_lines_wsquares and x25 then r25mid else na;
z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z25.AssignValueColor(if max25 then GlobalColor("colorhi") else color.gray);
z25.SetDefaultColor(Color.GRAY);
z25.SetLineWeight(line_thick);
z25.HideBubble();

plot z26 = if show_lines_wsquares and x26 then r26mid else na;
z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z26.AssignValueColor(if max26 then GlobalColor("colorhi") else color.gray);
z26.SetDefaultColor(Color.GRAY);
z26.SetLineWeight(line_thick);
z26.HideBubble();

plot z27 = if show_lines_wsquares and x27 then r27mid else na;
z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z27.AssignValueColor(if max27 then GlobalColor("colorhi") else color.gray);
z27.SetDefaultColor(Color.GRAY);
z27.SetLineWeight(line_thick);
z27.HideBubble();

plot z28 = if show_lines_wsquares and x28 then r28mid else na;
z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z28.AssignValueColor(if max28 then GlobalColor("colorhi") else color.gray);
z28.SetDefaultColor(Color.GRAY);
z28.SetLineWeight(line_thick);
z28.HideBubble();

plot z29 = if show_lines_wsquares and x29 then r29mid else na;
z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z29.AssignValueColor(if max29 then GlobalColor("colorhi") else color.gray);
z29.SetDefaultColor(Color.GRAY);
z29.SetLineWeight(line_thick);
z29.HideBubble();

plot z30 = if show_lines_wsquares and x30 then r30mid else na;
z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z30.AssignValueColor(if max30 then GlobalColor("colorhi") else color.gray);
z30.SetDefaultColor(Color.GRAY);
z30.SetLineWeight(line_thick);
z30.HideBubble();

plot z31 = if show_lines_wsquares and x31 then r31mid else na;
z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z31.AssignValueColor(if max31 then GlobalColor("colorhi") else color.gray);
z31.SetDefaultColor(Color.GRAY);
z31.SetLineWeight(line_thick);
z31.HideBubble();

plot z32 = if show_lines_wsquares and x32 then r32mid else na;
z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z32.AssignValueColor(if max32 then GlobalColor("colorhi") else color.gray);
z32.SetDefaultColor(Color.GRAY);
z32.SetLineWeight(line_thick);
z32.HideBubble();

plot z33 = if show_lines_wsquares and x33 then r33mid else na;
z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z33.AssignValueColor(if max33 then GlobalColor("colorhi") else color.gray);
z33.SetDefaultColor(Color.GRAY);
z33.SetLineWeight(line_thick);
z33.HideBubble();

plot z34 = if show_lines_wsquares and x34 then r34mid else na;
z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z34.AssignValueColor(if max34 then GlobalColor("colorhi") else color.gray);
z34.SetDefaultColor(Color.GRAY);
z34.SetLineWeight(line_thick);
z34.HideBubble();

plot z35 = if show_lines_wsquares and x35 then r35mid else na;
z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z35.AssignValueColor(if max35 then GlobalColor("colorhi") else color.gray);
z35.SetDefaultColor(Color.GRAY);
z35.SetLineWeight(line_thick);
z35.HideBubble();

plot z36 = if show_lines_wsquares and x36 then r36mid else na;
z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z36.AssignValueColor(if max36 then GlobalColor("colorhi") else color.gray);
z36.SetDefaultColor(Color.GRAY);
z36.SetLineWeight(line_thick);
z36.HideBubble();

plot z37 = if show_lines_wsquares and x37 then r37mid else na;
z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z37.AssignValueColor(if max37 then GlobalColor("colorhi") else color.gray);
#z37.SetDefaultColor(Color.GRAY);
z37.SetLineWeight(line_thick);
z37.HideBubble();

plot z38 = if show_lines_wsquares and x38 then r38mid else na;
z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z38.AssignValueColor(if max38 then GlobalColor("colorhi") else color.gray);
#z38.SetDefaultColor(Color.GRAY);
z38.SetLineWeight(line_thick);
z38.HideBubble();

plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z39.AssignValueColor(if max39 then GlobalColor("colorhi") else color.gray);
#z39.SetDefaultColor(Color.GRAY);
z39.SetLineWeight(line_thick);
z39.HideBubble();


#---------------------------
# test stuff

input test1 = no;
AddChartBubble(test1, 82,
bn + "\n" +
lastbn + "\n" +
maxdata + "\n" +
r00cnt + "\n" +
r00r + "\n" +
#visual_row_width + "\n" +
Floor(r00cnt / maxdata) + "\n" +
x0
, Color.YELLOW, no);
#
#
def totalsum = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9 + z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19 + z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29 + z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;

def quadrant1 = z0 + z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;

def quadrant2 =  z10 + z11 + z12 + z13 + z14 + z15 + z16 + z17 + z18 + z19;

def quadrant3 = z20 + z21 + z22 + z23 + z24 + z25 + z26 + z27 + z28 + z29;

def quadrant4 = z30 + z31 + z32 + z33 + z34 + z35 + z36 + z37 + z38 + z39;;

def D_shaped_profile = if quadrant2>quadrant1 and quadrant1>quadrant4 and quadrant3>quadrant1 and quadrant3>quadrant4 and (((quadrant2+quadrant3)/2)<(quadrant2*1.1)) and (((quadrant2+quadrant3)/2)<(quadrant3*1.1)) then 1 else 0;

def P_shaped_profile = if quadrant1>quadrant3 and quadrant1>quadrant4 and quadrant2>quadrant3 and quadrant2>quadrant4 and ((quadrant1+quadrant2)/2)>(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def b_shaped_profile = if quadrant1<quadrant3 and quadrant1<quadrant4 and quadrant2<quadrant3 and quadrant2<quadrant4 and ((quadrant1+quadrant2)/2)<(((quadrant3+quadrant4)/2)*1.1) then 1 else 0;

def capital_B_shaped_profile = if quadrant2>quadrant1 and quadrant3>quadrant4 and quadrant2>quadrant4 and quadrant3>quadrant1 then 1 else 0;

AddLabel(D_shaped_profile==1,"D Profile",Color.White);
AddLabel(P_shaped_profile==1,"P Profile",Color.White);
AddLabel(b_shaped_profile==1,"b Profile",Color.White);
AddLabel(capital_B_shaped_profile==1,"B Profile",Color.White);
Hello, thank so much for sharing the script! I am a lover of Vol profile and I've been trying to modify the color dynamically but just can't succeed, I believe this would solve my problem. I would like to ask the type of changes that you would do to make it look more like this (see picture) I have charts where I only look at the profiles and it helps me a lot to see positions. Here you see that I have daily profiles but visualized on the 30 min timeframes (with the extended hours hidden).

Also I am aiming at changing the colors dynamically to match the volume bars at the bottom. I would greatly appreciate your help.
1703691969553.png
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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