Tradingview Poor man's volume profile

garythomas44

New member
Last edited by a moderator:
That poor mans volume profile is great on trading view, I would also like to know this as well to see multiple volume profile peaks highlighted if anyone here can code. I think would be great addition
 

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

Good Day Everyone, i found below volume profile and cluster as an interesting combination of indicators. Hope Someone find this useful and if so, can you make an effort to try to convert this to TOS platform ?

Culsters:
https://www.tradingview.com/script/eksYnVaP-Poor-man-s-volume-clusters/

Volume Profile:
https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/

Thank you Coders !!

EDIT,
finished code at post14
https://usethinkscript.com/threads/tradingview-poor-mans-volume-profile.14460/#post-119999

----------------

i'm looking at the clusters study.... but... ooof , 1700 code lines
 
Last edited:
Good Day Everyone, i found below volume profile and cluster as an interesting combination of indicators. Hope Someone find this useful and if so, can you make an effort to try to convert this to TOS platform ?

Culsters:
https://www.tradingview.com/script/eksYnVaP-Poor-man-s-volume-clusters/

Volume Profile:
https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/

Thank you Coders !!

cluster study ,
partially done through code lines 160 , ( minus some things )
draws 15 cloud rows.
i used alternating colors, cyan/yellow


this is not complete.
i can't guarantee i can complete this conversion.
i will work on it now and then and welcome others to help.

code lines skipped or altered,
21 - def custom_volume = if use_custom_volume_source then volume else volume;
41, 49, 57 , ... n_rows_affected := n_rows_affected + 1


Code:
# convert_profile_clusters_00

#https://usethinkscript.com/threads/convert-tradingview-poormans-volume-profile-and-clusters.13847/
#Tradingview Convert Tradingview PoorMan's Volume Profile and Clusters
#garythomas44  Dec 27, 2022

#Good Day Everyone, i found below volume profile and cluster as an interesting combination of indicators. Hope Someone find this useful and if so, can you make an effort to try to convert this to TOS platform ?

#Culsters:
#https://www.tradingview.com/script/eksYnVaP-Poor-man-s-volume-clusters/

#Volume Profile:
#https://www.tradingview.com/script/IWdpl712-Poor-man-s-volume-profile/

#===================================

#Culsters:
#https://www.tradingview.com/script/eksYnVaP-Poor-man-s-volume-clusters/

# https://www.tradingview.com/script/eksYnVaP-Poor-man-s-volume-clusters/



addlabel(1, "convert_profile_clusters_00", color.cyan);

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

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Ildar Akhmetgaleev (AkhIL)
#// See https://github.com/akhilman/vol-poorofile
#// vim: shiftwidth=2 tabstop=2
#//@version=4
#study("Poor man's volume clusters", "PMVolClust", overlay=true, max_bars_back=500)

#block_size = input(15, "Bars in profile block", minval=10, maxval=166)
#visual_row_width = input(10.0, "Visual row width", minval=10)
#show_vpoc = input(true, "Show volume point of control")
#filter_size = input(200, "Profile maximum high pass filter size in bars")
#use_custom_volume_source = input(false, "Use custom volume source")
#volume_source_symbol = input("", "Custom volume source symbol", input.symbol)

input block_size = 15;
# minval=10, maxval=166
input visual_row_width = 10.0;
input show_vpoc = yes;
input filter_size = 200;
input use_custom_volume_source = no;
input volume_source_symbol = "";

DefineGlobalColor("BOUNARY_COLOR", color.blue);
DefineGlobalColor("PROFILE1_COLOR", color.magenta);
DefineGlobalColor("PROFILE2_COLOR", color.light_green);
DefineGlobalColor("VPOC_COLOR", color.orange);

#custom_volume = use_custom_volume_source ? security(volume_source_symbol, timeframe.period, volume, lookahead=barmerge.lookahead_on) : volume
# ??
def custom_volume = if use_custom_volume_source then volume else volume;


#// Calculate profiles

#block_index = floor(bar_index / block_size)
#block_bar = bar_index % block_size
#rolling_high = highest(block_bar + 1)
#rolling_low = lowest(block_bar + 1)
#block_high = rolling_high[block_bar+1]
#block_low = rolling_low[block_bar+1]

def block_index = floor(bn / block_size);
def block_bar = bn % block_size;
# err - cant use var as length
#def rolling_high = highest(high, (block_bar + 1));
def rolling_high = 
fold lh = 0 to (block_bar + 1)
with ph = 0
do max(ph, getvalue(high, lh));
def rolling_low = 
fold ll = 0 to (block_bar + 1)
with pl = 99999
do min(pl, getvalue(low, ll));
def block_high = getvalue(rolling_high, (block_bar+1));
def block_low = getvalue(rolling_low, (block_bar+1));



input test_block_stuff2 = no;
addchartbubble(test_block_stuff2, low*0.995,
 block_index + "\n" +
 block_bar + "\n" +
 rolling_high + " rhi\n" +
 rolling_low + " rlo\n" +
 block_high + " bhi\n" +
 block_low + " blo"
, (if block_bar == 0 then color.cyan else color.gray), no);

input test_block0 = no;
addchartbubble(test_block0 and block_bar == 0, low*0.995,
 block_index + "\n" +
 block_bar + "\n" +
 rolling_high + " rhi\n" +
 rolling_low + " rlo\n" +
 block_high + " bhi\n" +
 block_low + " blo"
, color.cyan, no);


input test_block_stuff = no;
addlabel(test_block_stuff, block_index, color.cyan);
addlabel(test_block_stuff, block_bar, color.cyan);
addlabel(test_block_stuff, rolling_high, color.cyan);
addlabel(test_block_stuff, rolling_low, color.cyan);
addlabel(test_block_stuff, block_high, color.cyan);
addlabel(test_block_stuff, block_low, color.cyan);


#// plot(block_high, color=color.green)
#// plot(block_low, color=color.green)
#
#block_height = (block_high - block_low)
#row_height = block_height / 15
#n_rows_affected = 0

def block_height = (block_high - block_low);
def row_height = block_height / 15;
#n_rows_affected = 0


#row0_low = block_low + row_height * 0
#row0_high = block_low + row_height * 1
#row0_price = (row0_low + row0_high ) / 2
#row0_value = 0.0
#if high[block_size] > row0_low and low[block_size] < row0_high
#    row0_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1


def row0_low = block_low + row_height * 0;
def row0_high = block_low + row_height * 1;
def row0_price = (row0_low + row0_high ) / 2;
def row0_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row0_low and getvalue(low, block_size) < row0_high then getvalue(custom_volume, block_size)
 else na;
#    n_rows_affected := n_rows_affected + 1


plot z0l = row0_low;
plot z0h = row0_high;
#plot z0p = row0_price;
z0l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#z0p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
# volume
#plot z0v = row0_value;
addcloud(z0h,z0l,color.cyan);



#row1_low = block_low + row_height * 1
#row1_high = block_low + row_height * 2
#row1_price = (row1_low + row1_high ) / 2
#row1_value = 0.0
#if high[block_size] > row1_low and low[block_size] < row1_high
#    row1_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row1_low = block_low + row_height * 1;
def row1_high = block_low + row_height * 2;
def row1_price = (row1_low + row1_high ) / 2;
def row1_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row1_low and getvalue(low, block_size) < row1_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z1l = row1_low;
plot z1h = row1_high;
#plot z1p = row1_price;
z1l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z1v = row1_value;
addcloud(z1h,z1l,color.yellow);


#row2_low = block_low + row_height * 2
#row2_high = block_low + row_height * 3
#row2_price = (row2_low + row2_high ) / 2
#row2_value = 0.0
#if high[block_size] > row2_low and low[block_size] < row2_high
#    row2_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row2_low = block_low + row_height * 2;
def row2_high = block_low + row_height * 3;
def row2_price = (row2_low + row2_high ) / 2;
def row2_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row2_low and getvalue(low, block_size) < row2_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z2l = row2_low;
plot z2h = row2_high;
#plot z2p = row2_price;
z2l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z2v = row2_value;
addcloud(z2h,z2l,color.cyan);



#row3_low = block_low + row_height * 3
#row3_high = block_low + row_height * 4
#row3_price = (row3_low + row3_high ) / 2
#row3_value = 0.0
#if high[block_size] > row3_low and low[block_size] < row3_high
#    row3_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row3_low = block_low + row_height * 3;
def row3_high = block_low + row_height * 4;
def row3_price = (row3_low + row3_high ) / 2;
def row3_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row3_low and getvalue(low, block_size) < row3_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z3l = row3_low;
plot z3h = row3_high;
#plot z3p = row3_price;
z3l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z3v = row3_value;
addcloud(z3h,z3l,color.yellow);




#row4_low = block_low + row_height * 4
#row4_high = block_low + row_height * 5
#row4_price = (row4_low + row4_high ) / 2
#row4_value = 0.0
#if high[block_size] > row4_low and low[block_size] < row4_high
#    row4_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row4_low = block_low + row_height * 4;
def row4_high = block_low + row_height * 5;
def row4_price = (row4_low + row4_high ) / 2;
def row4_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row4_low and getvalue(low, block_size) < row4_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z4l = row4_low;
plot z4h = row4_high;
#plot z4p = row4_price;
z4l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z4v = row4_value;
addcloud(z4h,z4l,color.cyan);




#row5_low = block_low + row_height * 5
#row5_high = block_low + row_height * 6
#row5_price = (row5_low + row5_high ) / 2
#row5_value = 0.0
#if high[block_size] > row5_low and low[block_size] < row5_high
#    row5_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row5_low = block_low + row_height * 5;
def row5_high = block_low + row_height * 6;
def row5_price = (row5_low + row5_high ) / 2;
def row5_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row5_low and getvalue(low, block_size) < row5_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z5l = row5_low;
plot z5h = row5_high;
#plot z5p = row5_price;
z5l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z5v = row5_value;
addcloud(z5h,z5l,color.yellow);




#row6_low = block_low + row_height * 6
#row6_high = block_low + row_height * 7
#row6_price = (row6_low + row6_high ) / 2
#row6_value = 0.0
#if high[block_size] > row6_low and low[block_size] < row6_high
#    row6_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row6_low = block_low + row_height * 6;
def row6_high = block_low + row_height * 7;
def row6_price = (row6_low + row6_high ) / 2;
def row6_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row6_low and getvalue(low, block_size) < row6_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z6l = row6_low;
plot z6h = row6_high;
#plot z6p = row6_price;
z6l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z6h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z6v = row6_value;
addcloud(z6h,z6l,color.cyan);



#row7_low = block_low + row_height * 7
#row7_high = block_low + row_height * 8
#row7_price = (row7_low + row7_high ) / 2
#row7_value = 0.0
#if high[block_size] > row7_low and low[block_size] < row7_high
#    row7_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row7_low = block_low + row_height * 7;
def row7_high = block_low + row_height * 8;
def row7_price = (row7_low + row7_high ) / 2;
def row7_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row7_low and getvalue(low, block_size) < row7_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z7l = row7_low;
plot z7h = row7_high;
#plot z7p = row7_price;
z7l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z7h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z7v = row5_value;
addcloud(z7h,z7l,color.yellow);



#row8_low = block_low + row_height * 8
#row8_high = block_low + row_height * 9
#row8_price = (row8_low + row8_high ) / 2
#row8_value = 0.0
#if high[block_size] > row8_low and low[block_size] < row8_high
#    row8_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row8_low = block_low + row_height * 8;
def row8_high = block_low + row_height * 9;
def row8_price = (row8_low + row8_high ) / 2;
def row8_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row8_low and getvalue(low, block_size) < row8_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z8l = row8_low;
plot z8h = row8_high;
#plot z8p = row8_price;
z8l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z8h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z8v = row8_value;
addcloud(z8h,z8l,color.cyan);




#row9_low = block_low + row_height * 9
#row9_high = block_low + row_height * 10
#row9_price = (row9_low + row9_high ) / 2
#row9_value = 0.0
#if high[block_size] > row9_low and low[block_size] < row9_high
#    row9_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row9_low = block_low + row_height * 9;
def row9_high = block_low + row_height * 10;
def row9_price = (row9_low + row9_high ) / 2;
def row9_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row9_low and getvalue(low, block_size) < row9_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z9l = row9_low;
plot z9h = row9_high;
#plot z9p = row9_price;
z9l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z9h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z9v = row9_value;
addcloud(z9h,z9l,color.yellow);



#row10_low = block_low + row_height * 10
#row10_high = block_low + row_height * 11
#row10_price = (row10_low + row10_high ) / 2
#row10_value = 0.0
#if high[block_size] > row10_low and low[block_size] < row10_high
#    row10_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row10_low = block_low + row_height * 10;
def row10_high = block_low + row_height * 11;
def row10_price = (row10_low + row10_high ) / 2;
def row10_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row10_low and getvalue(low, block_size) < row10_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z10l = row10_low;
plot z10h = row10_high;
#plot z10p = row10_price;
z10l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z10h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z10v = row10_value;
addcloud(z10h,z10l,color.cyan);



#row11_low = block_low + row_height * 11
#row11_high = block_low + row_height * 12
#row11_price = (row11_low + row11_high ) / 2
#row11_value = 0.0
#if high[block_size] > row11_low and low[block_size] < row11_high
#    row11_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row11_low = block_low + row_height * 11;
def row11_high = block_low + row_height * 12;
def row11_price = (row11_low + row11_high ) / 2;
def row11_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row11_low and getvalue(low, block_size) < row11_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z11l = row11_low;
plot z11h = row11_high;
#plot z11p = row11_price;
z11l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z11h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z11v = row11_value;
addcloud(z11h,z11l,color.yellow);




#row12_low = block_low + row_height * 12
#row12_high = block_low + row_height * 13
#row12_price = (row12_low + row12_high ) / 2
#row12_value = 0.0
#if high[block_size] > row12_low and low[block_size] < row12_high
#    row12_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row12_low = block_low + row_height * 12;
def row12_high = block_low + row_height * 13;
def row12_price = (row12_low + row12_high ) / 2;
def row12_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row12_low and getvalue(low, block_size) < row12_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z12l = row12_low;
plot z12h = row12_high;
#plot z12p = row12_price;
z12l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z12h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z12v = row12_value;
addcloud(z12h,z12l,color.cyan);




#row13_low = block_low + row_height * 13
#row13_high = block_low + row_height * 14
#row13_price = (row13_low + row13_high ) / 2
#row13_value = 0.0
#if high[block_size] > row13_low and low[block_size] < row13_high
#    row13_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row13_low = block_low + row_height * 13;
def row13_high = block_low + row_height * 14;
def row13_price = (row13_low + row13_high ) / 2;
def row13_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row13_low and getvalue(low, block_size) < row13_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z13l = row13_low;
plot z13h = row13_high;
#plot z13p = row13_price;
z13l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z13h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z13v = row13_value;
addcloud(z13h,z13l,color.yellow);




#row14_low = block_low + row_height * 14
#row14_high = block_low + row_height * 15
#row14_price = (row14_low + row14_high ) / 2
#row14_value = 0.0
#if high[block_size] > row14_low and low[block_size] < row14_high
#    row14_value := custom_volume[block_size]
#    n_rows_affected := n_rows_affected + 1

def row14_low = block_low + row_height * 14;
def row14_high = block_low + row_height * 15;
def row14_price = (row14_low + row14_high ) / 2;
def row14_value = if bn == 1 then 0 
else if getvalue(high, block_size) > row14_low and getvalue(low, block_size) < row14_high then getvalue(custom_volume, block_size)
else na;
#    n_rows_affected := n_rows_affected + 1

