Price Heat Map
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jomy

//@version=5
indicator("Price Heat Map",overlay=true)

rng=input.int(200,"bars back",step=50,maxval=500)
modifier=input.float(.5,"brightness modifier",step=.1)

hh=ta.highest(high,rng)
ll=ta.lowest(low,rng)
chunk=(hh-ll)/20
level=0.0

count1=0.0
count2=0.0
count3=0.0
count4=0.0
count5=0.0
count6=0.0
count7=0.0
count8=0.0
count9=0.0
count10=0.0
count11=0.0
count12=0.0
count13=0.0
count14=0.0
count15=0.0
count16=0.0
count17=0.0
count18=0.0
count19=0.0
count20=0.0

for j = 1 to rng
    count1 := low[j] <= (ll+(chunk*1)) and high[j] >= (ll+(chunk*0))? count1 + 1 : count1
    count2 := low[j] <= (ll+(chunk*2)) and high[j] >= (ll+(chunk*1))? count2 + 1: count2
    count3 := low[j] <= (ll+(chunk*3)) and high[j] >= (ll+(chunk*2))? count3 + 1 : count3
    count4 := low[j] <= (ll+(chunk*4)) and high[j] >= (ll+(chunk*3))? count4 + 1 : count4
    count5 := low[j] <= (ll+(chunk*5)) and high[j] >= (ll+(chunk*4))? count5 + 1: count5
    count6 := low[j] <= (ll+(chunk*6)) and high[j] >= (ll+(chunk*5))? count6 + 1: count6
    count7 := low[j] <= (ll+(chunk*7)) and high[j] >= (ll+(chunk*6))? count7 + 1 : count7
    count8 := low[j] <= (ll+(chunk*8)) and high[j] >= (ll+(chunk*7))? count8 + 1 : count8
    count9 := low[j] <= (ll+(chunk*9)) and high[j] >= (ll+(chunk*8))? count9 + 1: count9
    count10 := low[j] <= (ll+(chunk*10)) and high[j] >= (ll+(chunk*9))? count10 + 1 : count10
    count11 := low[j] <= (ll+(chunk*11)) and high[j] >= (ll+(chunk*10))? count11 + 1 : count11
    count12 := low[j] <= (ll+(chunk*12)) and high[j] >= (ll+(chunk*11))? count12 + 1 : count12
    count13 := low[j] <= (ll+(chunk*13)) and high[j] >= (ll+(chunk*12))? count13 + 1 : count13
    count14 := low[j] <= (ll+(chunk*14)) and high[j] >= (ll+(chunk*13))? count14 + 1 : count14
    count15 := low[j] <= (ll+(chunk*15)) and high[j] >= (ll+(chunk*14))? count15 + 1 : count15
    count16 := low[j] <= (ll+(chunk*16)) and high[j] >= (ll+(chunk*15))? count16 + 1: count16
    count17 := low[j] <= (ll+(chunk*17)) and high[j] >= (ll+(chunk*16))? count17 + 1 : count17
    count18 := low[j] <= (ll+(chunk*18)) and high[j] >= (ll+(chunk*17))? count18 + 1 : count18
    count19 := low[j] <= (ll+(chunk*19)) and high[j] >= (ll+(chunk*18))? count19 + 1 : count19
    count20 := low[j] <= (ll+(chunk*20)) and high[j] >= (ll+(chunk*19))? count20 + 1 : count20

l1=ll
l2=ll+chunk*1
l3=ll+chunk*2
l4=ll+chunk*3
l5=ll+chunk*4
l6=ll+chunk*5
l7=ll+chunk*6
l8=ll+chunk*7
l9=ll+chunk*8
l10=ll+chunk*9
l11=ll+chunk*10
l12=ll+chunk*11
l13=ll+chunk*12
l14=ll+chunk*13
l15=ll+chunk*14
l16=ll+chunk*15
l17=ll+chunk*16
l18=ll+chunk*17
l19=ll+chunk*18
l20=ll+chunk*19

hz = math.max(count1,count2,count3,count4,count5,count6,count7,count8,count9,count10,count11,count12,count13,count14,count15,count16,count17,count18,count19,count20)

