Price Delta Heatmap
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("Price Delta Heatmap", overlay=false)

// Calculate price delta
priceDelta = close - close[1]

// Define color ranges for heatmap
delta1 = input.float(100.0, 'Highest Positive Delta Threshold')
delta2 = input.float(50.0, 'Third Positive Delta Threshold')
delta3 = input.float(20.0, 'Second Positive Delta Threshold')
delta4 = input.float(10.0, 'Lowest Positive Delta Threshold')
delta5 = 0
delta6 = input.float(-10.0, 'Lowest Negative Delta Threshold')
delta7 = input.float(-20.0, 'Second Negative Delta Threshold')
delta8 = input.float(-50.0, 'Third Negative Delta Threshold')
delta9 = input.float(-100.0, 'Lowest Negative Delta Threshold')

// Set bar and background colors based on price delta ranges
barcolor(priceDelta >= delta1 ? color.lime :
         priceDelta >= delta2 ? color.green :
         priceDelta >= delta3 ? color.olive :
         priceDelta >= delta4 ? color.yellow :
         priceDelta >= delta5 ? color.white :
         priceDelta >= delta6 ? color.yellow :
         priceDelta >= delta7 ? color.orange :
         priceDelta >= delta8 ? color.red :
         color.maroon)

bgcolor(priceDelta >= delta1 ? color.new(color.lime, 70) :
         priceDelta >= delta2 ? color.new(color.green, 70) :
         priceDelta >= delta3 ? color.new(color.olive, 70) :
         priceDelta >= delta4 ? color.new(color.yellow, 70) :
         priceDelta >= delta5 ? color.new(color.white, 70) :
         priceDelta >= delta6 ? color.new(color.yellow, 70) :
         priceDelta >= delta7 ? color.new(color.orange, 70) :
         priceDelta >= delta8 ? color.new(color.red, 70) :
         color.new(color.maroon, 70))

// Plotting
deltaColor = priceDelta >= delta3 ? color.lime : priceDelta <= delta7 ? color.fuchsia : color.aqua

plotshape(priceDelta >= delta3, 'Positive Delta Signal', style = shape.triangleup, size=size.small, color=color.lime, location=location.bottom)
plotshape(priceDelta <= delta7, 'Negative Delta Signal', style = shape.triangledown, size=size.small, color=color.fuchsia, location=location.bottom)

plot(priceDelta, color=deltaColor, linewidth=4, title="Price Delta")
hline(delta1)
hline(delta2)
hline(delta3)
hline(delta4)
hline(delta5, linewidth=2)
hline(delta6)
hline(delta7)
hline(delta8)
hline(delta9)
