EMA + ATR Support and Resistance + Take Profit Signal
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © uoi2020

//@version=5
indicator(title='EMA+ ATR Support Resistance Take Profit signal', shorttitle='EMA+ ATR Support/Resistance Take profit', overlay=true)

// Support and Resistance
SR2 = input.string(title='Top Line', defval='Resistance', options=['Support', 'Resistance'])
SR1 = input.string(title='Bottom line', defval='Support', options=['Support', 'Resistance'])


// EMA and ATR lengths and line width 
EmaMainLength = input.int(20, minval=1, title='EMA Length')
AtrMainLength = input.int(14, minval=1, title='ATR Length')
SRLength = input.float(2, minval=0.1, title='S/R Length', step=0.1)
LineWidth = input.int(10, minval=1, title='Line Width')
// Calculate Support/Resistance levels
ema = ta.ema(close, EmaMainLength)
atr = ta.rma(ta.tr(true), AtrMainLength)

out1 = SR1 == 'Support' ? ema - atr * SRLength : ema + atr * SRLength
out2 = SR2 == 'Support' ? ema - atr * SRLength : ema + atr * SRLength

// Plot EMA and Support and Resistance levels
plot(ema, title='EMA', color=color.rgb(255, 153, 0, 100), linewidth=LineWidth)
plot(out1, title='Support', color=color.rgb(76, 175, 79, 85), linewidth=LineWidth)
plot(out2, title='Resistance', color=color.rgb(255, 82, 82, 85), linewidth=LineWidth)

// Signal when price hits support or resistance level
support_hit = low <= out1 ? true : false
resistance_hit = high >= out2 ? true : false

plotshape(series=support_hit, title="Support Hit", location=location.belowbar, color=color.lime, style=shape.xcross, size=size.tiny)
plotshape(series=resistance_hit, title="Resistance Hit", location=location.abovebar, color=color.red, style=shape.xcross, size=size.tiny)
