BB_MDL_V1
// 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
indicator("BB_MDL_V1", overlay=true)

//###############VAR###################
//muestra=input(title='muestra', defval=20)
var_mdl=input(title='var_mdl', defval=35)


// Variables
var float lastTradePrice = na
var float lastTradeProfit = 0
var float learningRate = 0.01

//###############VAR###################


//###################BB################
//Parameter Setting
mdl = ta.sma(close, var_mdl)
dev = ta.stdev(close, 10) 

upr = mdl + 2*dev 
lwr = mdl - 2*dev 

pb = (close - lwr)*100/(upr - lwr) 
bbw = (upr - lwr)*100/mdl 

//Plot
//plot(mdl2, color = color.white) 
//p1 = plot(upr, color = color.blue) 
//p2 = plot(lwr, color = color.blue) 
//fill(p1,p2)

//###################BB################

//© Hugo Omar Klein
//*****ANGLE*********//
normalizacion=220
pendiente(y)=>
    y/y[1] - 1

angulo(y)=> 
    math.atan(pendiente(y)) *180/math.acos(-1) * normalizacion 

angulocruce(m1,m2)=>
    math.atan((pendiente(m1)-pendiente(m2)) / (1 + pendiente(m1) * pendiente(m2)))* 100 / math.acos(-1) * normalizacion

m1=ta.ema(close, 14)
m2=ta.ema(close, 21)

//hline(0,color=color.yellow)
//plot (angulo(m1))
//*****ANGLE*********//

//###############EMA##############/
var_color=color.black
var_trade=""
if (angulo(ta.ema(close, 200)))>1
    var_color:=color.green
    var_trade:='L'

if (angulo(ta.ema(close, 200)))<-1
    var_color:=color.red
    var_trade:='S'

if ((angulo(ta.ema(close, 200)))>-1)and((angulo(ta.ema(close, 200)))<1)
    var_color:=color.yellow
    var_trade:='N'

plot(ta.ema(close, 200), title='ema 200', color=var_color,style=plot.style_linebr, linewidth=2)
//plot(ta.ema(close, 50), title='ema 50', color=color.white, linewidth=2)
//#############################/

cross=ta.crossover(close,mdl)
bcolor2 = ta.crossunder(close,mdl) ? color.red :  cross ? color.green: close<mdl ? color.red : close>mdl ? color.green: color.green // : color.black 

barcolor(bcolor2)




