lev=0.0
lev:= hz==count1?ll+(chunk*0.5):lev
lev:= hz==count2?ll+(chunk*1.5):lev
lev:= hz==count3?ll+(chunk*2.5):lev
lev:= hz==count4?ll+(chunk*3.5):lev
lev:= hz==count5?ll+(chunk*4.5):lev
lev:= hz==count6?ll+(chunk*5.5):lev
lev:= hz==count7?ll+(chunk*6.5):lev
lev:= hz==count8?ll+(chunk*7.5):lev
lev:= hz==count9?ll+(chunk*8.5):lev
lev:= hz==count10?ll+(chunk*9.5):lev
lev:= hz==count11?ll+(chunk*10.5):lev
lev:= hz==count12?ll+(chunk*11.5):lev
lev:= hz==count13?ll+(chunk*12.5):lev
lev:= hz==count14?ll+(chunk*13.5):lev
lev:= hz==count15?ll+(chunk*14.5):lev
lev:= hz==count16?ll+(chunk*15.5):lev
lev:= hz==count17?ll+(chunk*16.5):lev
lev:= hz==count18?ll+(chunk*17.5):lev
lev:= hz==count19?ll+(chunk*18.5):lev
lev:= hz==count20?ll+(chunk*19.5):lev

p1=plot(l1,color=color.rgb(255,255,255,100))
p2=plot(l2,color=color.rgb(0,0,0,100))
p3=plot(l3,color=color.rgb(0,0,0,100))
p4=plot(l4,color=color.rgb(0,0,0,100))
p5=plot(l5,color=color.rgb(0,0,0,100))
p6=plot(l6,color=color.rgb(0,0,0,100))
p7=plot(l7,color=color.rgb(0,0,0,100))
p8=plot(l8,color=color.rgb(0,0,0,100))
p9=plot(l9,color=color.rgb(0,0,0,100))
p10=plot(l10,color=color.rgb(0,0,0,100))
p11=plot(l11,color=color.rgb(0,0,0,100))
p12=plot(l12,color=color.rgb(0,0,0,100))
p13=plot(l13,color=color.rgb(0,0,0,100))
p14=plot(l14,color=color.rgb(0,0,0,100))
p15=plot(l15,color=color.rgb(0,0,0,100))
p16=plot(l16,color=color.rgb(0,0,0,100))
p17=plot(l17,color=color.rgb(0,0,0,100))
p18=plot(l18,color=color.rgb(0,0,0,100))
p19=plot(l19,color=color.rgb(0,0,0,100))
p20=plot(l20,color=color.rgb(255,255,255,100))

fill(p1,p2,color.rgb(255,0,0,100-count1*500/rng*modifier))
fill(p2,p3,color.rgb(255,0,0,100-count2*500/rng*modifier))
fill(p3,p4,color.rgb(255,0,0,100-count3*500/rng*modifier))
fill(p4,p5,color.rgb(255,0,0,100-count4*500/rng*modifier))
fill(p5,p6,color.rgb(255,0,0,100-count5*500/rng*modifier))
fill(p6,p7,color.rgb(255,0,0,100-count6*500/rng*modifier))
fill(p7,p8,color.rgb(255,0,0,100-count7*500/rng*modifier))
fill(p8,p9,color.rgb(255,0,0,100-count8*500/rng*modifier))
fill(p9,p10,color.rgb(255,0,0,100-count9*500/rng*modifier))
fill(p10,p11,color.rgb(255,0,0,100-count10*500/rng*modifier))
fill(p11,p12,color.rgb(255,0,0,100-count11*500/rng*modifier))
fill(p12,p13,color.rgb(255,0,0,100-count12*500/rng*modifier))
fill(p13,p14,color.rgb(255,0,0,100-count13*500/rng*modifier))
fill(p14,p15,color.rgb(255,0,0,100-count14*500/rng*modifier))
fill(p15,p16,color.rgb(255,0,0,100-count15*500/rng*modifier))
fill(p16,p17,color.rgb(255,0,0,100-count16*500/rng*modifier))
fill(p17,p18,color.rgb(255,0,0,100-count17*500/rng*modifier))
fill(p18,p19,color.rgb(255,0,0,100-count18*500/rng*modifier))
fill(p19,p20,color.rgb(255,0,0,100-count19*500/rng*modifier))

plot(lev)
plot(ta.ema(close,rng),color=color.yellow)

