Divergences in 52 Week Moving Averages, Adjusted and Smoothed
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © blueberryjones

//@version=5
indicator("Divergences in 52 Week Moving Averages, Adjusted and Smoothed", timeframe='D', overlay=true)

//Allow user to adjust EMA, 3 is standard.
emaLength = input.int(3, title="EMA Length")

//Allow user to adjust for sensitivity settings. 
standardSignals = input.bool(true, title="Show Standard Signals")
sensitiveSignals = input.bool(true, title="Show Sensitive Signals")
highlysensitiveSignals = input.bool(true, title="Show Highly Sensitive Signals")

//Pull NAHF for 52-Week High Values, then apply EMA for smoothing. 
hi_index = request.security("NAHF", "D", close)
hi_index_ema = ta.ema(hi_index,emaLength)

//Pull NALF for 52-Week Low Values, then apply EMA for smoothing. 
lo_index = request.security("NALF", "D", close)
lo_index_ema = ta.ema(lo_index,emaLength)

//The logic below caps the areas for signals. 
//Greater than 4.5 is considered to be a standard signal, few false positives appear here. 
//Between 3.5 and 4.5 is considered to be sensitive.
//Between 2.5 and 3.5 is considered to be highly sensitive. 
//Readings under 2.5 are excluded due to the high number of false positive and 'next day' moves that appear, feel free to adjust but it does not fit the intended style of the signal. 
highly_sensitive_short_criteria = hi_index_ema >= 2.5 and hi_index_ema < 3.5
sensitive_short_criteria = hi_index_ema >= 3.5 and hi_index_ema < 4.5
standard_short_criteria = hi_index_ema >= 4.5
highly_sensitive_long_criteria = lo_index_ema >= 2.5 and lo_index_ema < 3.5
sensitive_long_criteria = lo_index_ema >= 3.5 and lo_index_ema < 4.5
standard_long_criteria = lo_index_ema >= 4.5

// Logic is applied here for a boolean (true/false) statement if the criteria has been met to signal a move. 
highly_sensitive_short_signal = if highly_sensitive_short_criteria and highlysensitiveSignals
    true
else
    false

sensitive_short_signal = if sensitive_short_criteria and sensitiveSignals
    true
else
    false

standard_short_signal = if standard_short_criteria and standardSignals
    true
else
    false

highly_sensitive_long_signal = if highly_sensitive_long_criteria and highlysensitiveSignals
    true
else
    false

sensitive_long_signal = if sensitive_long_criteria and sensitiveSignals
    true
else
    false

standard_long_signal = if standard_long_criteria and standardSignals
    true
else
    false

// Unicode Characters (Emoji's) are plotted when crtiera has triggers, these emoji's are plotted corresponding to the Sensitivity Level that has been checked. 
plotchar(highly_sensitive_short_signal, "Short", "❗️", location=location.abovebar, size = size.auto)
plotchar(sensitive_short_signal, "Short", "🆘", location=location.abovebar, size = size.auto)
plotchar(standard_short_signal, "Short", "🔻", location=location.abovebar, size = size.auto)
plotchar(highly_sensitive_long_signal, "Long", "❕", location=location.belowbar, size = size.auto)
plotchar(sensitive_long_signal, "Long", "🆙", location=location.belowbar, size = size.auto)
plotchar(standard_long_signal, "Long", "🔺", location=location.belowbar, size = size.auto)