plot z14l = row14_low;
plot z14h = row14_high;
#plot z14p = row14_price;
z14l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z14h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot z14v = row14_value;
addcloud(z14h,z14l,color.cyan);





#row0_value := row0_value / n_rows_affected / row_height
#row1_value := row1_value / n_rows_affected / row_height
#row2_value := row2_value / n_rows_affected / row_height
#row3_value := row3_value / n_rows_affected / row_height
#row4_value := row4_value / n_rows_affected / row_height
#row5_value := row5_value / n_rows_affected / row_height
#row6_value := row6_value / n_rows_affected / row_height
#row7_value := row7_value / n_rows_affected / row_height
#row8_value := row8_value / n_rows_affected / row_height
#row9_value := row9_value / n_rows_affected / row_height
#row10_value := row10_value / n_rows_affected / row_height
#row11_value := row11_value / n_rows_affected / row_height
#row12_value := row12_value / n_rows_affected / row_height
#row13_value := row13_value / n_rows_affected / row_height
#row14_value := row14_value / n_rows_affected / row_height
#
#// plot(row0_value, color=color.red, style=plot.style_linebr)
#
#if block_bar != 0
#    row0_value := row0_value + row0_value[1]
#    row1_value := row1_value + row1_value[1]
#    row2_value := row2_value + row2_value[1]
#    row3_value := row3_value + row3_value[1]
#    row4_value := row4_value + row4_value[1]
#    row5_value := row5_value + row5_value[1]
#    row6_value := row6_value + row6_value[1]
#    row7_value := row7_value + row7_value[1]
#    row8_value := row8_value + row8_value[1]
#    row9_value := row9_value + row9_value[1]
#    row10_value := row10_value + row10_value[1]
#    row11_value := row11_value + row11_value[1]
#    row12_value := row12_value + row12_value[1]
#    row13_value := row13_value + row13_value[1]
#    row14_value := row14_value + row14_value[1]
#
#float vpoc_price = na
#highest_row_value = 0.0
#if block_bar == block_size - 1
#    if highest_row_value < row0_value
#        highest_row_value := row0_value
#        vpoc_price := row0_price
#    if highest_row_value < row1_value
#        highest_row_value := row1_value
#        vpoc_price := row1_price
#    if highest_row_value < row2_value
#        highest_row_value := row2_value
#        vpoc_price := row2_price
#    if highest_row_value < row3_value
#        highest_row_value := row3_value
#        vpoc_price := row3_price
#    if highest_row_value < row4_value
#        highest_row_value := row4_value
#        vpoc_price := row4_price
#    if highest_row_value < row5_value
#        highest_row_value := row5_value
#        vpoc_price := row5_price
#    if highest_row_value < row6_value
#        highest_row_value := row6_value
#        vpoc_price := row6_price
#    if highest_row_value < row7_value
#        highest_row_value := row7_value
#        vpoc_price := row7_price
#    if highest_row_value < row8_value
#        highest_row_value := row8_value
#        vpoc_price := row8_price
#    if highest_row_value < row9_value
#        highest_row_value := row9_value
#        vpoc_price := row9_price
#    if highest_row_value < row10_value
#        highest_row_value := row10_value
#        vpoc_price := row10_price
#    if highest_row_value < row11_value
#        highest_row_value := row11_value
#        vpoc_price := row11_price
#    if highest_row_value < row12_value
#        highest_row_value := row12_value
#        vpoc_price := row12_price
#    if highest_row_value < row13_value
#        highest_row_value := row13_value
#        vpoc_price := row13_price
#    if highest_row_value < row14_value
#        highest_row_value := row14_value
#        vpoc_price := row14_price
#
#else
#    highest_row_value := highest_row_value[1]
#
#highest_row_value_avg = ema(highest_row_value, filter_size)
#
#// plot(row0_value)
#// plot(highest_row_value, color=color.yellow)
#// plot(highest_row_value_avg, color=color.blue)
#
#row0_width = floor(visual_row_width * row0_value / highest_row_value_avg[block_bar+1])
#row1_width = floor(visual_row_width * row1_value / highest_row_value_avg[block_bar+1])
#row2_width = floor(visual_row_width * row2_value / highest_row_value_avg[block_bar+1])
#row3_width = floor(visual_row_width * row3_value / highest_row_value_avg[block_bar+1])
#row4_width = floor(visual_row_width * row4_value / highest_row_value_avg[block_bar+1])
#row5_width = floor(visual_row_width * row5_value / highest_row_value_avg[block_bar+1])
#row6_width = floor(visual_row_width * row6_value / highest_row_value_avg[block_bar+1])
#row7_width = floor(visual_row_width * row7_value / highest_row_value_avg[block_bar+1])
#row8_width = floor(visual_row_width * row8_value / highest_row_value_avg[block_bar+1])
#row9_width = floor(visual_row_width * row9_value / highest_row_value_avg[block_bar+1])
#row10_width = floor(visual_row_width * row10_value / highest_row_value_avg[block_bar+1])
#row11_width = floor(visual_row_width * row11_value / highest_row_value_avg[block_bar+1])
#row12_width = floor(visual_row_width * row12_value / highest_row_value_avg[block_bar+1])
#row13_width = floor(visual_row_width * row13_value / highest_row_value_avg[block_bar+1])
#row14_width = floor(visual_row_width * row14_value / highest_row_value_avg[block_bar+1])
#
#// plot(row0_value, color=color.red, style=plot.style_linebr, offset=-block_size)
#
#////
#// Draw history blocks
#///
#
#// draw boudns
#
#bounds_high_y = block_bar != block_size -1 ? block_high[block_bar+1] : na
#bounds_low_y = block_bar != block_size -1 ? block_low[block_bar+1] : na
#plot(bounds_high_y, color=BOUNARY_COLOR, style=plot.style_linebr, offset=-block_size*2, title="History block high")
#plot(bounds_low_y, color=BOUNARY_COLOR, style=plot.style_linebr, offset=-block_size*2, title="History block low")
#
#// draw profile
#
#history1_block_bar = (block_index + 1) % 2 * block_size + block_bar
#
#history1_row0_price = row0_price[history1_block_bar+1]
#history1_row0_width = min(28, row0_width[history1_block_bar+1])
#history1_row0_y = history1_block_bar <= history1_row0_width ? history1_row0_price : na
#history1_row1_price = row1_price[history1_block_bar+1]
#history1_row1_width = min(28, row1_width[history1_block_bar+1])
#history1_row1_y = history1_block_bar <= history1_row1_width ? history1_row1_price : na
#history1_row2_price = row2_price[history1_block_bar+1]
#history1_row2_width = min(28, row2_width[history1_block_bar+1])
#history1_row2_y = history1_block_bar <= history1_row2_width ? history1_row2_price : na
#history1_row3_price = row3_price[history1_block_bar+1]
#history1_row3_width = min(28, row3_width[history1_block_bar+1])
#history1_row3_y = history1_block_bar <= history1_row3_width ? history1_row3_price : na
#history1_row4_price = row4_price[history1_block_bar+1]
#history1_row4_width = min(28, row4_width[history1_block_bar+1])
#history1_row4_y = history1_block_bar <= history1_row4_width ? history1_row4_price : na
#history1_row5_price = row5_price[history1_block_bar+1]
#history1_row5_width = min(28, row5_width[history1_block_bar+1])
#history1_row5_y = history1_block_bar <= history1_row5_width ? history1_row5_price : na
#history1_row6_price = row6_price[history1_block_bar+1]
#history1_row6_width = min(28, row6_width[history1_block_bar+1])
#history1_row6_y = history1_block_bar <= history1_row6_width ? history1_row6_price : na
#history1_row7_price = row7_price[history1_block_bar+1]
#history1_row7_width = min(28, row7_width[history1_block_bar+1])
#history1_row7_y = history1_block_bar <= history1_row7_width ? history1_row7_price : na
#history1_row8_price = row8_price[history1_block_bar+1]
#history1_row8_width = min(28, row8_width[history1_block_bar+1])
#history1_row8_y = history1_block_bar <= history1_row8_width ? history1_row8_price : na
#history1_row9_price = row9_price[history1_block_bar+1]
#history1_row9_width = min(28, row9_width[history1_block_bar+1])
#history1_row9_y = history1_block_bar <= history1_row9_width ? history1_row9_price : na
#history1_row10_price = row10_price[history1_block_bar+1]
#history1_row10_width = min(28, row10_width[history1_block_bar+1])
#history1_row10_y = history1_block_bar <= history1_row10_width ? history1_row10_price : na
#history1_row11_price = row11_price[history1_block_bar+1]
#history1_row11_width = min(28, row11_width[history1_block_bar+1])
#history1_row11_y = history1_block_bar <= history1_row11_width ? history1_row11_price : na
#history1_row12_price = row12_price[history1_block_bar+1]
#history1_row12_width = min(28, row12_width[history1_block_bar+1])
#history1_row12_y = history1_block_bar <= history1_row12_width ? history1_row12_price : na
#history1_row13_price = row13_price[history1_block_bar+1]
#history1_row13_width = min(28, row13_width[history1_block_bar+1])
#history1_row13_y = history1_block_bar <= history1_row13_width ? history1_row13_price : na
#history1_row14_price = row14_price[history1_block_bar+1]
#history1_row14_width = min(28, row14_width[history1_block_bar+1])
#history1_row14_y = history1_block_bar <= history1_row14_width ? history1_row14_price : na
#
#plot(history1_row0_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 0")
#plot(history1_row1_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 1")
#plot(history1_row2_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 2")
#plot(history1_row3_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 3")
#plot(history1_row4_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 4")
#plot(history1_row5_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 5")
#plot(history1_row6_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 6")
#plot(history1_row7_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 7")
#plot(history1_row8_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 8")
#plot(history1_row9_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 9")
#plot(history1_row10_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 10")
#plot(history1_row11_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 11")
#plot(history1_row12_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 12")
#plot(history1_row13_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 13")
#plot(history1_row14_y, color=PROFILE1_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 1 row 14")

#history2_block_bar = (block_index + 2) % 2 * block_size + block_bar

#history2_row0_price = row0_price[history2_block_bar+1]
#history2_row0_width = min(28, row0_width[history2_block_bar+1])
#history2_row0_y = history2_block_bar <= history2_row0_width ? history2_row0_price : na
#history2_row1_price = row1_price[history2_block_bar+1]
#history2_row1_width = min(28, row1_width[history2_block_bar+1])
#history2_row1_y = history2_block_bar <= history2_row1_width ? history2_row1_price : na
#history2_row2_price = row2_price[history2_block_bar+1]
#history2_row2_width = min(28, row2_width[history2_block_bar+1])
#history2_row2_y = history2_block_bar <= history2_row2_width ? history2_row2_price : na
#history2_row3_price = row3_price[history2_block_bar+1]
#history2_row3_width = min(28, row3_width[history2_block_bar+1])
#history2_row3_y = history2_block_bar <= history2_row3_width ? history2_row3_price : na
#history2_row4_price = row4_price[history2_block_bar+1]
#history2_row4_width = min(28, row4_width[history2_block_bar+1])
#history2_row4_y = history2_block_bar <= history2_row4_width ? history2_row4_price : na
#history2_row5_price = row5_price[history2_block_bar+1]
#history2_row5_width = min(28, row5_width[history2_block_bar+1])
#history2_row5_y = history2_block_bar <= history2_row5_width ? history2_row5_price : na
#history2_row6_price = row6_price[history2_block_bar+1]
#history2_row6_width = min(28, row6_width[history2_block_bar+1])
#history2_row6_y = history2_block_bar <= history2_row6_width ? history2_row6_price : na
#history2_row7_price = row7_price[history2_block_bar+1]
#history2_row7_width = min(28, row7_width[history2_block_bar+1])
#history2_row7_y = history2_block_bar <= history2_row7_width ? history2_row7_price : na
#history2_row8_price = row8_price[history2_block_bar+1]
#history2_row8_width = min(28, row8_width[history2_block_bar+1])
#history2_row8_y = history2_block_bar <= history2_row8_width ? history2_row8_price : na
#history2_row9_price = row9_price[history2_block_bar+1]
#history2_row9_width = min(28, row9_width[history2_block_bar+1])
#history2_row9_y = history2_block_bar <= history2_row9_width ? history2_row9_price : na
#history2_row10_price = row10_price[history2_block_bar+1]
#history2_row10_width = min(28, row10_width[history2_block_bar+1])
#history2_row10_y = history2_block_bar <= history2_row10_width ? history2_row10_price : na
#history2_row11_price = row11_price[history2_block_bar+1]
#history2_row11_width = min(28, row11_width[history2_block_bar+1])
#history2_row11_y = history2_block_bar <= history2_row11_width ? history2_row11_price : na
#history2_row12_price = row12_price[history2_block_bar+1]
#history2_row12_width = min(28, row12_width[history2_block_bar+1])
#history2_row12_y = history2_block_bar <= history2_row12_width ? history2_row12_price : na
#history2_row13_price = row13_price[history2_block_bar+1]
#history2_row13_width = min(28, row13_width[history2_block_bar+1])
#history2_row13_y = history2_block_bar <= history2_row13_width ? history2_row13_price : na
#history2_row14_price = row14_price[history2_block_bar+1]
#history2_row14_width = min(28, row14_width[history2_block_bar+1])
#history2_row14_y = history2_block_bar <= history2_row14_width ? history2_row14_price : na

#plot(history2_row0_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 0")
#plot(history2_row1_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 1")
#plot(history2_row2_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 2")
#plot(history2_row3_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 3")
#plot(history2_row4_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 4")
#plot(history2_row5_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 5")
#plot(history2_row6_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 6")
#plot(history2_row7_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 7")
#plot(history2_row8_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 8")
#plot(history2_row9_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 9")
#plot(history2_row10_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 10")
#plot(history2_row11_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 11")
#plot(history2_row12_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 12")
#plot(history2_row13_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 13")
#plot(history2_row14_y, color=PROFILE2_COLOR, style=plot.style_linebr, linewidth=2, offset=-block_size*2, title="History 2 row 14")


#// draw vpoc

#vpoc_y = show_vpoc ? vpoc_price : na
#plotshape(vpoc_y, title="VPoC", location=location.absolute, color=VPOC_COLOR, style=shape.diamond, size=size.tiny, offset=-block_size*2)

#////
#// Caclulate and draw last three blocks
#///

#var line recent0_high_line = na
#var line recent0_low_line = na

#var label recent0_vpoc_label = na

