D3score
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © venkatadora

//@version=5
indicator("D3score")


D3scr = 0

if ((close < low[1]))
    D3scr := -1
if ((close < low[1]) and (close < low[2]))
    D3scr := -2
if ((close < low[1]) and (close < low[2]) and (close < low [3]))
    D3scr := -3
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]))
    D3scr := -4
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]))
    D3scr := -5
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]) and (close < low[6]))
    D3scr := -6
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]) and (close < low [6]) and (close < low [7]))
    D3scr := -7
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]) and (close < low [6]) and (close < low [7]) and (close < low [8]))
    D3scr := -8
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]) and (close < low [6]) and (close < low [7]) and (close < low [8]) and (close < low[9]))
    D3scr := -9
if ((close < low[1]) and (close < low[2])and (close < low [3]) and (close < low [4]) and (close < low [5]) and (close < low [6]) and (close < low [7]) and ( close < low [8]) and ( close < low [9]) and ( close < low [10]))
    D3scr := -10
if ((close > high [1]))
    D3scr := 1
if ((close > high [1]) and (close > high[2]))
    D3scr := 2
if ((close > high [1]) and (close > high[2]) and (close > high[3]))
    D3scr := 3
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]))
    D3scr := 4
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]))
    D3scr := 5
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]) and (close> high [6]))
    D3scr := 6
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]) and (close > high[6]) and (close > high [7]))
    D3scr := 7
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]) and (close > high[6]) and (close > high [7]) and ( close > high [8]))
    D3scr := 8
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]) and (close > high[6]) and (close > high [7]) and (close > high [8]) and (close > high [9]))
    D3scr := 9
if ((close > high [1]) and (close > high[2]) and (close > high[3]) and (close > high[4]) and (close > high[5]) and (close > high[6]) and (close > high [7]) and (close > high [8]) and (close > high [9]) and ( close > high [10]))
    D3scr := 10
    
Escore =    ta.hma (D3scr,20)/ta.stdev(D3scr,20)


//Thresholds
uthres = 1
dthres = -1
cent = 0

//Center Plot
centplot = plot(cent,color=#FFEB3B,title ="Center Line",style = plot.style_circles )

//Threshold Plots
utplot = plot(uthres, color=#FF5252,title ="Upper Threshold", style = plot.style_circles)
dtplot = plot(dthres, color=#4CAF50,title ="Lower Threshold", style = plot.style_circles)


//Colors
dcolor = Escore > 0 ? color(#00c3ff) : Escore < 0 ? color(#ff0062) : color(color.black)
fcolor = Escore > 0 ? color(color.green) :Escore < 0 ? color(color.maroon) : color(color.black)

plot(Escore,color=dcolor,linewidth= 3, title ="D3score", style = plot.style_columns)


