EMA_TREND_CATCHER
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pernath

//@version=5
strategy("TREND_CATCHER", overlay=true, commission_value=0.05, commission_type=strategy.commission.percent, initial_capital=1000)

//#####variables##############
profit_short=input(title='profit_short', defval=27)
stop_short=input(title='stop_short', defval=2)

stop_long=input(title='stop_long', defval=3)
profit_long=input(title='profit_long', defval=35)


media_1=input(title='media_1', defval=55)
media_2=input(title='media_2', defval=100)
resta_medias=input(title='resta_medias', defval=0)
resta_medias2=input(title='resta_medias2', defval=0)

RSI_periodos=input(title='RSI_periodos', defval=42)
//###############VARIABLES###################




//#####Alert#####
id_bot = ""
email_token = ""
long_open =""
long_close =""
short_open =""
short_close =""
//#  {{strategy.order.alert_message}}


//#############################
//#############################

//###############EMA##############/
//plot(ta.ema(close, 1), title='ema 5', color=color.white)
plot(ta.ema(close, 12), title='ema 12', color=color.white)
plot(ta.ema(close, 25), title='ema 25', color=color.white)
plot(ta.ema(close, 30), title='ema 30', color=color.white, linewidth=1)
plot(ta.ema(close, 40), title='ema 40', color=color.white, linewidth=1)
plot(ta.ema(close, 55), title='ema 55', color=color.orange, linewidth=1)
plot(ta.ema(close, 100), title='ema 100', color=color.red, linewidth=1)
plot(ta.ema(close, 200), title='ema 200', color=color.white, linewidth=3)

//#############################/





//######VISUAL#############
EMA50 = ta.ema(close, 55)
EMA100 = ta.ema(close, 100)


estado_medias=EMA50-EMA100




a = plot(EMA50, title="EMA(50)", color=color.orange, linewidth=1 ) 
b = plot(EMA100, title="EMA(100)", color=color.red, linewidth=1 )


var color col = na
col := estado_medias>resta_medias ? color.green : color.red
fill(a,b,color=col,transp=40)


//######VISUAL#############





Go_Short=(ta.crossunder(ta.ema(close,100),ta.ema(close,200)))
Go_Long=((ta.crossover(ta.ema(close,55),ta.ema(close,100))and(ta.ema(close,12)>ta.ema(close,200))))


strategy.close("enter long", (Go_Short),alert_message=long_open)

cancelar_short=((ta.crossunder(ta.ema(close,25),ta.ema(close,6))))



if Go_Short
    strategy.entry("enter short", strategy.short,1, alert_message=short_open) 
  
strategy.exit("cerrar short", "enter short", 1, profit=close*profit_short/100/syminfo.mintick, loss=close*stop_short/100/syminfo.mintick, alert_message=short_close)




strategy.close("enter short", (Go_Long),alert_message=short_close)
cancelar=((ta.crossunder(ta.ema(close,12),ta.ema(close,30))))



if Go_Long
    strategy.entry("enter long", strategy.long,1,alert_message=long_open)

strategy.exit("cerrar long", "enter long", 1, profit=close*profit_long/100/syminfo.mintick, loss=close*stop_long/100/syminfo.mintick, alert_message=long_close)




strategy.close("enter short", (cancelar_short),alert_message=short_close)

strategy.close("enter long", (cancelar),alert_message=long_close)


//posiciones abiertas
bgcolor((strategy.position_size > 0 or strategy.position_size < 0) ? color.blue : na, transp=70)







