EMA+RSI Pump & Drop Swing Sniper (SL+TP) - Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mmoiwgg

//@version=4
strategy(title="EMA+RSI Pump & Drop Swing Sniper (With Alerts & SL+TP) - Strategy", shorttitle="EMA+RSI Swing Strategy", overlay=true)
emaLength = input(title="EMA Length", type=input.integer, defval=50, minval=0)
emarsiSource = input(close, title="EMA+RSI Source")
condSource = input(high, title="Long+Short Condition Source")
emaVal = ema(emarsiSource, emaLength)
rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0)
rsiVal = rsi(emarsiSource, rsiLength)

//Safety 
emaLength2 = input(title="Safety EMA Length", type=input.integer, defval=70, minval=0)
emaSource2 = input(close, title="Safety EMA Source")
ema = ema(emaSource2, emaLength2)
emaColorSource2 = close
emaBSource2 = close

// Backtest+Dates
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2019, title = "From Year", minval = 2017)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)
showDate  = input(defval = true, title = "Show Date Range", type = input.bool)
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)        // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest end window
window()  => time >= start and time <= finish ? true : false       // create function - add window() to entry/exit/close

// Conditions
exit_long = crossover(emaVal, condSource)
longCond = crossunder(emaVal, condSource) and close > ema

//Stoploss + TakeProfit
sl = input(0.051, step=0.001, title="Stop Loss")
tp = input(0.096, step=0.001, title="Take Profit")

// Plots Colors
colors = emarsiSource > emaVal and rsiVal > 14 ? color.green : color.red
emaColorSource = input(close, title="Line Color Source")
emaBSource = input(close, title="Line Color B Source")

// Plots
plot(ema, color=emaColorSource2[1] > ema and emaBSource2 > ema ? color.green : color.red, linewidth=1)
plot(emaVal, color=emaColorSource[1] > emaVal and emaBSource > emaVal ? color.green : color.red, linewidth=3)
plotcandle(open, high, low, close, color=colors)


//Strategy Entry+Exits
strategy.entry("long",1,when=window() and longCond)
strategy.close("long",when=window() and exit_long)
strategy.exit("long tp/sl", "long", profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick)
