MAX_MIN_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("MAX_MIN_V1", overlay=true)

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

//angulo_mdl_short=input(title='angle_mdl_short', defval=-3.0)
//angulo_mdl_long=input(title='angle_mdl_long', defval=10.0)
var_ema=input(title='var_ema', defval=500)
var_mdl=input(title='var_mdl', defval=35)
var_mdl2=input(title='var_mdl2', defval=400)//SOL


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

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


//#######HIGH_LOW_MID################
highestHigh = ta.highest(high, 1000)[1]
lowestLow   = ta.lowest(low, 1000)[1]


middle=(highestHigh+lowestLow)/2
   

highestHigh_val=ta.sma(highestHigh,100)
lowestLow_val=ta.sma(lowestLow,100)

plot(highestHigh_val, color=color.green, linewidth=2, title="Highest High")
plot(lowestLow_val, color=color.red, linewidth=2, title="Lowest Low")

middle_val=ta.sma(middle,100)
plot(middle_val, color=color.white, linewidth=1, title="middle")


//#######HIGH_LOW_MID################



mdl = ta.sma(close, var_mdl) // 20 trading days simple moving average
mdl2 = ta.sma(close, var_mdl2)


//*****ANGLE EMA*********//
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)

//*****ANGLE EMA*********//

//###############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'


if (angulo(middle_val))>0.1
    var_color:=color.green
    var_trade:='L'

if (angulo(middle_val))<-0.1
    var_color:=color.red
    var_trade:='S'

if ((angulo(middle_val))>-0.1)and((angulo(middle_val))<0.1)
    var_color:=color.yellow
    var_trade:='N'


plot(middle_val, title='middle_color', color=var_color,style=plot.style_linebr, linewidth=1)
//plot(ta.ema(close, 200), title='ema 200', color=var_color,style=plot.style_linebr, linewidth=2)

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


muestra=1000
diferencial_total=0.0

for i = 1 to muestra
    diferencial_total:=diferencial_total+(((high[i]-low[i])*100)/close[i])
      
    

diferencial_tot=diferencial_total/muestra

angulo_mdl=angulo(mdl)

highestHigh_2 = ta.highest(high, 100)[1]

bcolor = ta.crossunder(close,middle_val) ? color.red :  ta.crossover(close,middle_val) ? color.green: close<middle_val ? color.red : close>middle_val ? color.green: color.green // : color.black 

barcolor(bcolor)





