#var line recent0_row0_line = na
#var line recent0_row1_line = na
#var line recent0_row2_line = na
#var line recent0_row3_line = na
#var line recent0_row4_line = na
#var line recent0_row5_line = na
#var line recent0_row6_line = na
#var line recent0_row7_line = na
#var line recent0_row8_line = na
#var line recent0_row9_line = na
#var line recent0_row10_line = na
#var line recent0_row11_line = na
#var line recent0_row12_line = na
#var line recent0_row13_line = na
#var line recent0_row14_line = na
#var line recent1_high_line = na
#var line recent1_low_line = na
#
#var label recent1_vpoc_label = na
#
#var line recent1_row0_line = na
#var line recent1_row1_line = na
#var line recent1_row2_line = na
#var line recent1_row3_line = na
#var line recent1_row4_line = na
#var line recent1_row5_line = na
#var line recent1_row6_line = na
#var line recent1_row7_line = na
#var line recent1_row8_line = na
#var line recent1_row9_line = na
#var line recent1_row10_line = na
#var line recent1_row11_line = na
#var line recent1_row12_line = na
#var line recent1_row13_line = na
#var line recent1_row14_line = na
#var line recent2_high_line = na
#var line recent2_low_line = na
#
#var line recent2_row0_line = na
#var line recent2_row1_line = na
#var line recent2_row2_line = na
#var line recent2_row3_line = na
#var line recent2_row4_line = na
#var line recent2_row5_line = na
#var line recent2_row6_line = na
#var line recent2_row7_line = na
#var line recent2_row8_line = na
#var line recent2_row9_line = na
#var line recent2_row10_line = na
#var line recent2_row11_line = na
#var line recent2_row12_line = na
#var line recent2_row13_line = na
#var line recent2_row14_line = na
#
#if barstate.islast
#    recent0_start_i = block_size * 0 + block_bar
#    recent0_end_i = max(block_size * 0 - (block_size - block_bar) + 1, 0)
#
#    recent0_color_n = (block_index[recent0_end_i] + 3) % 2
#    recent0_color = if recent0_color_n == 0
#        color.purple
#    else if recent0_color_n == 1
#        color.teal
#
#    if not na(time[recent0_start_i]) and recent0_start_i - recent0_end_i > 5
#
#        // high/low bounds
#
#        if na(recent0_low_line)
#            recent0_low_line := line.new(bar_index, high, bar_index, high, color=BOUNARY_COLOR)
#        if na(recent0_high_line)
#            recent0_high_line := line.new(bar_index, low, bar_index, low, color=BOUNARY_COLOR)
#
#        recent0_block_high = rolling_high[recent0_end_i]
#        recent0_block_low = rolling_low[recent0_end_i]
#
#        line.set_xloc(recent0_low_line, time[recent0_start_i], time[recent0_end_i], xloc.bar_time)
#        line.set_y1(recent0_low_line, recent0_block_low)
#        line.set_y2(recent0_low_line, recent0_block_low)
#
#        line.set_xloc(recent0_high_line, time[recent0_start_i], time[recent0_end_i], xloc.bar_time)
#        line.set_y1(recent0_high_line, recent0_block_high)
#        line.set_y2(recent0_high_line, recent0_block_high)
#
#        // calculate profile rows
#
#        recent0_block_height = recent0_block_high - recent0_block_low
#        recent0_row_height = recent0_block_height / 15
#
#        recent0_row0_low = recent0_block_low + recent0_row_height * 0
#        recent0_row0_high = recent0_block_low + recent0_row_height * 1
#        recent0_row0_value = 0.0
#        recent0_row1_low = recent0_block_low + recent0_row_height * 1
#        recent0_row1_high = recent0_block_low + recent0_row_height * 2
#        recent0_row1_value = 0.0
#        recent0_row2_low = recent0_block_low + recent0_row_height * 2
#        recent0_row2_high = recent0_block_low + recent0_row_height * 3
#        recent0_row2_value = 0.0
#        recent0_row3_low = recent0_block_low + recent0_row_height * 3
#        recent0_row3_high = recent0_block_low + recent0_row_height * 4
#        recent0_row3_value = 0.0
#        recent0_row4_low = recent0_block_low + recent0_row_height * 4
#        recent0_row4_high = recent0_block_low + recent0_row_height * 5
#        recent0_row4_value = 0.0
#        recent0_row5_low = recent0_block_low + recent0_row_height * 5
#        recent0_row5_high = recent0_block_low + recent0_row_height * 6
#        recent0_row5_value = 0.0
#        recent0_row6_low = recent0_block_low + recent0_row_height * 6
#        recent0_row6_high = recent0_block_low + recent0_row_height * 7
#        recent0_row6_value = 0.0
#        recent0_row7_low = recent0_block_low + recent0_row_height * 7
#        recent0_row7_high = recent0_block_low + recent0_row_height * 8
#        recent0_row7_value = 0.0
#        recent0_row8_low = recent0_block_low + recent0_row_height * 8
#        recent0_row8_high = recent0_block_low + recent0_row_height * 9
#        recent0_row8_value = 0.0
#        recent0_row9_low = recent0_block_low + recent0_row_height * 9
#        recent0_row9_high = recent0_block_low + recent0_row_height * 10
#        recent0_row9_value = 0.0
#        recent0_row10_low = recent0_block_low + recent0_row_height * 10
#        recent0_row10_high = recent0_block_low + recent0_row_height * 11
#        recent0_row10_value = 0.0
#        recent0_row11_low = recent0_block_low + recent0_row_height * 11
#        recent0_row11_high = recent0_block_low + recent0_row_height * 12
#        recent0_row11_value = 0.0
#        recent0_row12_low = recent0_block_low + recent0_row_height * 12
#        recent0_row12_high = recent0_block_low + recent0_row_height * 13
#        recent0_row12_value = 0.0
#        recent0_row13_low = recent0_block_low + recent0_row_height * 13
#        recent0_row13_high = recent0_block_low + recent0_row_height * 14
#        recent0_row13_value = 0.0
#        recent0_row14_low = recent0_block_low + recent0_row_height * 14
#        recent0_row14_high = recent0_block_low + recent0_row_height * 15
#        recent0_row14_value = 0.0
#
#        for i = recent0_start_i to recent0_end_i + 1
#            bar_n_rows_affected = 0
#            bar_row0_value = 0.0
#            if low[i] < recent0_row0_high and high[i] > recent0_row0_low
#                bar_row0_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row1_value = 0.0
#            if low[i] < recent0_row1_high and high[i] > recent0_row1_low
#                bar_row1_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row2_value = 0.0
#            if low[i] < recent0_row2_high and high[i] > recent0_row2_low
#                bar_row2_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row3_value = 0.0
#            if low[i] < recent0_row3_high and high[i] > recent0_row3_low
#                bar_row3_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row4_value = 0.0
#            if low[i] < recent0_row4_high and high[i] > recent0_row4_low
#                bar_row4_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row5_value = 0.0
#            if low[i] < recent0_row5_high and high[i] > recent0_row5_low
#                bar_row5_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row6_value = 0.0
#            if low[i] < recent0_row6_high and high[i] > recent0_row6_low
#                bar_row6_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row7_value = 0.0
#            if low[i] < recent0_row7_high and high[i] > recent0_row7_low
#                bar_row7_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row8_value = 0.0
#            if low[i] < recent0_row8_high and high[i] > recent0_row8_low
#                bar_row8_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row9_value = 0.0
#            if low[i] < recent0_row9_high and high[i] > recent0_row9_low
#                bar_row9_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row10_value = 0.0
#            if low[i] < recent0_row10_high and high[i] > recent0_row10_low
#                bar_row10_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row11_value = 0.0
#            if low[i] < recent0_row11_high and high[i] > recent0_row11_low
#                bar_row11_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row12_value = 0.0
#            if low[i] < recent0_row12_high and high[i] > recent0_row12_low
#                bar_row12_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row13_value = 0.0
#            if low[i] < recent0_row13_high and high[i] > recent0_row13_low
#                bar_row13_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row14_value = 0.0
#            if low[i] < recent0_row14_high and high[i] > recent0_row14_low
#                bar_row14_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#
#            recent0_row0_value := recent0_row0_value + bar_row0_value / bar_n_rows_affected / recent0_row_height
#            recent0_row1_value := recent0_row1_value + bar_row1_value / bar_n_rows_affected / recent0_row_height
#            recent0_row2_value := recent0_row2_value + bar_row2_value / bar_n_rows_affected / recent0_row_height
#            recent0_row3_value := recent0_row3_value + bar_row3_value / bar_n_rows_affected / recent0_row_height
#            recent0_row4_value := recent0_row4_value + bar_row4_value / bar_n_rows_affected / recent0_row_height
#            recent0_row5_value := recent0_row5_value + bar_row5_value / bar_n_rows_affected / recent0_row_height
#            recent0_row6_value := recent0_row6_value + bar_row6_value / bar_n_rows_affected / recent0_row_height
#            recent0_row7_value := recent0_row7_value + bar_row7_value / bar_n_rows_affected / recent0_row_height
#            recent0_row8_value := recent0_row8_value + bar_row8_value / bar_n_rows_affected / recent0_row_height
#            recent0_row9_value := recent0_row9_value + bar_row9_value / bar_n_rows_affected / recent0_row_height
#            recent0_row10_value := recent0_row10_value + bar_row10_value / bar_n_rows_affected / recent0_row_height
#            recent0_row11_value := recent0_row11_value + bar_row11_value / bar_n_rows_affected / recent0_row_height
#            recent0_row12_value := recent0_row12_value + bar_row12_value / bar_n_rows_affected / recent0_row_height
#            recent0_row13_value := recent0_row13_value + bar_row13_value / bar_n_rows_affected / recent0_row_height
#            recent0_row14_value := recent0_row14_value + bar_row14_value / bar_n_rows_affected / recent0_row_height
#
#        recent0_avg_i = min(recent0_start_i + 1 + block_size * 2, bar_index)
#        recent0_row0_price = (recent0_row0_low + recent0_row0_high ) / 2
#        recent0_row0_width = floor(visual_row_width * recent0_row0_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row1_price = (recent0_row1_low + recent0_row1_high ) / 2
#        recent0_row1_width = floor(visual_row_width * recent0_row1_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row2_price = (recent0_row2_low + recent0_row2_high ) / 2
#        recent0_row2_width = floor(visual_row_width * recent0_row2_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row3_price = (recent0_row3_low + recent0_row3_high ) / 2
#        recent0_row3_width = floor(visual_row_width * recent0_row3_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row4_price = (recent0_row4_low + recent0_row4_high ) / 2
#        recent0_row4_width = floor(visual_row_width * recent0_row4_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row5_price = (recent0_row5_low + recent0_row5_high ) / 2
#        recent0_row5_width = floor(visual_row_width * recent0_row5_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row6_price = (recent0_row6_low + recent0_row6_high ) / 2
#        recent0_row6_width = floor(visual_row_width * recent0_row6_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row7_price = (recent0_row7_low + recent0_row7_high ) / 2
#        recent0_row7_width = floor(visual_row_width * recent0_row7_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row8_price = (recent0_row8_low + recent0_row8_high ) / 2
#        recent0_row8_width = floor(visual_row_width * recent0_row8_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row9_price = (recent0_row9_low + recent0_row9_high ) / 2
#        recent0_row9_width = floor(visual_row_width * recent0_row9_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row10_price = (recent0_row10_low + recent0_row10_high ) / 2
#        recent0_row10_width = floor(visual_row_width * recent0_row10_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row11_price = (recent0_row11_low + recent0_row11_high ) / 2
#        recent0_row11_width = floor(visual_row_width * recent0_row11_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row12_price = (recent0_row12_low + recent0_row12_high ) / 2
#        recent0_row12_width = floor(visual_row_width * recent0_row12_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row13_price = (recent0_row13_low + recent0_row13_high ) / 2
#        recent0_row13_width = floor(visual_row_width * recent0_row13_value / highest_row_value_avg[recent0_avg_i])
#        recent0_row14_price = (recent0_row14_low + recent0_row14_high ) / 2
#        recent0_row14_width = floor(visual_row_width * recent0_row14_value / highest_row_value_avg[recent0_avg_i])
#
#        // calculate vpoc
#
#        float recent0_vpoc_price = na
#        float recent0_highes_row_value = 0
#        if recent0_highes_row_value < recent0_row0_value
#            recent0_highes_row_value := recent0_row0_value
#            recent0_vpoc_price := recent0_row0_price
#        if recent0_highes_row_value < recent0_row1_value
#            recent0_highes_row_value := recent0_row1_value
#            recent0_vpoc_price := recent0_row1_price
#        if recent0_highes_row_value < recent0_row2_value
#            recent0_highes_row_value := recent0_row2_value
#            recent0_vpoc_price := recent0_row2_price
#        if recent0_highes_row_value < recent0_row3_value
#            recent0_highes_row_value := recent0_row3_value
#            recent0_vpoc_price := recent0_row3_price
#        if recent0_highes_row_value < recent0_row4_value
#            recent0_highes_row_value := recent0_row4_value
#            recent0_vpoc_price := recent0_row4_price
#        if recent0_highes_row_value < recent0_row5_value
#            recent0_highes_row_value := recent0_row5_value
#            recent0_vpoc_price := recent0_row5_price
#        if recent0_highes_row_value < recent0_row6_value
#            recent0_highes_row_value := recent0_row6_value
#            recent0_vpoc_price := recent0_row6_price
#        if recent0_highes_row_value < recent0_row7_value
#            recent0_highes_row_value := recent0_row7_value
#            recent0_vpoc_price := recent0_row7_price
#        if recent0_highes_row_value < recent0_row8_value
#            recent0_highes_row_value := recent0_row8_value
#            recent0_vpoc_price := recent0_row8_price
#        if recent0_highes_row_value < recent0_row9_value
#            recent0_highes_row_value := recent0_row9_value
#            recent0_vpoc_price := recent0_row9_price
#        if recent0_highes_row_value < recent0_row10_value
#            recent0_highes_row_value := recent0_row10_value
#            recent0_vpoc_price := recent0_row10_price
#        if recent0_highes_row_value < recent0_row11_value
#            recent0_highes_row_value := recent0_row11_value
#            recent0_vpoc_price := recent0_row11_price
#        if recent0_highes_row_value < recent0_row12_value
#            recent0_highes_row_value := recent0_row12_value
#            recent0_vpoc_price := recent0_row12_price
#        if recent0_highes_row_value < recent0_row13_value
#            recent0_highes_row_value := recent0_row13_value
#            recent0_vpoc_price := recent0_row13_price
#        if recent0_highes_row_value < recent0_row14_value
#            recent0_highes_row_value := recent0_row14_value
#            recent0_vpoc_price := recent0_row14_price
#
#        // draw profile rows
#
#        if na(recent0_row0_line)
#            recent0_row0_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row1_line)
#            recent0_row1_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row2_line)
#            recent0_row2_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row3_line)
#            recent0_row3_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row4_line)
#            recent0_row4_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row5_line)
#            recent0_row5_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row6_line)
#            recent0_row6_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row7_line)
#            recent0_row7_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row8_line)
#            recent0_row8_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row9_line)
#            recent0_row9_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row10_line)
#            recent0_row10_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row11_line)
#            recent0_row11_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row12_line)
#            recent0_row12_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row13_line)
#            recent0_row13_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent0_row14_line)
#            recent0_row14_line := line.new(bar_index, close, bar_index, close, width=2)
#
#
#        line.set_xloc(recent0_row0_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row0_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row0_line, recent0_row0_price)
#        line.set_y2(recent0_row0_line, recent0_row0_price)
#        line.set_color(recent0_row0_line, recent0_color)
#
#        line.set_xloc(recent0_row1_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row1_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row1_line, recent0_row1_price)
#        line.set_y2(recent0_row1_line, recent0_row1_price)
#        line.set_color(recent0_row1_line, recent0_color)
#
#        line.set_xloc(recent0_row2_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row2_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row2_line, recent0_row2_price)
#        line.set_y2(recent0_row2_line, recent0_row2_price)
#        line.set_color(recent0_row2_line, recent0_color)
#
#        line.set_xloc(recent0_row3_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row3_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row3_line, recent0_row3_price)
#        line.set_y2(recent0_row3_line, recent0_row3_price)
#        line.set_color(recent0_row3_line, recent0_color)
#
#        line.set_xloc(recent0_row4_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row4_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row4_line, recent0_row4_price)
#        line.set_y2(recent0_row4_line, recent0_row4_price)
#        line.set_color(recent0_row4_line, recent0_color)
#
#        line.set_xloc(recent0_row5_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row5_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row5_line, recent0_row5_price)
#        line.set_y2(recent0_row5_line, recent0_row5_price)
#        line.set_color(recent0_row5_line, recent0_color)
#
#        line.set_xloc(recent0_row6_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row6_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row6_line, recent0_row6_price)
#        line.set_y2(recent0_row6_line, recent0_row6_price)
#        line.set_color(recent0_row6_line, recent0_color)
#
#        line.set_xloc(recent0_row7_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row7_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row7_line, recent0_row7_price)
#        line.set_y2(recent0_row7_line, recent0_row7_price)
#        line.set_color(recent0_row7_line, recent0_color)
#
#        line.set_xloc(recent0_row8_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row8_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row8_line, recent0_row8_price)
#        line.set_y2(recent0_row8_line, recent0_row8_price)
#        line.set_color(recent0_row8_line, recent0_color)
#
#        line.set_xloc(recent0_row9_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row9_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row9_line, recent0_row9_price)
#        line.set_y2(recent0_row9_line, recent0_row9_price)
#        line.set_color(recent0_row9_line, recent0_color)
#
#        line.set_xloc(recent0_row10_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row10_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row10_line, recent0_row10_price)
#        line.set_y2(recent0_row10_line, recent0_row10_price)
#        line.set_color(recent0_row10_line, recent0_color)
#
#        line.set_xloc(recent0_row11_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row11_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row11_line, recent0_row11_price)
#        line.set_y2(recent0_row11_line, recent0_row11_price)
#        line.set_color(recent0_row11_line, recent0_color)
#
#        line.set_xloc(recent0_row12_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row12_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row12_line, recent0_row12_price)
#        line.set_y2(recent0_row12_line, recent0_row12_price)
#        line.set_color(recent0_row12_line, recent0_color)
#
#        line.set_xloc(recent0_row13_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row13_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row13_line, recent0_row13_price)
#        line.set_y2(recent0_row13_line, recent0_row13_price)
#        line.set_color(recent0_row13_line, recent0_color)
#
#        line.set_xloc(recent0_row14_line, time[recent0_start_i], time_close[max(recent0_start_i - recent0_row14_width, 0)], xloc.bar_time)
#        line.set_y1(recent0_row14_line, recent0_row14_price)
#        line.set_y2(recent0_row14_line, recent0_row14_price)
#        line.set_color(recent0_row14_line, recent0_color)
#
#
#        // draw vpoc
#
#        if show_vpoc
#            if na(recent0_vpoc_label)
#                recent0_vpoc_label := label.new(bar_index, close, yloc=yloc.price, style=label.style_diamond, size=size.tiny, color=VPOC_COLOR)
#
#            label.set_xloc(recent0_vpoc_label, time[recent0_start_i + 1], xloc.bar_time)
#            label.set_y(recent0_vpoc_label, recent0_vpoc_price)
#
#        if not show_vpoc and not na(recent0_vpoc_label)
#            label.delete(recent0_vpoc_label)
#            recent0_vpoc_label := na
#
#        0
#
#    else
#
#        // remove unused lines
#
#        if not na(recent0_low_line)
#            line.delete(recent0_low_line)
#            recent0_low_line := na
#        if not na(recent0_high_line)
#            line.delete(recent0_high_line)
#            recent0_high_line := na
#
#        if not na(recent0_vpoc_label)
#            label.delete(recent0_vpoc_label)
#            recent0_vpoc_label := na
#
#        if not na(recent0_row0_line)
#            line.delete(recent0_row0_line)
#            recent0_row0_line := na
#        if not na(recent0_row1_line)
#            line.delete(recent0_row1_line)
#            recent0_row1_line := na
#        if not na(recent0_row2_line)
#            line.delete(recent0_row2_line)
#            recent0_row2_line := na
#        if not na(recent0_row3_line)
#            line.delete(recent0_row3_line)
#            recent0_row3_line := na
#        if not na(recent0_row4_line)
#            line.delete(recent0_row4_line)
#            recent0_row4_line := na
#        if not na(recent0_row5_line)
#            line.delete(recent0_row5_line)
#            recent0_row5_line := na
#        if not na(recent0_row6_line)
#            line.delete(recent0_row6_line)
#            recent0_row6_line := na
#        if not na(recent0_row7_line)
#            line.delete(recent0_row7_line)
#            recent0_row7_line := na
#        if not na(recent0_row8_line)
#            line.delete(recent0_row8_line)
#            recent0_row8_line := na
#        if not na(recent0_row9_line)
#            line.delete(recent0_row9_line)
#            recent0_row9_line := na
#        if not na(recent0_row10_line)
#            line.delete(recent0_row10_line)
#            recent0_row10_line := na
#        if not na(recent0_row11_line)
#            line.delete(recent0_row11_line)
#            recent0_row11_line := na
#        if not na(recent0_row12_line)
#            line.delete(recent0_row12_line)
#            recent0_row12_line := na
#        if not na(recent0_row13_line)
#            line.delete(recent0_row13_line)
#            recent0_row13_line := na
#        if not na(recent0_row14_line)
#            line.delete(recent0_row14_line)
#            recent0_row14_line := na
#
#        0
#
#    recent1_start_i = block_size * 1 + block_bar
#    recent1_end_i = max(block_size * 1 - (block_size - block_bar) + 1, 0)
#
#    recent1_color_n = (block_index[recent1_end_i] + 3) % 2
#    recent1_color = if recent1_color_n == 0
#        color.purple
#    else if recent1_color_n == 1
#        color.teal
#
#    if not na(time[recent1_start_i]) and recent1_start_i - recent1_end_i > 5
#
#        // high/low bounds
#
#        if na(recent1_low_line)
#            recent1_low_line := line.new(bar_index, high, bar_index, high, color=BOUNARY_COLOR)
#        if na(recent1_high_line)
#            recent1_high_line := line.new(bar_index, low, bar_index, low, color=BOUNARY_COLOR)
#
#        recent1_block_high = rolling_high[recent1_end_i]
#        recent1_block_low = rolling_low[recent1_end_i]
#
#        line.set_xloc(recent1_low_line, time[recent1_start_i], time[recent1_end_i], xloc.bar_time)
#        line.set_y1(recent1_low_line, recent1_block_low)
#        line.set_y2(recent1_low_line, recent1_block_low)
#
#        line.set_xloc(recent1_high_line, time[recent1_start_i], time[recent1_end_i], xloc.bar_time)
#        line.set_y1(recent1_high_line, recent1_block_high)
#        line.set_y2(recent1_high_line, recent1_block_high)
#
#        // calculate profile rows
#
#        recent1_block_height = recent1_block_high - recent1_block_low
#        recent1_row_height = recent1_block_height / 15
#
#        recent1_row0_low = recent1_block_low + recent1_row_height * 0
#        recent1_row0_high = recent1_block_low + recent1_row_height * 1
#        recent1_row0_value = 0.0
#        recent1_row1_low = recent1_block_low + recent1_row_height * 1
#        recent1_row1_high = recent1_block_low + recent1_row_height * 2
#        recent1_row1_value = 0.0
#        recent1_row2_low = recent1_block_low + recent1_row_height * 2
#        recent1_row2_high = recent1_block_low + recent1_row_height * 3
#        recent1_row2_value = 0.0
#        recent1_row3_low = recent1_block_low + recent1_row_height * 3
#        recent1_row3_high = recent1_block_low + recent1_row_height * 4
#        recent1_row3_value = 0.0
#        recent1_row4_low = recent1_block_low + recent1_row_height * 4
#        recent1_row4_high = recent1_block_low + recent1_row_height * 5
#        recent1_row4_value = 0.0
#        recent1_row5_low = recent1_block_low + recent1_row_height * 5
#        recent1_row5_high = recent1_block_low + recent1_row_height * 6
#        recent1_row5_value = 0.0
#        recent1_row6_low = recent1_block_low + recent1_row_height * 6
#        recent1_row6_high = recent1_block_low + recent1_row_height * 7
#        recent1_row6_value = 0.0
#        recent1_row7_low = recent1_block_low + recent1_row_height * 7
#        recent1_row7_high = recent1_block_low + recent1_row_height * 8
#        recent1_row7_value = 0.0
#        recent1_row8_low = recent1_block_low + recent1_row_height * 8
#        recent1_row8_high = recent1_block_low + recent1_row_height * 9
#        recent1_row8_value = 0.0
#        recent1_row9_low = recent1_block_low + recent1_row_height * 9
#        recent1_row9_high = recent1_block_low + recent1_row_height * 10
#        recent1_row9_value = 0.0
#        recent1_row10_low = recent1_block_low + recent1_row_height * 10
#        recent1_row10_high = recent1_block_low + recent1_row_height * 11
#        recent1_row10_value = 0.0
#        recent1_row11_low = recent1_block_low + recent1_row_height * 11
#        recent1_row11_high = recent1_block_low + recent1_row_height * 12
#        recent1_row11_value = 0.0
#        recent1_row12_low = recent1_block_low + recent1_row_height * 12
#        recent1_row12_high = recent1_block_low + recent1_row_height * 13
#        recent1_row12_value = 0.0
#        recent1_row13_low = recent1_block_low + recent1_row_height * 13
#        recent1_row13_high = recent1_block_low + recent1_row_height * 14
#        recent1_row13_value = 0.0
#        recent1_row14_low = recent1_block_low + recent1_row_height * 14
#        recent1_row14_high = recent1_block_low + recent1_row_height * 15
#        recent1_row14_value = 0.0
#
#        for i = recent1_start_i to recent1_end_i + 1
#            bar_n_rows_affected = 0
#            bar_row0_value = 0.0
#            if low[i] < recent1_row0_high and high[i] > recent1_row0_low
#                bar_row0_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row1_value = 0.0
#            if low[i] < recent1_row1_high and high[i] > recent1_row1_low
#                bar_row1_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row2_value = 0.0
#            if low[i] < recent1_row2_high and high[i] > recent1_row2_low
#                bar_row2_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row3_value = 0.0
#            if low[i] < recent1_row3_high and high[i] > recent1_row3_low
#                bar_row3_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row4_value = 0.0
#            if low[i] < recent1_row4_high and high[i] > recent1_row4_low
#                bar_row4_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row5_value = 0.0
#            if low[i] < recent1_row5_high and high[i] > recent1_row5_low
#                bar_row5_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row6_value = 0.0
#            if low[i] < recent1_row6_high and high[i] > recent1_row6_low
#                bar_row6_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row7_value = 0.0
#            if low[i] < recent1_row7_high and high[i] > recent1_row7_low
#                bar_row7_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row8_value = 0.0
#            if low[i] < recent1_row8_high and high[i] > recent1_row8_low
#                bar_row8_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row9_value = 0.0
#            if low[i] < recent1_row9_high and high[i] > recent1_row9_low
#                bar_row9_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row10_value = 0.0
#            if low[i] < recent1_row10_high and high[i] > recent1_row10_low
#                bar_row10_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row11_value = 0.0
#            if low[i] < recent1_row11_high and high[i] > recent1_row11_low
#                bar_row11_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row12_value = 0.0
#            if low[i] < recent1_row12_high and high[i] > recent1_row12_low
#                bar_row12_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row13_value = 0.0
#            if low[i] < recent1_row13_high and high[i] > recent1_row13_low
#                bar_row13_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row14_value = 0.0
#            if low[i] < recent1_row14_high and high[i] > recent1_row14_low
#                bar_row14_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#
#            recent1_row0_value := recent1_row0_value + bar_row0_value / bar_n_rows_affected / recent1_row_height
#            recent1_row1_value := recent1_row1_value + bar_row1_value / bar_n_rows_affected / recent1_row_height
#            recent1_row2_value := recent1_row2_value + bar_row2_value / bar_n_rows_affected / recent1_row_height
#            recent1_row3_value := recent1_row3_value + bar_row3_value / bar_n_rows_affected / recent1_row_height
#            recent1_row4_value := recent1_row4_value + bar_row4_value / bar_n_rows_affected / recent1_row_height
#            recent1_row5_value := recent1_row5_value + bar_row5_value / bar_n_rows_affected / recent1_row_height
#            recent1_row6_value := recent1_row6_value + bar_row6_value / bar_n_rows_affected / recent1_row_height
#            recent1_row7_value := recent1_row7_value + bar_row7_value / bar_n_rows_affected / recent1_row_height
#            recent1_row8_value := recent1_row8_value + bar_row8_value / bar_n_rows_affected / recent1_row_height
#            recent1_row9_value := recent1_row9_value + bar_row9_value / bar_n_rows_affected / recent1_row_height
#            recent1_row10_value := recent1_row10_value + bar_row10_value / bar_n_rows_affected / recent1_row_height
#            recent1_row11_value := recent1_row11_value + bar_row11_value / bar_n_rows_affected / recent1_row_height
#            recent1_row12_value := recent1_row12_value + bar_row12_value / bar_n_rows_affected / recent1_row_height
#            recent1_row13_value := recent1_row13_value + bar_row13_value / bar_n_rows_affected / recent1_row_height
#            recent1_row14_value := recent1_row14_value + bar_row14_value / bar_n_rows_affected / recent1_row_height
#
#        recent1_avg_i = min(recent1_start_i + 1 + block_size * 3, bar_index)
#        recent1_row0_price = (recent1_row0_low + recent1_row0_high ) / 2
#        recent1_row0_width = floor(visual_row_width * recent1_row0_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row1_price = (recent1_row1_low + recent1_row1_high ) / 2
#        recent1_row1_width = floor(visual_row_width * recent1_row1_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row2_price = (recent1_row2_low + recent1_row2_high ) / 2
#        recent1_row2_width = floor(visual_row_width * recent1_row2_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row3_price = (recent1_row3_low + recent1_row3_high ) / 2
#        recent1_row3_width = floor(visual_row_width * recent1_row3_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row4_price = (recent1_row4_low + recent1_row4_high ) / 2
#        recent1_row4_width = floor(visual_row_width * recent1_row4_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row5_price = (recent1_row5_low + recent1_row5_high ) / 2
#        recent1_row5_width = floor(visual_row_width * recent1_row5_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row6_price = (recent1_row6_low + recent1_row6_high ) / 2
#        recent1_row6_width = floor(visual_row_width * recent1_row6_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row7_price = (recent1_row7_low + recent1_row7_high ) / 2
#        recent1_row7_width = floor(visual_row_width * recent1_row7_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row8_price = (recent1_row8_low + recent1_row8_high ) / 2
#        recent1_row8_width = floor(visual_row_width * recent1_row8_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row9_price = (recent1_row9_low + recent1_row9_high ) / 2
#        recent1_row9_width = floor(visual_row_width * recent1_row9_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row10_price = (recent1_row10_low + recent1_row10_high ) / 2
#        recent1_row10_width = floor(visual_row_width * recent1_row10_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row11_price = (recent1_row11_low + recent1_row11_high ) / 2
#        recent1_row11_width = floor(visual_row_width * recent1_row11_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row12_price = (recent1_row12_low + recent1_row12_high ) / 2
#        recent1_row12_width = floor(visual_row_width * recent1_row12_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row13_price = (recent1_row13_low + recent1_row13_high ) / 2
#        recent1_row13_width = floor(visual_row_width * recent1_row13_value / highest_row_value_avg[recent1_avg_i])
#        recent1_row14_price = (recent1_row14_low + recent1_row14_high ) / 2
#        recent1_row14_width = floor(visual_row_width * recent1_row14_value / highest_row_value_avg[recent1_avg_i])
#
#        // calculate vpoc
#
#        float recent1_vpoc_price = na
#        float recent1_highes_row_value = 0
#        if recent1_highes_row_value < recent1_row0_value
#            recent1_highes_row_value := recent1_row0_value
#            recent1_vpoc_price := recent1_row0_price
#        if recent1_highes_row_value < recent1_row1_value
#            recent1_highes_row_value := recent1_row1_value
#            recent1_vpoc_price := recent1_row1_price
#        if recent1_highes_row_value < recent1_row2_value
#            recent1_highes_row_value := recent1_row2_value
#            recent1_vpoc_price := recent1_row2_price
#        if recent1_highes_row_value < recent1_row3_value
#            recent1_highes_row_value := recent1_row3_value
#            recent1_vpoc_price := recent1_row3_price
#        if recent1_highes_row_value < recent1_row4_value
#            recent1_highes_row_value := recent1_row4_value
#            recent1_vpoc_price := recent1_row4_price
#        if recent1_highes_row_value < recent1_row5_value
#            recent1_highes_row_value := recent1_row5_value
#            recent1_vpoc_price := recent1_row5_price
#        if recent1_highes_row_value < recent1_row6_value
#            recent1_highes_row_value := recent1_row6_value
#            recent1_vpoc_price := recent1_row6_price
#        if recent1_highes_row_value < recent1_row7_value
#            recent1_highes_row_value := recent1_row7_value
#            recent1_vpoc_price := recent1_row7_price
#        if recent1_highes_row_value < recent1_row8_value
#            recent1_highes_row_value := recent1_row8_value
#            recent1_vpoc_price := recent1_row8_price
#        if recent1_highes_row_value < recent1_row9_value
#            recent1_highes_row_value := recent1_row9_value
#            recent1_vpoc_price := recent1_row9_price
#        if recent1_highes_row_value < recent1_row10_value
#            recent1_highes_row_value := recent1_row10_value
#            recent1_vpoc_price := recent1_row10_price
#        if recent1_highes_row_value < recent1_row11_value
#            recent1_highes_row_value := recent1_row11_value
#            recent1_vpoc_price := recent1_row11_price
#        if recent1_highes_row_value < recent1_row12_value
#            recent1_highes_row_value := recent1_row12_value
#            recent1_vpoc_price := recent1_row12_price
#        if recent1_highes_row_value < recent1_row13_value
#            recent1_highes_row_value := recent1_row13_value
#            recent1_vpoc_price := recent1_row13_price
#        if recent1_highes_row_value < recent1_row14_value
#            recent1_highes_row_value := recent1_row14_value
#            recent1_vpoc_price := recent1_row14_price
#
#        // draw profile rows
#
#        if na(recent1_row0_line)
#            recent1_row0_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row1_line)
#            recent1_row1_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row2_line)
#            recent1_row2_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row3_line)
#            recent1_row3_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row4_line)
#            recent1_row4_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row5_line)
#            recent1_row5_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row6_line)
#            recent1_row6_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row7_line)
#            recent1_row7_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row8_line)
#            recent1_row8_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row9_line)
#            recent1_row9_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row10_line)
#            recent1_row10_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row11_line)
#            recent1_row11_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row12_line)
#            recent1_row12_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row13_line)
#            recent1_row13_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent1_row14_line)
#            recent1_row14_line := line.new(bar_index, close, bar_index, close, width=2)
#
#
#        line.set_xloc(recent1_row0_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row0_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row0_line, recent1_row0_price)
#        line.set_y2(recent1_row0_line, recent1_row0_price)
#        line.set_color(recent1_row0_line, recent1_color)
#
#        line.set_xloc(recent1_row1_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row1_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row1_line, recent1_row1_price)
#        line.set_y2(recent1_row1_line, recent1_row1_price)
#        line.set_color(recent1_row1_line, recent1_color)
#
#        line.set_xloc(recent1_row2_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row2_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row2_line, recent1_row2_price)
#        line.set_y2(recent1_row2_line, recent1_row2_price)
#        line.set_color(recent1_row2_line, recent1_color)
#
#        line.set_xloc(recent1_row3_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row3_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row3_line, recent1_row3_price)
#        line.set_y2(recent1_row3_line, recent1_row3_price)
#        line.set_color(recent1_row3_line, recent1_color)
#
#        line.set_xloc(recent1_row4_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row4_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row4_line, recent1_row4_price)
#        line.set_y2(recent1_row4_line, recent1_row4_price)
#        line.set_color(recent1_row4_line, recent1_color)
#
#        line.set_xloc(recent1_row5_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row5_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row5_line, recent1_row5_price)
#        line.set_y2(recent1_row5_line, recent1_row5_price)
#        line.set_color(recent1_row5_line, recent1_color)
#
#        line.set_xloc(recent1_row6_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row6_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row6_line, recent1_row6_price)
#        line.set_y2(recent1_row6_line, recent1_row6_price)
#        line.set_color(recent1_row6_line, recent1_color)
#
#        line.set_xloc(recent1_row7_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row7_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row7_line, recent1_row7_price)
#        line.set_y2(recent1_row7_line, recent1_row7_price)
#        line.set_color(recent1_row7_line, recent1_color)
#
#        line.set_xloc(recent1_row8_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row8_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row8_line, recent1_row8_price)
#        line.set_y2(recent1_row8_line, recent1_row8_price)
#        line.set_color(recent1_row8_line, recent1_color)
#
#        line.set_xloc(recent1_row9_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row9_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row9_line, recent1_row9_price)
#        line.set_y2(recent1_row9_line, recent1_row9_price)
#        line.set_color(recent1_row9_line, recent1_color)
#
#        line.set_xloc(recent1_row10_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row10_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row10_line, recent1_row10_price)
#        line.set_y2(recent1_row10_line, recent1_row10_price)
#        line.set_color(recent1_row10_line, recent1_color)
#
#        line.set_xloc(recent1_row11_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row11_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row11_line, recent1_row11_price)
#        line.set_y2(recent1_row11_line, recent1_row11_price)
#        line.set_color(recent1_row11_line, recent1_color)
#
#        line.set_xloc(recent1_row12_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row12_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row12_line, recent1_row12_price)
#        line.set_y2(recent1_row12_line, recent1_row12_price)
#        line.set_color(recent1_row12_line, recent1_color)
#
#        line.set_xloc(recent1_row13_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row13_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row13_line, recent1_row13_price)
#        line.set_y2(recent1_row13_line, recent1_row13_price)
#        line.set_color(recent1_row13_line, recent1_color)
#
#        line.set_xloc(recent1_row14_line, time[recent1_start_i], time_close[max(recent1_start_i - recent1_row14_width, 0)], xloc.bar_time)
#        line.set_y1(recent1_row14_line, recent1_row14_price)
#        line.set_y2(recent1_row14_line, recent1_row14_price)
#        line.set_color(recent1_row14_line, recent1_color)
#
#
#        // draw vpoc
#
#        if show_vpoc
#            if na(recent1_vpoc_label)
#                recent1_vpoc_label := label.new(bar_index, close, yloc=yloc.price, style=label.style_diamond, size=size.tiny, color=VPOC_COLOR)
#
#            label.set_xloc(recent1_vpoc_label, time[recent1_start_i + 1], xloc.bar_time)
#            label.set_y(recent1_vpoc_label, recent1_vpoc_price)
#
#        if not show_vpoc and not na(recent1_vpoc_label)
#            label.delete(recent1_vpoc_label)
#            recent1_vpoc_label := na
#
#        0
#
#    else
#
#        // remove unused lines
#
#        if not na(recent1_low_line)
#            line.delete(recent1_low_line)
#            recent1_low_line := na
#        if not na(recent1_high_line)
#            line.delete(recent1_high_line)
#            recent1_high_line := na
#
#        if not na(recent1_vpoc_label)
#            label.delete(recent1_vpoc_label)
#            recent1_vpoc_label := na
#
#        if not na(recent1_row0_line)
#            line.delete(recent1_row0_line)
#            recent1_row0_line := na
#        if not na(recent1_row1_line)
#            line.delete(recent1_row1_line)
#            recent1_row1_line := na
#        if not na(recent1_row2_line)
#            line.delete(recent1_row2_line)
#            recent1_row2_line := na
#        if not na(recent1_row3_line)
#            line.delete(recent1_row3_line)
#            recent1_row3_line := na
#        if not na(recent1_row4_line)
#            line.delete(recent1_row4_line)
#            recent1_row4_line := na
#        if not na(recent1_row5_line)
#            line.delete(recent1_row5_line)
#            recent1_row5_line := na
#        if not na(recent1_row6_line)
#            line.delete(recent1_row6_line)
#            recent1_row6_line := na
#        if not na(recent1_row7_line)
#            line.delete(recent1_row7_line)
#            recent1_row7_line := na
#        if not na(recent1_row8_line)
#            line.delete(recent1_row8_line)
#            recent1_row8_line := na
#        if not na(recent1_row9_line)
#            line.delete(recent1_row9_line)
#            recent1_row9_line := na
#        if not na(recent1_row10_line)
#            line.delete(recent1_row10_line)
#            recent1_row10_line := na
#        if not na(recent1_row11_line)
#            line.delete(recent1_row11_line)
#            recent1_row11_line := na
#        if not na(recent1_row12_line)
#            line.delete(recent1_row12_line)
#            recent1_row12_line := na
#        if not na(recent1_row13_line)
#            line.delete(recent1_row13_line)
#            recent1_row13_line := na
#        if not na(recent1_row14_line)
#            line.delete(recent1_row14_line)
#            recent1_row14_line := na
#
#        0
#
#    recent2_start_i = block_size * 2 + block_bar
#    recent2_end_i = max(block_size * 2 - (block_size - block_bar) + 1, 0)
#
#    recent2_color_n = (block_index[recent2_end_i] + 3) % 2
#    recent2_color = if recent2_color_n == 0
#        color.purple
#    else if recent2_color_n == 1
#        color.teal
#
#    if not na(time[recent2_start_i]) and recent2_start_i - recent2_end_i > 5
#
#        // high/low bounds
#
#        if na(recent2_low_line)
#            recent2_low_line := line.new(bar_index, high, bar_index, high, color=BOUNARY_COLOR)
#        if na(recent2_high_line)
#            recent2_high_line := line.new(bar_index, low, bar_index, low, color=BOUNARY_COLOR)
#
#        recent2_block_high = rolling_high[recent2_end_i]
#        recent2_block_low = rolling_low[recent2_end_i]
#
#        line.set_xloc(recent2_low_line, time[recent2_start_i], time[recent2_end_i], xloc.bar_time)
#        line.set_y1(recent2_low_line, recent2_block_low)
#        line.set_y2(recent2_low_line, recent2_block_low)
#
#        line.set_xloc(recent2_high_line, time[recent2_start_i], time[recent2_end_i], xloc.bar_time)
#        line.set_y1(recent2_high_line, recent2_block_high)
#        line.set_y2(recent2_high_line, recent2_block_high)
#
#        // calculate profile rows
#
#        recent2_block_height = recent2_block_high - recent2_block_low
#        recent2_row_height = recent2_block_height / 15
#
#        recent2_row0_low = recent2_block_low + recent2_row_height * 0
#        recent2_row0_high = recent2_block_low + recent2_row_height * 1
#        recent2_row0_value = 0.0
#        recent2_row1_low = recent2_block_low + recent2_row_height * 1
#        recent2_row1_high = recent2_block_low + recent2_row_height * 2
#        recent2_row1_value = 0.0
#        recent2_row2_low = recent2_block_low + recent2_row_height * 2
#        recent2_row2_high = recent2_block_low + recent2_row_height * 3
#        recent2_row2_value = 0.0
#        recent2_row3_low = recent2_block_low + recent2_row_height * 3
#        recent2_row3_high = recent2_block_low + recent2_row_height * 4
#        recent2_row3_value = 0.0
#        recent2_row4_low = recent2_block_low + recent2_row_height * 4
#        recent2_row4_high = recent2_block_low + recent2_row_height * 5
#        recent2_row4_value = 0.0
#        recent2_row5_low = recent2_block_low + recent2_row_height * 5
#        recent2_row5_high = recent2_block_low + recent2_row_height * 6
#        recent2_row5_value = 0.0
#        recent2_row6_low = recent2_block_low + recent2_row_height * 6
#        recent2_row6_high = recent2_block_low + recent2_row_height * 7
#        recent2_row6_value = 0.0
#        recent2_row7_low = recent2_block_low + recent2_row_height * 7
#        recent2_row7_high = recent2_block_low + recent2_row_height * 8
#        recent2_row7_value = 0.0
#        recent2_row8_low = recent2_block_low + recent2_row_height * 8
#        recent2_row8_high = recent2_block_low + recent2_row_height * 9
#        recent2_row8_value = 0.0
#        recent2_row9_low = recent2_block_low + recent2_row_height * 9
#        recent2_row9_high = recent2_block_low + recent2_row_height * 10
#        recent2_row9_value = 0.0
#        recent2_row10_low = recent2_block_low + recent2_row_height * 10
#        recent2_row10_high = recent2_block_low + recent2_row_height * 11
#        recent2_row10_value = 0.0
#        recent2_row11_low = recent2_block_low + recent2_row_height * 11
#        recent2_row11_high = recent2_block_low + recent2_row_height * 12
#        recent2_row11_value = 0.0
#        recent2_row12_low = recent2_block_low + recent2_row_height * 12
#        recent2_row12_high = recent2_block_low + recent2_row_height * 13
#        recent2_row12_value = 0.0
#        recent2_row13_low = recent2_block_low + recent2_row_height * 13
#        recent2_row13_high = recent2_block_low + recent2_row_height * 14
#        recent2_row13_value = 0.0
#        recent2_row14_low = recent2_block_low + recent2_row_height * 14
#        recent2_row14_high = recent2_block_low + recent2_row_height * 15
#        recent2_row14_value = 0.0
#
#        for i = recent2_start_i to recent2_end_i + 1
#            bar_n_rows_affected = 0
#            bar_row0_value = 0.0
#            if low[i] < recent2_row0_high and high[i] > recent2_row0_low
#                bar_row0_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row1_value = 0.0
#            if low[i] < recent2_row1_high and high[i] > recent2_row1_low
#                bar_row1_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row2_value = 0.0
#            if low[i] < recent2_row2_high and high[i] > recent2_row2_low
#                bar_row2_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row3_value = 0.0
#            if low[i] < recent2_row3_high and high[i] > recent2_row3_low
#                bar_row3_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row4_value = 0.0
#            if low[i] < recent2_row4_high and high[i] > recent2_row4_low
#                bar_row4_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row5_value = 0.0
#            if low[i] < recent2_row5_high and high[i] > recent2_row5_low
#                bar_row5_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row6_value = 0.0
#            if low[i] < recent2_row6_high and high[i] > recent2_row6_low
#                bar_row6_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row7_value = 0.0
#            if low[i] < recent2_row7_high and high[i] > recent2_row7_low
#                bar_row7_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row8_value = 0.0
#            if low[i] < recent2_row8_high and high[i] > recent2_row8_low
#                bar_row8_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row9_value = 0.0
#            if low[i] < recent2_row9_high and high[i] > recent2_row9_low
#                bar_row9_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row10_value = 0.0
#            if low[i] < recent2_row10_high and high[i] > recent2_row10_low
#                bar_row10_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row11_value = 0.0
#            if low[i] < recent2_row11_high and high[i] > recent2_row11_low
#                bar_row11_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row12_value = 0.0
#            if low[i] < recent2_row12_high and high[i] > recent2_row12_low
#                bar_row12_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row13_value = 0.0
#            if low[i] < recent2_row13_high and high[i] > recent2_row13_low
#                bar_row13_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#            bar_row14_value = 0.0
#            if low[i] < recent2_row14_high and high[i] > recent2_row14_low
#                bar_row14_value := custom_volume[i]
#                bar_n_rows_affected := bar_n_rows_affected + 1
#
#            recent2_row0_value := recent2_row0_value + bar_row0_value / bar_n_rows_affected / recent2_row_height
#            recent2_row1_value := recent2_row1_value + bar_row1_value / bar_n_rows_affected / recent2_row_height
#            recent2_row2_value := recent2_row2_value + bar_row2_value / bar_n_rows_affected / recent2_row_height
#            recent2_row3_value := recent2_row3_value + bar_row3_value / bar_n_rows_affected / recent2_row_height
#            recent2_row4_value := recent2_row4_value + bar_row4_value / bar_n_rows_affected / recent2_row_height
#            recent2_row5_value := recent2_row5_value + bar_row5_value / bar_n_rows_affected / recent2_row_height
#            recent2_row6_value := recent2_row6_value + bar_row6_value / bar_n_rows_affected / recent2_row_height
#            recent2_row7_value := recent2_row7_value + bar_row7_value / bar_n_rows_affected / recent2_row_height
#            recent2_row8_value := recent2_row8_value + bar_row8_value / bar_n_rows_affected / recent2_row_height
#            recent2_row9_value := recent2_row9_value + bar_row9_value / bar_n_rows_affected / recent2_row_height
#            recent2_row10_value := recent2_row10_value + bar_row10_value / bar_n_rows_affected / recent2_row_height
#            recent2_row11_value := recent2_row11_value + bar_row11_value / bar_n_rows_affected / recent2_row_height
#            recent2_row12_value := recent2_row12_value + bar_row12_value / bar_n_rows_affected / recent2_row_height
#            recent2_row13_value := recent2_row13_value + bar_row13_value / bar_n_rows_affected / recent2_row_height
#            recent2_row14_value := recent2_row14_value + bar_row14_value / bar_n_rows_affected / recent2_row_height
#
#        recent2_avg_i = min(recent2_start_i + 1 + block_size * 4, bar_index)
#        recent2_row0_price = (recent2_row0_low + recent2_row0_high ) / 2
#        recent2_row0_width = floor(visual_row_width * recent2_row0_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row1_price = (recent2_row1_low + recent2_row1_high ) / 2
#        recent2_row1_width = floor(visual_row_width * recent2_row1_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row2_price = (recent2_row2_low + recent2_row2_high ) / 2
#        recent2_row2_width = floor(visual_row_width * recent2_row2_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row3_price = (recent2_row3_low + recent2_row3_high ) / 2
#        recent2_row3_width = floor(visual_row_width * recent2_row3_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row4_price = (recent2_row4_low + recent2_row4_high ) / 2
#        recent2_row4_width = floor(visual_row_width * recent2_row4_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row5_price = (recent2_row5_low + recent2_row5_high ) / 2
#        recent2_row5_width = floor(visual_row_width * recent2_row5_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row6_price = (recent2_row6_low + recent2_row6_high ) / 2
#        recent2_row6_width = floor(visual_row_width * recent2_row6_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row7_price = (recent2_row7_low + recent2_row7_high ) / 2
#        recent2_row7_width = floor(visual_row_width * recent2_row7_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row8_price = (recent2_row8_low + recent2_row8_high ) / 2
#        recent2_row8_width = floor(visual_row_width * recent2_row8_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row9_price = (recent2_row9_low + recent2_row9_high ) / 2
#        recent2_row9_width = floor(visual_row_width * recent2_row9_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row10_price = (recent2_row10_low + recent2_row10_high ) / 2
#        recent2_row10_width = floor(visual_row_width * recent2_row10_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row11_price = (recent2_row11_low + recent2_row11_high ) / 2
#        recent2_row11_width = floor(visual_row_width * recent2_row11_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row12_price = (recent2_row12_low + recent2_row12_high ) / 2
#        recent2_row12_width = floor(visual_row_width * recent2_row12_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row13_price = (recent2_row13_low + recent2_row13_high ) / 2
#        recent2_row13_width = floor(visual_row_width * recent2_row13_value / highest_row_value_avg[recent2_avg_i])
#        recent2_row14_price = (recent2_row14_low + recent2_row14_high ) / 2
#        recent2_row14_width = floor(visual_row_width * recent2_row14_value / highest_row_value_avg[recent2_avg_i])
#
#        // calculate vpoc
#
#        float recent2_vpoc_price = na
#        float recent2_highes_row_value = 0
#        if recent2_highes_row_value < recent2_row0_value
#            recent2_highes_row_value := recent2_row0_value
#            recent2_vpoc_price := recent2_row0_price
#        if recent2_highes_row_value < recent2_row1_value
#            recent2_highes_row_value := recent2_row1_value
#            recent2_vpoc_price := recent2_row1_price
#        if recent2_highes_row_value < recent2_row2_value
#            recent2_highes_row_value := recent2_row2_value
#            recent2_vpoc_price := recent2_row2_price
#        if recent2_highes_row_value < recent2_row3_value
#            recent2_highes_row_value := recent2_row3_value
#            recent2_vpoc_price := recent2_row3_price
#        if recent2_highes_row_value < recent2_row4_value
#            recent2_highes_row_value := recent2_row4_value
#            recent2_vpoc_price := recent2_row4_price
#        if recent2_highes_row_value < recent2_row5_value
#            recent2_highes_row_value := recent2_row5_value
#            recent2_vpoc_price := recent2_row5_price
#        if recent2_highes_row_value < recent2_row6_value
#            recent2_highes_row_value := recent2_row6_value
#            recent2_vpoc_price := recent2_row6_price
#        if recent2_highes_row_value < recent2_row7_value
#            recent2_highes_row_value := recent2_row7_value
#            recent2_vpoc_price := recent2_row7_price
#        if recent2_highes_row_value < recent2_row8_value
#            recent2_highes_row_value := recent2_row8_value
#            recent2_vpoc_price := recent2_row8_price
#        if recent2_highes_row_value < recent2_row9_value
#            recent2_highes_row_value := recent2_row9_value
#            recent2_vpoc_price := recent2_row9_price
#        if recent2_highes_row_value < recent2_row10_value
#            recent2_highes_row_value := recent2_row10_value
#            recent2_vpoc_price := recent2_row10_price
#        if recent2_highes_row_value < recent2_row11_value
#            recent2_highes_row_value := recent2_row11_value
#            recent2_vpoc_price := recent2_row11_price
#        if recent2_highes_row_value < recent2_row12_value
#            recent2_highes_row_value := recent2_row12_value
#            recent2_vpoc_price := recent2_row12_price
#        if recent2_highes_row_value < recent2_row13_value
#            recent2_highes_row_value := recent2_row13_value
#            recent2_vpoc_price := recent2_row13_price
#        if recent2_highes_row_value < recent2_row14_value
#            recent2_highes_row_value := recent2_row14_value
#            recent2_vpoc_price := recent2_row14_price
#
#        // draw profile rows
#
#        if na(recent2_row0_line)
#            recent2_row0_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row1_line)
#            recent2_row1_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row2_line)
#            recent2_row2_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row3_line)
#            recent2_row3_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row4_line)
#            recent2_row4_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row5_line)
#            recent2_row5_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row6_line)
#            recent2_row6_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row7_line)
#            recent2_row7_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row8_line)
#            recent2_row8_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row9_line)
#            recent2_row9_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row10_line)
#            recent2_row10_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row11_line)
#            recent2_row11_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row12_line)
#            recent2_row12_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row13_line)
#            recent2_row13_line := line.new(bar_index, close, bar_index, close, width=2)
#        if na(recent2_row14_line)
#            recent2_row14_line := line.new(bar_index, close, bar_index, close, width=2)
#
#
#        line.set_xloc(recent2_row0_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row0_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row0_line, recent2_row0_price)
#        line.set_y2(recent2_row0_line, recent2_row0_price)
#        line.set_color(recent2_row0_line, recent2_color)
#
#        line.set_xloc(recent2_row1_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row1_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row1_line, recent2_row1_price)
#        line.set_y2(recent2_row1_line, recent2_row1_price)
#        line.set_color(recent2_row1_line, recent2_color)
#
#        line.set_xloc(recent2_row2_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row2_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row2_line, recent2_row2_price)
#        line.set_y2(recent2_row2_line, recent2_row2_price)
#        line.set_color(recent2_row2_line, recent2_color)
#
#        line.set_xloc(recent2_row3_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row3_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row3_line, recent2_row3_price)
#        line.set_y2(recent2_row3_line, recent2_row3_price)
#        line.set_color(recent2_row3_line, recent2_color)
#
#        line.set_xloc(recent2_row4_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row4_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row4_line, recent2_row4_price)
#        line.set_y2(recent2_row4_line, recent2_row4_price)
#        line.set_color(recent2_row4_line, recent2_color)
#
#        line.set_xloc(recent2_row5_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row5_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row5_line, recent2_row5_price)
#        line.set_y2(recent2_row5_line, recent2_row5_price)
#        line.set_color(recent2_row5_line, recent2_color)
#
#        line.set_xloc(recent2_row6_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row6_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row6_line, recent2_row6_price)
#        line.set_y2(recent2_row6_line, recent2_row6_price)
#        line.set_color(recent2_row6_line, recent2_color)
#
#        line.set_xloc(recent2_row7_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row7_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row7_line, recent2_row7_price)
#        line.set_y2(recent2_row7_line, recent2_row7_price)
#        line.set_color(recent2_row7_line, recent2_color)
#
#        line.set_xloc(recent2_row8_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row8_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row8_line, recent2_row8_price)
#        line.set_y2(recent2_row8_line, recent2_row8_price)
#        line.set_color(recent2_row8_line, recent2_color)
#
#        line.set_xloc(recent2_row9_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row9_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row9_line, recent2_row9_price)
#        line.set_y2(recent2_row9_line, recent2_row9_price)
#        line.set_color(recent2_row9_line, recent2_color)
#
#        line.set_xloc(recent2_row10_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row10_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row10_line, recent2_row10_price)
#        line.set_y2(recent2_row10_line, recent2_row10_price)
#        line.set_color(recent2_row10_line, recent2_color)
#
#        line.set_xloc(recent2_row11_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row11_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row11_line, recent2_row11_price)
#        line.set_y2(recent2_row11_line, recent2_row11_price)
#        line.set_color(recent2_row11_line, recent2_color)
#
#        line.set_xloc(recent2_row12_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row12_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row12_line, recent2_row12_price)
#        line.set_y2(recent2_row12_line, recent2_row12_price)
#        line.set_color(recent2_row12_line, recent2_color)
#
#        line.set_xloc(recent2_row13_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row13_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row13_line, recent2_row13_price)
#        line.set_y2(recent2_row13_line, recent2_row13_price)
#        line.set_color(recent2_row13_line, recent2_color)
#
#        line.set_xloc(recent2_row14_line, time[recent2_start_i], time_close[max(recent2_start_i - recent2_row14_width, 0)], xloc.bar_time)
#        line.set_y1(recent2_row14_line, recent2_row14_price)
#        line.set_y2(recent2_row14_line, recent2_row14_price)
#        line.set_color(recent2_row14_line, recent2_color)
#
#        0
#
#    else
#
#        // remove unused lines
#
#        if not na(recent2_low_line)
#            line.delete(recent2_low_line)
#            recent2_low_line := na
#        if not na(recent2_high_line)
#            line.delete(recent2_high_line)
#            recent2_high_line := na
#
#        if not na(recent2_row0_line)
#            line.delete(recent2_row0_line)
#            recent2_row0_line := na
#        if not na(recent2_row1_line)
#            line.delete(recent2_row1_line)
#            recent2_row1_line := na
#        if not na(recent2_row2_line)
#            line.delete(recent2_row2_line)
#            recent2_row2_line := na
#        if not na(recent2_row3_line)
#            line.delete(recent2_row3_line)
#            recent2_row3_line := na
#        if not na(recent2_row4_line)
#            line.delete(recent2_row4_line)
#            recent2_row4_line := na
#        if not na(recent2_row5_line)
#            line.delete(recent2_row5_line)
#            recent2_row5_line := na
#        if not na(recent2_row6_line)
#            line.delete(recent2_row6_line)
#            recent2_row6_line := na
#        if not na(recent2_row7_line)
#            line.delete(recent2_row7_line)
#            recent2_row7_line := na
#        if not na(recent2_row8_line)
#            line.delete(recent2_row8_line)
#            recent2_row8_line := na
#        if not na(recent2_row9_line)
#            line.delete(recent2_row9_line)
#            recent2_row9_line := na
#        if not na(recent2_row10_line)
#            line.delete(recent2_row10_line)
#            recent2_row10_line := na
#        if not na(recent2_row11_line)
#            line.delete(recent2_row11_line)
#            recent2_row11_line := na
#        if not na(recent2_row12_line)
#            line.delete(recent2_row12_line)
#            recent2_row12_line := na
#        if not na(recent2_row13_line)
#            line.delete(recent2_row13_line)
#            recent2_row13_line := na
#        if not na(recent2_row14_line)
#            line.delete(recent2_row14_line)
#            recent2_row14_line := na
#        0
#
#

