User Defined Range Selector and Color Changing EMA Line
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Crypto_Moses

//@version=4
study("User Defined Range Selector and Color Changing EMA Line", shorttitle="User EMA Range", overlay=true)

// User Inputs
len = input(69, title="EMA Length", minval=1)
slopeLength = input(3, title="Slope Length", minval=1)
src = input(low, title="Source")
colorUp = input(color.blue, title="Color for Upward Slope")
colorDown = input(color.red, title="Color for Downward Slope")
colorSideways = input(color.gray, title="Color for Sideways")
percentAway = input(1.5, title="Percentage Away for Mirrored Line", minval=0.1, step=0.1)

// Calculate EMA and its Slope
emaLine = ema(src, len)
slope = emaLine - emaLine[slopeLength]
emaColor = slope > 0 ? colorUp : slope < 0 ? colorDown : colorSideways

// Calculate Mirrored Line
mirroredLine = emaLine * (1 + percentAway / 100)

// Plotting
plot(emaLine, title="EMA", color=emaColor, linewidth=1)
plot(mirroredLine, title="Mirrored EMA", color=color.gray, linewidth=1, style=plot.style_circles)
