EMA Crossover Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BrendanW98

//@version=4
strategy("My Strategy", overlay=true)

ema5 = ema(close, 9)
ema20 = ema(close, 21)
ema50 = ema(close, 55)

//RSI Signals
// Get user input
rsiSource = close
rsiLength = 14
rsiOverbought = 70
rsiOversold = 30
rsiMid = 50
// Get RSI value
rsiValue = rsi(rsiSource, rsiLength)

//See if RSI crosses 50
doBuy = crossover(rsiValue, rsiOversold) and rsiValue < 50
doSell = crossunder(rsiValue, rsiOverbought) and rsiValue > 50

emacrossover = crossover(ema5, ema20) and ema5 > ema50 and ema20 > ema50 and close > ema50
emacrossunder = crossunder(ema5, ema20) and ema5 < ema50 and ema20 < ema50 and close < ema50

//Entry and Exit
longCondition = emacrossover
closelongCondition = doSell

strategy.entry("Long", strategy.long, 10000.0, when=longCondition)
strategy.close("Long", when=closelongCondition)


shortCondition = emacrossunder
closeshortCondition = doBuy

strategy.entry("Short", strategy.short, 10000.0, when=shortCondition)
strategy.close("Short", when=closeshortCondition)