Simple Moving Average Slope [AstrideUnicorn]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AstrideUnicorn

//@version=5
indicator("Simple Moving Average Slope [AstrideUnicorn]", shorttitle = "SMAS [AstrideUnicorn]", overlay = false)

// Inputs
window = input(20, "Window")
threshold = input(0.6, "Threshold")

// Calculate the Simple Moving Average slope
sma_slope = ta.sma(close,window) - ta.sma(close[1], window)

// Normalize the Simple Moving Average slope by dividing it by the long-term strandard deviation of the slope
normalized_sma_slope = sma_slope / ta.stdev(sma_slope, window*10)

// Define the conditional color variable
color_trend = normalized_sma_slope > threshold ? color.green : normalized_sma_slope < -threshold ? color.red : color.blue

// Plot the zero level
plot(0)

// Plot the normalized Simple Moving Average slope curve
ns = plot(normalized_sma_slope, color = color_trend)

// Plot the threshold levels
t_upper = plot(threshold)
t_lower = plot(-threshold)

// Fill the area under the the indicator curve with the conditional color
fill(ns,t_upper, normalized_sma_slope > threshold ? color_trend : na)
fill(ns,t_lower, normalized_sma_slope < -threshold ? color_trend : na)