aKiJcLM.jpg
 
Hello All,
Could anyone help us to get this indicator in TOS, I found this indicator is very useful for day trade.
@samer800 @BenTen Please help us to get this Indicator in TOS, Thanks in advance.

Poor man's volume profile


here is a template to get you started, it is not complete.
this will draw 5 of the 40 rows , 0 to 3 and 39

the original was set up to draw 40 rows of data, after the last bar.
this will do that, AFTER someone else adds the missing code lines.
7 sections of 40 code groups, is more than i'm willing to type out.


35 sets of formulas need to be created, in 7 sections
look for these lines and copy nearby code and modify the numbers in the variables
. add codes for 4 to 38 ////////////////////////////

example,
copy this,
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
. and change 03 to 04 , in 2 variables , r03hi

repeat this 34 times, for rows 5 to 38

then go to six other sections and do something similar , copy and change formulas........

i tried to make it consistant and easy to follow. it uses short variable names and 2 digits for the row numbers.


it is set up to read volume, in 1000s.
def data = volume/1000;
units don't matter, the output is based on ratios. i did volume/1000 to keep the numbers from getting huge.

the variable , data, that can be changed to collect other data.
use data = 1 , to count the bars in a price row


a vertical line can be drawn at the start of the time period.
default is 200 bars back from the last bar.


