Stochastic Buy Sell with EMA Trend
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RealTradingIndicator

//@version=5
indicator(title="Stochastic Buy Sell with EMA Trend", shorttitle="Stochastic Buy Sell with EMA Trend",overlay= true)

periodK = input.int(14, title="%K Length", minval=1)
smoothK = input.int(1, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
OverBought = input(80)
OverSold = input(20)

k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

co = ta.crossover(k,d)
cu = ta.crossunder(k,d)
ema_200 = ta.ema(close,200)

buy  = false
sell = false

if (not na(k) and not na(d))
	if (co and k < OverSold) and close > ema_200
		buy  := true

	if (cu and k > OverBought)  and close < ema_200
		sell := true

plotshape(buy, style=shape.labelup, location=location.belowbar,color=color.green,size=size.tiny,text="Buy",textcolor=color.white)
plotshape(sell, style=shape.labeldown, location=location.abovebar,color=color.red,size=size.tiny,text="Sell",textcolor=color.white)
plot(ema_200,"Ema 200")

