True Range Outlier Detector (TROD)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("TROD", explicit_plot_zorder = true)
normalize(float src, int len) =>
    out = (src - ta.lowest(src, len)) / (ta.highest(src, len) - ta.lowest(src, len))
    out
style = not input.bool(false, "Use Open Close instead of High Low")
length = input.int(100)
outlier_up = input.float(0.5, "Outlier High", step = 0.01)
outlier_down = input.float(-0.5, "Outlier Low", step = 0.01)
out = open > close ? -normalize(high - low, length) : normalize(high - low, length) 
other = (normalize(close - open, length) - 0.5) * 2

up = hline(outlier_up)
dn = hline(outlier_down)

fill(up, dn, color = color.new(color.navy, 80))

hline(1, color = color.new(color.green, 30), linestyle = hline.style_solid)
hline(-1, color = color.new(color.red, 30), linestyle = hline.style_solid)

plot(style ? out : other, color = (style ? out : other) > outlier_up ? color.green : (style ? out : other) < outlier_down ? color.red : color.blue, style = plot.style_columns)