Code:
# Poorman_volume_profile_01

# not complete
# data for 5 of 40 rows ,  0 to 3 , 39
# 35 sets of formulas need to be created, in 7 sections
# look for these lines and add code
#    add codes for 4 to 38 ////////////////////////////


#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#Tradingview Convert Tradingview Poor man's volume profile
#Rrm411   2/12

#Could anyone help us to get this indicator in TOS, I found this indicator is very useful for day trade.
#@samer800 @BenTen Please help us to get this Indicator in TOS, Thanks in advance.

#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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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;
#
#    add codes for 4 to 38 ////////////////////////////
#
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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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, r39cnt))));
#    add codes for 4 to 38 ////////////////////////////


# 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);
#
#    add codes for 4 to 38 ////////////////////////////
#
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));
#
#    add codes for 4 to 38 ////////////////////////////
#
def x39 = (bn > lastbn and bn <= (lastbn + r39r));



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.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.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.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.SetDefaultColor(Color.gray);
z3.setlineweight(line_thick);
z3.hidebubble();
#
#    add codes for 4 to 38 ////////////////////////////
#
plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
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);

#

CMWQvPQ.jpg
hal_prof
 
Last edited:
here is a template to get you started, it is not complete.
this will draw 5 of the 40 rows , 0 to 3 and 39

