ADX Heatmap & Di's + Fib Referencial by [JohnnySnow]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jmgneves
// The DMI indicators are generated by the built-in pinescript DMI with exactly the same default values.
// For quicker and easier interpretation, ADX line is displayed in a heatmap style. The more absolute difference between both DIs, the more intense the color. 
// Because some people use 20 ADX reference and others use 25 ADX reference to confirm the trend, I just add both as reference lines:)
// Additionally, reference lines were added with default values set to Fib levels
// Enjoy

//@version=5
indicator(title = "ADX Heatmap & Di's + fib referencial by [JohnnySnow]" , shorttitle = "ADX++", overlay = false)
// # ========================================================================= #

bgcolor(#000000, transp=30)
// # =================== Directional Moving Index Inputs ===================== #
di_lenght                   = input.int(defval = 14, title = "DI Length",     minval = 1,              inline = "01",  group = "🟠 ADX 🟠")
sigma_length                = input.int(defval = 14, title = "ADX Smoothing", minval = 1, inline = "02",  group = "🟠 ADX 🟠")
// # =================== Directional Moving Index Inputs ===================== #



// # =================== Reference Lines Inputs ===================== #

adx_reversal_zone_up_limit = input(25,  title = "ADX Reversal Zone (Upper limit)", group = "🟠 Reference Lines Configuration 🟠")
adx_reversal_zone_bottom_limit = input(20,  title = "ADX Reversal Zone (Lower limit)", group = "🟠 Reference Lines Configuration 🟠")
adx_reversal_zone_color  = color.new(#fbc02d, transp=50)
adx_reference_lines_color = color.new(color.gray, transp=75)

adx_reference_line_1 = input(0,  title = "ADX reference line 1 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_2 = input(23.6,  title = "ADX reference line 2 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_3 = input(38.2,  title = "ADX reference line 3 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_4 = input(50,  title = "ADX reference line 4 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_5 = input(61.8,  title = "ADX reference line 5 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_6 = input(78.6,  title = "ADX reference line 6 x", group = "🟠 Reference Lines Configuration 🟠")
adx_reference_line_7 = input(100,  title = "ADX reference line 7 x", group = "🟠 Reference Lines Configuration 🟠")
// # =================== Reference Lines Inputs ===================== #



// # ================ Directional Moving Index Calculation =================== #
[d_plus,d_minus, adx] = ta.dmi(di_lenght, sigma_length)
// # ================ Directional Moving Index Calculation =================== #



// # =================== Color Palettes ===================== #
green_palette = array.new_color()
red_palette = array.new_color()

array.push ( green_palette , #e8f5e9 )
array.push ( green_palette , #c8e6c9 )
array.push ( green_palette , #a5d6a7 )
array.push ( green_palette , #a5d6a7 )
array.push ( green_palette , #66bb6a )
array.push ( green_palette , #4caf50 )
array.push ( green_palette , #43a047 )
array.push ( green_palette , #388e3c )
array.push ( green_palette , #2e7d32 )
array.push ( green_palette , #1b5e20 )

array.push ( red_palette, #ffebee )
array.push ( red_palette, #ffcdd2 )
array.push ( red_palette, #ef9a9a )
array.push ( red_palette, #e57373 )
array.push ( red_palette, #ef5350 )
array.push ( red_palette, #f44336 )
array.push ( red_palette, #e53935 )
array.push ( red_palette, #d32f2f )
array.push ( red_palette, #c62828 )
array.push ( red_palette, #b71c1c )
// # =================== Color Palettes ===================== #



// # =================== Coloring Methods ===================== # 
get_adx_color(x, y) =>
    val = int(math.abs(x-y)) 
    ar = (x > y) ? green_palette : red_palette
    to_return = val>=50 ? array.get(ar, 9) : array.get(ar, int(val/5))
    to_return

// # =================== Coloring Methods ===================== #



// # ================== Directional Moving Index Plotting ==================== #
adx_plot = plot(series = adx, color=get_adx_color(d_plus, d_minus), style = plot.style_circles, linewidth=2, title = "ADX")

d_minus_plot = plot(series = d_minus, color = color.new(#ef9a9a, 80), title = "+DI")
d_plus_plot = plot(series = d_plus,  color = color.new(#a5d6a7,80), title = "-DI")

fill(d_plus_plot, d_minus_plot, color=get_adx_color(d_plus, d_minus),transp=80)
// # ================== Directional Moving Index Plotting ==================== #

// # ================== Reversal and Referencial Zones display ==================== #

trend_line_reversal_top  = hline(adx_reversal_zone_up_limit, color=adx_reversal_zone_color, linestyle=hline.style_solid)
trend_line_reversal_bottom = hline(adx_reversal_zone_bottom_limit, color=adx_reversal_zone_color,  linestyle=hline.style_solid)

fill(trend_line_reversal_top,trend_line_reversal_bottom,color=#fbc02d,transp=90)

hline(adx_reference_line_1, color=adx_reference_lines_color, linestyle=hline.style_solid)
hline(adx_reference_line_2, color=adx_reversal_zone_color, linestyle=hline.style_solid)
hline(adx_reference_line_3, color=adx_reference_lines_color, linestyle=hline.style_solid)
hline(adx_reference_line_4, color=adx_reference_lines_color, linestyle=hline.style_solid)
hline(adx_reference_line_5, color=adx_reference_lines_color, linestyle=hline.style_solid)
hline(adx_reference_line_6, color=adx_reference_lines_color, linestyle=hline.style_solid)
hline(adx_reference_line_7, color=adx_reference_lines_color, linestyle=hline.style_solid)
// # ================== Reversal and Referencial Zones display ==================== #