5Ema Indicator only sell signals
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JOJO
//@version=5

indicator(title='5Ema Indicator only sell signals', overlay=true)

RR = input.int(defval=3, title='Risk to Reward Ratio', minval=1, maxval=100)
ema = ta.ema(close,5)
pema = plot(ema, '5 Ema', color=color.black, linewidth=2)


var bool Short  = na
var int shortC = 0
var int sellstoplosshitC = 0
var int selltargethitC = 0
var float sellstoploss = na
var float selltargetl = na
var float selltarget = na
var float sellat = na
var float alert_shorthigh = na
var float alert_shortlow = na


Short := shortC == 0 and low[1] > ema[1] and low[1] > low
sellstoplosshit = high > sellstoploss and shortC > 0 and sellstoplosshitC == 0
selltargethit = low < selltarget and shortC > 0 and selltargethitC == 0


if Short
    shortC := shortC + 1
    sellstoplosshitC := 0
    selltargethitC := 0
    alert_shorthigh := high[1]
    sellstoploss := high[1]  
    selltargetl := (high[1] - low[1]) * RR
    selltarget := low[1] - selltargetl
    sellat := low[1]
    
if sellstoplosshit == false and selltargethit == false and shortC > 0
    sellstoplosshitC := 0
    selltargethitC := 0
else
    if sellstoplosshit
        shortC := 0
        sellstoplosshitC := sellstoplosshitC + 1
    else
        if low < selltarget and shortC > 0 and selltargethitC == 0
            shortC := 0
            selltargethitC := selltargethitC + 1

plotshape(Short, title='Sell', location=location.abovebar, color=color.teal, style=shape.arrowdown, text='Sell', textcolor=color.teal)
plotshape(sellstoplosshit, title='Short SL Hit', location=location.abovebar, color=color.red, style=shape.arrowdown, text='Short SL Hit', textcolor=color.red)
plotshape(selltargethit, title='Short Target Hit', location=location.belowbar, color=color.green, style=shape.arrowup, text='Short Target Hit', textcolor=color.green)

alertcondition(Short, "Go Short", "Go Short")
alertcondition(sellstoplosshit, "Stop-loss hit", "Stop-loss hit")
alertcondition(selltargethit, "Target hit", "Target hit")