the original was set up to draw 40 rows of data, after the last bar.
this will do that, AFTER someone else adds the missing code lines.
7 sections of 40 code groups, is more than i'm willing to type out.


35 sets of formulas need to be created, in 7 sections
look for these lines and copy nearby code and modify the numbers in the variables
. add codes for 4 to 38 ////////////////////////////

example,
copy this,
def r03hi = if bn == 1 then k else if lastbar then (block_low + row_height * 4) else r03hi[1];
. and change 03 to 04 , in 2 variables , r03hi

repeat this 34 times, for rows 5 to 38

then go to six other sections and do something similar , copy and change formulas........

i tried to make it consistant and easy to follow. it uses short variable names and 2 digits for the row numbers.


it is set up to read volume, in 1000s.
def data = volume/1000;
units don't matter, the output is based on ratios. i did volume/1000 to keep the numbers from getting huge.

the variable , data, that can be changed to collect other data.
use data = 1 , to count the bars in a price row


a vertical line can be drawn at the start of the time period.
default is 200 bars back from the last bar.


Code:
# Poorman_volume_profile_01

# not complete
# data for 5 of 40 rows ,  0 to 3 , 39
# 35 sets of formulas need to be created, in 7 sections
# look for these lines and add code
#    add codes for 4 to 38 ////////////////////////////


