FalconRed 5 EMA Indicator (Powerofstocks)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © falcon_red

//@version=5
indicator("FR_POS_5EMA_Indicator_V2", overlay=true)

shortRR=input.float(3, minval=1, title="Sell Risk:Reward Ratio")
buyRR=input.float(2, minval=1, title="Buy Risk:Reward Ratio")
showBUY=input(false, "Show Buy")
showSELL=input(true, "Show Sell")


draw_line(y,col,sty)=>line.new(x1=time-(10*60*1000),y1=y,x2=time+(60*60*1000),y2=y, color=col,xloc= xloc.bar_time, style=sty)
draw_label(y)=>
    display_text =str.format(" ({0})", math.round_to_mintick(y)) 
    label.new(x = time+(60*60*1000), y=y, text=display_text, textcolor=color.new(color.white,50), color=#00000000, xloc=xloc.bar_time)

ema15 = ta.ema(close, 15 )
ema5 = ta.ema(close, 5 )
sl= 0.0
tar = 0.0

type AlertCandle
    float o
    float h
    float l
    float c
    float v


var alertSellCandle = AlertCandle.new()
var alertBuyCandle = AlertCandle.new()


plot(ema5, color=color.green, title="5 EMA", linewidth=2)
plot(ema15, color=color.rgb(11, 74, 13), title="15 EMA", linewidth=2)


if low > ema5 or (not na(alertSellCandle) and alertSellCandle.l < low)
    alertSellCandle := AlertCandle.new(o=open, h=high, l=low, c=close, v=volume)

if high < ema15 or (not na(alertBuyCandle) and alertBuyCandle.h > high)
    alertBuyCandle := AlertCandle.new(o=open, h=high, l=low, c=close, v=volume)


plotshape(showSELL and low<alertSellCandle.l and not(barstate.isfirst), title="Sell Label", text="SELL",color=color.new(#ff000d, 0), location=location.abovebar, style=shape.labeldown, size=size.tiny, textcolor=color.white)
if showSELL and low<alertSellCandle.l and not(barstate.isfirst)
    sl := high>alertSellCandle.h?high:alertSellCandle.h
    tar := alertSellCandle.l-(shortRR*(sl-alertSellCandle.l))
    draw_line(sl,color.red,line.style_solid)
    draw_label(sl)
    draw_line(tar,color.green,line.style_solid)
    draw_label(tar)
    draw_line(alertSellCandle.l,color.rgb(0, 82, 246),line.style_solid)
    alertSellCandle := AlertCandle.new()


plotshape(showBUY and high>alertBuyCandle.h and not(barstate.isfirst), title="Buy Label", text="BUY",color=color.new(#2fec55, 0), location=location.belowbar, style=shape.labelup, size=size.tiny, textcolor=color.white)
if showBUY and high>alertBuyCandle.h and not(barstate.isfirst)
    sl := low<alertBuyCandle.l?low:alertBuyCandle.l
    tar := alertBuyCandle.h+(buyRR*(alertBuyCandle.h-sl))
    draw_line(sl,color.red,line.style_solid)
    draw_label(sl)
    draw_line(tar,color.green,line.style_solid)
    draw_label(tar)
    draw_line(alertBuyCandle.h,color.rgb(0, 82, 246),line.style_solid)
    alertBuyCandle := AlertCandle.new()
  