#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#Tradingview Convert Tradingview Poor man's volume profile
#Rrm411   2/12

#Could anyone help us to get this indicator in TOS, I found this indicator is very useful for day trade.
#@samer800 @BenTen Please help us to get this Indicator in TOS, Thanks in advance.

#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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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;
#
#    add codes for 4 to 38 ////////////////////////////
#
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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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, r39cnt))));
#    add codes for 4 to 38 ////////////////////////////


# 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);
#
#    add codes for 4 to 38 ////////////////////////////
#
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));
#
#    add codes for 4 to 38 ////////////////////////////
#
def x39 = (bn > lastbn and bn <= (lastbn + r39r));



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.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.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.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.SetDefaultColor(Color.gray);
z3.setlineweight(line_thick);
z3.hidebubble();
#
#    add codes for 4 to 38 ////////////////////////////
#
plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
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);

#

CMWQvPQ.jpg
@halcyonguy

Thank you for the code,

I have updated the code further as commented, i am getting error, please review and let me know is there anything i can work on that, here i can do only copy and paste with number update, i do not know any strategy in coding, so please check the below updated code and guide us if anythind i can do further.


Code:
#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 + r010r));

def x11 = (bn > lastbn and bn <= (lastbn + r011r));

def x12 = (bn > lastbn and bn <= (lastbn + r012r));

def x13 = (bn > lastbn and bn <= (lastbn + r013r));

def x14 = (bn > lastbn and bn <= (lastbn + r014r));

def x15 = (bn > lastbn and bn <= (lastbn + r015r));

def x16 = (bn > lastbn and bn <= (lastbn + r016r));

def x17 = (bn > lastbn and bn <= (lastbn + r017r));

def x18 = (bn > lastbn and bn <= (lastbn + r018r));

def x19 = (bn > lastbn and bn <= (lastbn + r019r));

def x20 = (bn > lastbn and bn <= (lastbn + r020r));

def x21 = (bn > lastbn and bn <= (lastbn + r021r));

def x22 = (bn > lastbn and bn <= (lastbn + r022r));

def x23 = (bn > lastbn and bn <= (lastbn + r023r));

def x24 = (bn > lastbn and bn <= (lastbn + r024r));

def x25 = (bn > lastbn and bn <= (lastbn + r025r));

def x26 = (bn > lastbn and bn <= (lastbn + r026r));

def x27 = (bn > lastbn and bn <= (lastbn + r027r));

def x28 = (bn > lastbn and bn <= (lastbn + r028r));

def x29 = (bn > lastbn and bn <= (lastbn + r029r));

def x30 = (bn > lastbn and bn <= (lastbn + r030r));

def x31 = (bn > lastbn and bn <= (lastbn + r031r));

def x32 = (bn > lastbn and bn <= (lastbn + r032r));

def x33 = (bn > lastbn and bn <= (lastbn + r033r));

def x34 = (bn > lastbn and bn <= (lastbn + r034r));

def x35 = (bn > lastbn and bn <= (lastbn + r035r));

def x36 = (bn > lastbn and bn <= (lastbn + r036r));

def x37 = (bn > lastbn and bn <= (lastbn + r037r));

def x38 = (bn > lastbn and bn <= (lastbn + r038r));

def x39 = (bn > lastbn and bn <= (lastbn + r39r));







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.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.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.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.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.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.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.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.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.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.SetDefaultColor(Color.gray);

z9.setlineweight(line_thick);

z9.hidebubble();



plot z10 = if show_lines_wsquares and x10 then r010mid else na;

z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z10.SetDefaultColor(Color.gray);

z10.setlineweight(line_thick);

z10.hidebubble();



plot z11 = if show_lines_wsquares and x11 then r011mid else na;

z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z11.SetDefaultColor(Color.gray);

z11.setlineweight(line_thick);

z11.hidebubble();



plot z12 = if show_lines_wsquares and x12 then r012mid else na;

z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z12.SetDefaultColor(Color.gray);

z12.setlineweight(line_thick);

z12.hidebubble();



plot z13 = if show_lines_wsquares and x13 then r013mid else na;

z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z13.SetDefaultColor(Color.gray);

z13.setlineweight(line_thick);

z13.hidebubble();



plot z14 = if show_lines_wsquares and x14 then r014mid else na;

z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z14.SetDefaultColor(Color.gray);

z14.setlineweight(line_thick);

z14.hidebubble();



plot z15 = if show_lines_wsquares and x15 then r015mid else na;

z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z15.SetDefaultColor(Color.gray);

z15.setlineweight(line_thick);

z15.hidebubble();



plot z16 = if show_lines_wsquares and x16 then r016mid else na;

z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z16.SetDefaultColor(Color.gray);

z16.setlineweight(line_thick);

z16.hidebubble();



plot z17 = if show_lines_wsquares and x17 then r017mid else na;

z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z17.SetDefaultColor(Color.gray);

z17.setlineweight(line_thick);

z17.hidebubble();



plot z18 = if show_lines_wsquares and x18 then r018mid else na;

z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z18.SetDefaultColor(Color.gray);

z18.setlineweight(line_thick);

z18.hidebubble();



plot z19 = if show_lines_wsquares and x19 then r019mid else na;

z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z19.SetDefaultColor(Color.gray);

z19.setlineweight(line_thick);

z19.hidebubble();



plot z20 = if show_lines_wsquares and x20 then r020mid else na;

z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z20.SetDefaultColor(Color.gray);

z20.setlineweight(line_thick);

z20.hidebubble();



plot z21 = if show_lines_wsquares and x21 then r021mid else na;

z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z21.SetDefaultColor(Color.gray);

z21.setlineweight(line_thick);

z21.hidebubble();



plot z22 = if show_lines_wsquares and x22 then r022mid else na;

z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z22.SetDefaultColor(Color.gray);

z22.setlineweight(line_thick);

z22.hidebubble();



plot z23 = if show_lines_wsquares and x23 then r023mid else na;

z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z23.SetDefaultColor(Color.gray);

z23.setlineweight(line_thick);

z23.hidebubble();



plot z24 = if show_lines_wsquares and x24 then r024mid else na;

z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z24.SetDefaultColor(Color.gray);

z24.setlineweight(line_thick);

z24.hidebubble();

 

plot z25 = if show_lines_wsquares and x25 then r025mid else na;

z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z25.SetDefaultColor(Color.gray);

z25.setlineweight(line_thick);

z25.hidebubble();



plot z26 = if show_lines_wsquares and x26 then r026mid else na;

z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z26.SetDefaultColor(Color.gray);

z26.setlineweight(line_thick);

z26.hidebubble();



plot z27 = if show_lines_wsquares and x27 then r027mid else na;

z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z27.SetDefaultColor(Color.gray);

z27.setlineweight(line_thick);

z27.hidebubble();



plot z28 = if show_lines_wsquares and x28 then r028mid else na;

z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z28.SetDefaultColor(Color.gray);

z28.setlineweight(line_thick);

z28.hidebubble();



plot z29 = if show_lines_wsquares and x29 then r029mid else na;

z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z29.SetDefaultColor(Color.gray);

z29.setlineweight(line_thick);

z29.hidebubble();



plot z30 = if show_lines_wsquares and x30 then r030mid else na;

z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z30.SetDefaultColor(Color.gray);

z30.setlineweight(line_thick);

z30.hidebubble();



plot z31 = if show_lines_wsquares and x31 then r031mid else na;

z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z31.SetDefaultColor(Color.gray);

z31.setlineweight(line_thick);

z31.hidebubble();



plot z32 = if show_lines_wsquares and x32 then r032mid else na;

z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z32.SetDefaultColor(Color.gray);

z32.setlineweight(line_thick);

z32.hidebubble();

 

plot z33 = if show_lines_wsquares and x33 then r033mid else na;

z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z33.SetDefaultColor(Color.gray);

z33.setlineweight(line_thick);

z33.hidebubble();



plot z34 = if show_lines_wsquares and x34 then r034mid else na;

z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z34.SetDefaultColor(Color.gray);

z34.setlineweight(line_thick);

z34.hidebubble();



plot z35 = if show_lines_wsquares and x35 then r035mid else na;

z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z35.SetDefaultColor(Color.gray);

z35.setlineweight(line_thick);

z35.hidebubble();



plot z36 = if show_lines_wsquares and x36 then r036mid else na;

z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z36.SetDefaultColor(Color.gray);

z36.setlineweight(line_thick);

z36.hidebubble();



plot z37 = if show_lines_wsquares and x37 then r037mid else na;

z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

z37.SetDefaultColor(Color.gray);

z37.setlineweight(line_thick);

z37.hidebubble();



plot z38 = if show_lines_wsquares and x38 then r038mid else na;

z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

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



#
 
Last edited:
@halcyonguy

Thank you for the code,

I have updated the code further as commented, i am getting error, please review and let me know is there anything i can work on that, here i can do only copy and paste with number update, i do not know any strategy in coding, so please check the below updated code and guide us if anythind i can do further.




####################################################################################################

# Poorman_volume_profile_01

# not complete
# data for 5 of 40 rows , 0 to 3 , 39
# 35 sets of formulas need to be created, in 7 sections
# look for these lines and add code
# add codes for 4 to 38 ////////////////////////////


#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#Tradingview Convert Tradingview Poor man's volume profile
#Rrm411 2/12

#Could anyone help us to get this indicator in TOS, I found this indicator is very useful for day trade.
#@samer800 @BenTen Please help us to get this Indicator in TOS, Thanks in advance.

#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 + r010r));
def x11 = (bn > lastbn and bn <= (lastbn + r011r));
def x12 = (bn > lastbn and bn <= (lastbn + r012r));
def x13 = (bn > lastbn and bn <= (lastbn + r013r));
def x14 = (bn > lastbn and bn <= (lastbn + r014r));
def x15 = (bn > lastbn and bn <= (lastbn + r015r));
def x16 = (bn > lastbn and bn <= (lastbn + r016r));
def x17 = (bn > lastbn and bn <= (lastbn + r017r));
def x18 = (bn > lastbn and bn <= (lastbn + r018r));
def x19 = (bn > lastbn and bn <= (lastbn + r019r));
def x20 = (bn > lastbn and bn <= (lastbn + r020r));
def x21 = (bn > lastbn and bn <= (lastbn + r021r));
def x22 = (bn > lastbn and bn <= (lastbn + r022r));
def x23 = (bn > lastbn and bn <= (lastbn + r023r));
def x24 = (bn > lastbn and bn <= (lastbn + r024r));
def x25 = (bn > lastbn and bn <= (lastbn + r025r));
def x26 = (bn > lastbn and bn <= (lastbn + r026r));
def x27 = (bn > lastbn and bn <= (lastbn + r027r));
def x28 = (bn > lastbn and bn <= (lastbn + r028r));
def x29 = (bn > lastbn and bn <= (lastbn + r029r));
def x30 = (bn > lastbn and bn <= (lastbn + r030r));
def x31 = (bn > lastbn and bn <= (lastbn + r031r));
def x32 = (bn > lastbn and bn <= (lastbn + r032r));
def x33 = (bn > lastbn and bn <= (lastbn + r033r));
def x34 = (bn > lastbn and bn <= (lastbn + r034r));
def x35 = (bn > lastbn and bn <= (lastbn + r035r));
def x36 = (bn > lastbn and bn <= (lastbn + r036r));
def x37 = (bn > lastbn and bn <= (lastbn + r037r));
def x38 = (bn > lastbn and bn <= (lastbn + r038r));
def x39 = (bn > lastbn and bn <= (lastbn + r39r));



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.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.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.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.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.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.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.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.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.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.SetDefaultColor(Color.gray);
z9.setlineweight(line_thick);
z9.hidebubble();

plot z10 = if show_lines_wsquares and x10 then r010mid else na;
z10.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z10.SetDefaultColor(Color.gray);
z10.setlineweight(line_thick);
z10.hidebubble();

plot z11 = if show_lines_wsquares and x11 then r011mid else na;
z11.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z11.SetDefaultColor(Color.gray);
z11.setlineweight(line_thick);
z11.hidebubble();

plot z12 = if show_lines_wsquares and x12 then r012mid else na;
z12.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z12.SetDefaultColor(Color.gray);
z12.setlineweight(line_thick);
z12.hidebubble();

plot z13 = if show_lines_wsquares and x13 then r013mid else na;
z13.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z13.SetDefaultColor(Color.gray);
z13.setlineweight(line_thick);
z13.hidebubble();

plot z14 = if show_lines_wsquares and x14 then r014mid else na;
z14.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z14.SetDefaultColor(Color.gray);
z14.setlineweight(line_thick);
z14.hidebubble();

plot z15 = if show_lines_wsquares and x15 then r015mid else na;
z15.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z15.SetDefaultColor(Color.gray);
z15.setlineweight(line_thick);
z15.hidebubble();

plot z16 = if show_lines_wsquares and x16 then r016mid else na;
z16.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z16.SetDefaultColor(Color.gray);
z16.setlineweight(line_thick);
z16.hidebubble();

plot z17 = if show_lines_wsquares and x17 then r017mid else na;
z17.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z17.SetDefaultColor(Color.gray);
z17.setlineweight(line_thick);
z17.hidebubble();

plot z18 = if show_lines_wsquares and x18 then r018mid else na;
z18.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z18.SetDefaultColor(Color.gray);
z18.setlineweight(line_thick);
z18.hidebubble();

plot z19 = if show_lines_wsquares and x19 then r019mid else na;
z19.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z19.SetDefaultColor(Color.gray);
z19.setlineweight(line_thick);
z19.hidebubble();

plot z20 = if show_lines_wsquares and x20 then r020mid else na;
z20.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z20.SetDefaultColor(Color.gray);
z20.setlineweight(line_thick);
z20.hidebubble();

plot z21 = if show_lines_wsquares and x21 then r021mid else na;
z21.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z21.SetDefaultColor(Color.gray);
z21.setlineweight(line_thick);
z21.hidebubble();

plot z22 = if show_lines_wsquares and x22 then r022mid else na;
z22.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z22.SetDefaultColor(Color.gray);
z22.setlineweight(line_thick);
z22.hidebubble();

plot z23 = if show_lines_wsquares and x23 then r023mid else na;
z23.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z23.SetDefaultColor(Color.gray);
z23.setlineweight(line_thick);
z23.hidebubble();

plot z24 = if show_lines_wsquares and x24 then r024mid else na;
z24.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z24.SetDefaultColor(Color.gray);
z24.setlineweight(line_thick);
z24.hidebubble();

plot z25 = if show_lines_wsquares and x25 then r025mid else na;
z25.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z25.SetDefaultColor(Color.gray);
z25.setlineweight(line_thick);
z25.hidebubble();

plot z26 = if show_lines_wsquares and x26 then r026mid else na;
z26.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z26.SetDefaultColor(Color.gray);
z26.setlineweight(line_thick);
z26.hidebubble();

plot z27 = if show_lines_wsquares and x27 then r027mid else na;
z27.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z27.SetDefaultColor(Color.gray);
z27.setlineweight(line_thick);
z27.hidebubble();

plot z28 = if show_lines_wsquares and x28 then r028mid else na;
z28.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z28.SetDefaultColor(Color.gray);
z28.setlineweight(line_thick);
z28.hidebubble();

plot z29 = if show_lines_wsquares and x29 then r029mid else na;
z29.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z29.SetDefaultColor(Color.gray);
z29.setlineweight(line_thick);
z29.hidebubble();

plot z30 = if show_lines_wsquares and x30 then r030mid else na;
z30.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z30.SetDefaultColor(Color.gray);
z30.setlineweight(line_thick);
z30.hidebubble();

plot z31 = if show_lines_wsquares and x31 then r031mid else na;
z31.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z31.SetDefaultColor(Color.gray);
z31.setlineweight(line_thick);
z31.hidebubble();

plot z32 = if show_lines_wsquares and x32 then r032mid else na;
z32.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z32.SetDefaultColor(Color.gray);
z32.setlineweight(line_thick);
z32.hidebubble();

plot z33 = if show_lines_wsquares and x33 then r033mid else na;
z33.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z33.SetDefaultColor(Color.gray);
z33.setlineweight(line_thick);
z33.hidebubble();

plot z34 = if show_lines_wsquares and x34 then r034mid else na;
z34.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z34.SetDefaultColor(Color.gray);
z34.setlineweight(line_thick);
z34.hidebubble();

plot z35 = if show_lines_wsquares and x35 then r035mid else na;
z35.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z35.SetDefaultColor(Color.gray);
z35.setlineweight(line_thick);
z35.hidebubble();

plot z36 = if show_lines_wsquares and x36 then r036mid else na;
z36.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z36.SetDefaultColor(Color.gray);
z36.setlineweight(line_thick);
z36.hidebubble();

plot z37 = if show_lines_wsquares and x37 then r037mid else na;
z37.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
z37.SetDefaultColor(Color.gray);
z37.setlineweight(line_thick);
z37.hidebubble();

plot z38 = if show_lines_wsquares and x38 then r038mid else na;
z38.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
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.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);

#

please post code in a code window
</> in the header

just looking at your post on phone...
you have extra 0
in variables 10 and bigger
r010r


def x10 = (bn > lastbn and bn <= (lastbn + r010r));
def x11 = (bn > lastbn and bn <= (lastbn + r011r));
def x12 = (bn > lastbn and bn <= (lastbn + r012r));
def x13 = (bn > lastbn and bn <= (lastbn + r013r
 
please post code in a code window
</> in the header

just looking at your post on phone...
you have extra 0
in variables 10 and bigger
r010r


def x10 = (bn > lastbn and bn <= (lastbn + r010r));
def x11 = (bn > lastbn and bn <= (lastbn + r011r));
def x12 = (bn > lastbn and bn <= (lastbn + r012r));
def x13 = (bn > lastbn and bn <= (lastbn + r013r

@halcyonguy

Thank you for the correction, i have updated the code now as below, its working except Yellow highlight, kindly suggest if any further correction or update.

17641[/ATTACH]']
gS6FcYB.jpg


Code:
#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));



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

#
.
 

Attachments

  • gS6FcYB.jpg
    gS6FcYB.jpg
    134.1 KB · Views: 185
Last edited:
@halcyonguy

Thank you for the correction, i have updated the code now as below, its working except Yellow highlight, kindly suggest if any further correction or update.

17644[/ATTACH]']
gS6FcYB.jpg


Code:
#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));



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

#
.

i didn't convert the code to change the color of some bars.
i will look at the original code...
 

Attachments

  • gS6FcYB.jpg
    gS6FcYB.jpg
    134.1 KB · Views: 139
@halcyonguy

Thank you for the correction, i have updated the code now as below, its working except Yellow highlight, kindly suggest if any further correction or update.


Code:
#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));



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

#
.

EDIT - sorry, i think i pasted in the wrong code before
here is the correct code

-------------------------------------------
here is an updated code to post#11

it has 40 rows,
a row is orange if the row has a higher number than the previous 5 rows and the following 5 rows
( to mimic how the original code formulas worked )

max formulas added at rows 500+... , and code added to the plots

this chooses how many bars back to look for price data
input block_size2 = 200;

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

hRVHtUp.jpg
 
Last edited:
here is an updated code to post#11

it has 40 rows,
a row is orange if the row has a higher number than the previous 5 rows and the following 5 rows
( to mimic how the original code formulas worked )

max formulas added at rows 500+... , and code added to the plots


Code:
# Poorman_volume_profile_01

# not complete
# data for 5 of 40 rows ,  0 to 3 , 39
# 35 sets of formulas need to be created, in 7 sections
# look for these lines and add code
#    add codes for 4 to 38 ////////////////////////////


#https://usethinkscript.com/threads/convert-tradingview-poor-mans-volume-profile.14460/
#Tradingview Convert Tradingview Poor man's volume profile
#Rrm411   2/12

#Could anyone help us to get this indicator in TOS, I found this indicator is very useful for day trade.
#@samer800 @BenTen Please help us to get this Indicator in TOS, Thanks in advance.

#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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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;
#
#    add codes for 4 to 38 ////////////////////////////
#
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];
#
#    add codes for 4 to 38 ////////////////////////////
#
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, r39cnt))));
#    add codes for 4 to 38 ////////////////////////////


# 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);
#
#    add codes for 4 to 38 ////////////////////////////
#
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));
#
#    add codes for 4 to 38 ////////////////////////////
#
def x39 = (bn > lastbn and bn <= (lastbn + r39r));



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.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.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.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.SetDefaultColor(Color.gray);
z3.setlineweight(line_thick);
z3.hidebubble();
#
#    add codes for 4 to 38 ////////////////////////////
#
plot z39 = if show_lines_wsquares and x39 then r39mid else na;
z39.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
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);

#

hRVHtUp.jpg
I appreciate this study very much! I have the gray volume bars but still no highlight the peaks like yours in yellow for some reason when I pasted. Do you see if I missed that code for highlighting the peaks?

Code:
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));

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

#
 
I appreciate this study very much! I have the gray volume bars but still no highlight the peaks like yours in yellow for some reason when I pasted. Do you see if I missed that code for highlighting the peaks?

Code:
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));

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

#

first thing, you removed the header, so i don't know what code that is in post15, so i'm not checking it.
( if i did want to check it, i would use notepad++ with the compare plugin installed, and load 2 files)

i did look at post14, and i think i screwed up and posted the wrong code.
i updated the code in post14 , i copied it right from my TOS.
 
EDIT - sorry, i think i pasted in the wrong code beore
here is the correct code

-------------------------------------------
here is an updated code to post#11

it has 40 rows,
a row is orange if the row has a higher number than the previous 5 rows and the following 5 rows
( to mimic how the original code formulas worked )

max formulas added at rows 500+... , and code added to the plots


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

View attachment 17697
how do we add some spacing between the volume profile and the candles? thanks!
 
@samer800 I love your study, thank you very much. Is there a way you can add the option to set the start of the study at pre-market open at 1:00am PST/4:00am EST? Like perhaps a clickable button option to have pre-market volume profile go from 4:00am EST and end at 9:30am EST, then the study could revert to the settings of X number of bars per VP cluster?

The picture I included shows the dashed line where pre-market trading opens. the settings in the picture is a 5m chart with 48 profile size or 4hrs per VP cluster.

Thank you for your time
 

Attachments

  • Screenshot 2023-07-16 112713.png
    Screenshot 2023-07-16 112713.png
    124.5 KB · Views: 266
I appreciate this study very much! I have the gray volume bars but still no highlight the peaks like yours in yellow for some reason when I pasted. Do you see if I missed that code for highlighting the peaks?

Code:
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));

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

#
try this, I just created below may help for profile cluster. I added time and volume profile. pls check

timeprofileS_CHARTS.png


CODE:
CSS:
# Time Profile
# Create by Sam4Cok@Samer800    -07/2023 - Requested by useThinkScript.com memeber

input profileType = {"Volume Profile",Default "Time Profile"};
input profileSize = 15;
input noOfProfile = 10;
input showProfile = yes;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 50;
input opacity = 30;

def na = Double.NaN;
def last = IsNaN(close);
#--- Color--
DefineGlobalColor("Level" , CreateColor(33, 150, 243));
DefineGlobalColor("Profile", CreateColor(156, 39, 176));
DefineGlobalColor("VPOC"    , CreateColor(255, 152, 0));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

#// Calculate profiles
def barCount = if last then barCount[1] else barCount[1] + 1;
def block_bar = Floor(barCount % profileSize);
def cond = block_bar == 1;

profile tm = TimeProfile("startNewProfile" = cond, "onExpansion" = no,
"numberOfProfiles" = NoOfProfile, "value area percent" = valueAreaPercent, "pricePerRow" = 0.0000001);

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no,
"numberOfProfiles" = NoOfProfile, "value area percent" = valueAreaPercent, "pricePerRow" = 0.0000001);

def hTM = CompoundValue(1, if IsNaN(tm.GetHighest()) then hTM[1] else tm.GetHighest(), tm.GetHighest());
def lTM = CompoundValue(1, if IsNaN(tm.GetLowest())  then lTM[1] else tm.GetLowest(), tm.GetLowest());
def pcTM = if IsNaN(tm.getPointOfControl()) then pcTM[1] else tm.getPointOfControl();

def hVo = CompoundValue(1, if IsNaN(vol.GetHighest()) then hVo[1] else vol.GetHighest(), vol.GetHighest());
def lVo = CompoundValue(1, if IsNaN(vol.GetLowest())  then lVo[1] else vol.GetLowest(), vol.GetLowest());
def pcVo = if IsNaN(vol.getPointOfControl()) then pcVo[1] else vol.getPointOfControl();

def hProfile; def lProfile; def pc;
Switch (profileType) {
Case "Volume Profile" :
    hProfile = hVo;
    lProfile = lVo;
    pc       = pcVo;
Case "Time Profile" :
    hProfile = hTM;
    lProfile = lTM;
    pc       = pcTM;
}

plot blhigh = if last then na else hProfile;
blHigh.SetDefaultColor(GlobalColor("Level"));
blhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot bllow = if last then na else lProfile;
bllow.SetDefaultColor(GlobalColor("Level"));
bllow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

tm.Show(if showProfile then GlobalColor("Profile") else Color.CURRENT,
         if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT,
         if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);

#// draw vpoc


plot POC = if last or pc==0 then na else pc;
POC.SetDefaultColor(globalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def pocStart = if showPointOfControl then if pc!=pc[1] then pc else na else na;
plot VPoC = pocStart[-1];
VPoC.SetPaintingStrategy(PaintingStrategy.SQUARES);
VPoC.SetDefaultColor(GlobalColor("VPOC"));


#-- END of CODE
 
@samer800 I love your study, thank you very much. Is there a way you can add the option to set the start of the study at pre-market open at 1:00am PST/4:00am EST? Like perhaps a clickable button option to have pre-market volume profile go from 4:00am EST and end at 9:30am EST, then the study could revert to the settings of X number of bars per VP cluster?

The picture I included shows the dashed line where pre-market trading opens. the settings in the picture is a 5m chart with 48 profile size or 4hrs per VP cluster.

Thank you for your time
try this. The best I could do.

CSS:
# Time Profile
# Create by Sam4Cok@Samer800    -07/2023 - Requested by useThinkScript.com memeber
# -- Update -- added session profile - 08/2023

input profileCondition = {Default "Regular Trading Hours", "Extended-Hours Trading", "All Sessions"};
input profileType = {"Volume Profile",Default "Time Profile"};
input profileSize = 15;
input noOfProfile = 10;
input showProfile = yes;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 50;
input opacity = 30;

def na = Double.NaN;
def last = IsNaN(close);
#--- Color--
DefineGlobalColor("Level" , CreateColor(33, 150, 243));
DefineGlobalColor("Profile", CreateColor(156, 39, 176));
DefineGlobalColor("VPOC"    , CreateColor(255, 152, 0));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

#// Calculate profiles
def time = GetTime();
def t1 = time >= RegularTradingStart(GetYYYYMMDD()) and time <= RegularTradingEND(GetYYYYMMDD());

def profileCond;
Switch (profileCondition) {
Case "Regular Trading Hours" : profileCond  = t1;
Case "Extended-Hours Trading" : profileCond = !t1;
Case "All Sessions" : profileCond = yes;
}
def plotCond = !last and profileCond;
def barCount = if !plotCond then 0 else barCount[1] + 1;
def block_bar = Floor(barCount % profileSize);

def cond = if !plotCond then na else block_bar == 1;
def noProfile = if !plotCond then 0 else NoOfProfile;

profile tm = TimeProfile("startNewProfile" = cond, "onExpansion" = no,
"numberOfProfiles" = NoOfProfile, "value area percent" = valueAreaPercent, "pricePerRow" = 0.0000001);

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no,
"numberOfProfiles" = NoOfProfile, "value area percent" = valueAreaPercent, "pricePerRow" = 0.0000001);

def hTM = CompoundValue(1, if IsNaN(tm.GetHighest()) then hTM[1] else tm.GetHighest(), tm.GetHighest());
def lTM = CompoundValue(1, if IsNaN(tm.GetLowest())  then lTM[1] else tm.GetLowest(), tm.GetLowest());
def pcTM = if IsNaN(tm.getPointOfControl()) then pcTM[1] else tm.getPointOfControl();

def hVo = CompoundValue(1, if IsNaN(vol.GetHighest()) then hVo[1] else vol.GetHighest(), vol.GetHighest());
def lVo = CompoundValue(1, if IsNaN(vol.GetLowest())  then lVo[1] else vol.GetLowest(), vol.GetLowest());
def pcVo = if IsNaN(vol.getPointOfControl()) then pcVo[1] else vol.getPointOfControl();

def hProfile; def lProfile; def pc;
Switch (profileType) {
Case "Volume Profile" :
    hProfile = if !plotCond then na else hVo;
    lProfile = if !plotCond then na else lVo;
    pc       = if !plotCond then na else pcVo;
Case "Time Profile" :
    hProfile = if !plotCond then na else hTM;
    lProfile = if !plotCond then na else lTM;
    pc       = if !plotCond then na else pcTM;
}

plot blhigh = hProfile;
blHigh.SetDefaultColor(GlobalColor("Level"));
blhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot bllow = lProfile;
bllow.SetDefaultColor(GlobalColor("Level"));
bllow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

tm.Show(if showProfile then GlobalColor("Profile") else Color.CURRENT,
         if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT,
         if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);

#// draw vpoc


plot POC = if pc==0 then na else pc;
POC.SetDefaultColor(globalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def pocStart = if showPointOfControl then if pc!=pc[1] then pc else na else na;
plot VPoC = pocStart[-1];
VPoC.SetPaintingStrategy(PaintingStrategy.SQUARES);
VPoC.SetDefaultColor(GlobalColor("VPOC"));


#-- END of CODE
 
Love this profile, I have one request to add - is it possible to have this profile show a certain amount of time?

For example if I wanted to see 7am-714am?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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