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

//@version=4
study(title="A_HMS_LAST", overlay=true , max_lines_count=500 , max_bars_back=500)

////////////////////////////////pivots///////////////
pvtLenL          = input(10,minval=1,title="Length Left")
pvtLenR          = input(10,minval=1,title="Length Right")
ShowPivotLabels  = input(false)
pvthi = pivothigh(pvtLenL,pvtLenR)
pvtlo = pivotlow(pvtLenL,pvtLenR)
plotshape(ShowPivotLabels? pvthi[1]: na, title='Pivot High Label', style=shape.triangledown, size = size.tiny ,color = color.red,  location=location.abovebar,size=size.auto ,offset=-pvtLenR-1,transp=0)
plotshape(ShowPivotLabels? pvtlo[1]: na, title='Pivot Low Label', style=shape.triangleup, size = size.tiny ,color = color.green , location=location.belowbar,size=size.auto , offset=-pvtLenR-1,transp=0)

/////////////////////////////////////////////////$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$///////////////////////////


//EMA_Lines__START******************************************************************************************************************
//*****************************************************************************************************************************
source = input(type = input.source , defval = ohlc4 , title = "Source:")
showema9 = input(true , title = "Show EMA9 Lines ?")
showema19 = input(true , title = "Show EMA19 Lines ?")
showema33 = input(true , title = "Show ema33 Line ?")
showema66 = input(true , title = "Show ema66 Line ?")
showema99 = input(true , title = "Show ema99 Line ?")
showema199 = input(true , title = "Show ema199 Line ?")
show_emas =  input(true , title = "Show EMA LineS ?")
ema9n = input(title = "EMA9" , type = input.integer , defval = 9)
ema19n = input(title = "EMA19" , type = input.integer , defval = 19)
ema33n = input(title = "EMA33" , type = input.integer , defval = 33)
ema66n = input(title = "EMA66" , type = input.integer , defval = 66)
ema99n = input(title = "EMA99" , type = input.integer , defval = 99)
ema199n = input(title = "EMA199" , type = input.integer , defval = 199)
ema9 = ema(source , ema9n)
ema19 = ema(source , ema19n)
ema33 = ema(source , ema33n)
ema66 = ema(source , ema66n)
ema99 = ema(source , ema99n)
ema199 = ema(source , ema199n)
plot(showema9 and show_emas ? ema9 : na ,color = color.navy , transp=80 , linewidth = 1 , title = "EMA9")
plot(showema19 and show_emas ? ema19 : na ,color = color.orange , linewidth = 2 , title = "EMA19")
plot(showema33 and show_emas ? ema33 : na  ,  color = color.rgb(59, 113, 115 , 80) , linewidth = 1 , title = "EMA33")
plot(showema66 and show_emas ? ema66 : na ,  color = color.black, linewidth = 1 , title = "EMA66")
plot(showema99 and show_emas ? ema99 : na ,  color = color.aqua, linewidth = 1 , title = "EMA99")
plot(showema199 and show_emas ? ema199 : na ,  color = #9333FF , linewidth = 1, title = "EMA199 ")



//High EMAs
showema299 = input(true , title = "Show ema299 Line ?")
ema299n = input(title = "EMA299" , type = input.integer , defval = 299)
ema299 = ema(source , ema299n)
plot(showema299 or show_emas ? ema299 : na ,   color = color.rgb(159, 113, 115 , 85) , linewidth = 1, title = "EMA299 ")


showema399 = input(true , title = "Show ema399 Line ?")
ema399n = input(title = "EMA399" , type = input.integer , defval = 399)
ema399 = ema(source , ema399n)
plot(showema399 or show_emas ? ema399 : na ,   color = color.rgb(159, 113, 115 , 85) , linewidth = 1, title = "EMA399 ")


showema499 = input(true , title = "Show ema499 Line ?")
ema499n = input(title = "EMA499" , type = input.integer , defval = 499)
ema499 = ema(source , ema499n)
plot(showema499 or show_emas ? ema499 : na ,   color = color.rgb(159, 113, 115 , 85) , linewidth = 1, title = "EMA499 ")


showema599 = input(true , title = "Show ema599 Line ?")
ema599n = input(title = "EMA599" , type = input.integer , defval = 599)
ema599 = ema(source , ema599n)
plot(showema599 or show_emas ? ema599 : na ,   color = color.rgb(159, 113, 115, 85) , linewidth = 1, title = "EMA599 ")

showema699 = input(true , title = "Show ema699 Line ?")
ema699n = input(title = "EMA699" , type = input.integer , defval = 699)
ema699 = ema(source , ema699n)
plot(showema699 or show_emas ? ema699 : na ,   color = color.rgb(159, 113, 115, 85) , linewidth = 1, title = "EMA699 ")

showema799 = input(true , title = "Show ema799 Line ?")
ema799n = input(title = "EMA799" , type = input.integer , defval = 799)
ema799 = ema(source , ema799n)
plot(showema799 or show_emas ? ema799 : na ,   color = color.rgb(159, 113, 115, 85) , linewidth = 1, title = "EMA799 ")

showema899 = input(true , title = "Show ema899 Line ?")
ema899n = input(title = "EMA899" , type = input.integer , defval = 899)
ema899 = ema(source , ema899n)
plot(showema899 or show_emas ? ema899 : na ,   color = color.rgb(159, 113, 115, 85) , linewidth = 1, title = "EMA899 ")

showema999 = input(true , title = "Show ema999 Line ?")
ema999n = input(title = "EMA999" , type = input.integer , defval = 999)
ema999 = ema(source , ema999n)
plot(showema999 or show_emas ? ema999 : na ,   color = color.rgb(159, 113, 115, 85) , linewidth = 1, title = "EMA999 ")


//EMALines__END****************************************************************************************************************************
//******************************************************************************************************************************************

//EMAStrategy__START****************************************************************************************************************************
//******************************************************************************************************************************************
showemastrateg = input(false , title = "Show EMA Strateg?")
ema9s = ema(source , 9)
ema19s = ema(source , 19)
ema33s = ema(source , 33)
ema66s = ema(source , 66)
ema199s = ema(source , 199)
///////////////////////CROSSOVERS???????????????????????????????????????????
crossoverpoint1 = (crossover(ema19s , ema66s) and  crossover(ema19s , ema199s))
crossoverpoint2 = (crossover(ema9s , ema33s) and  crossover(ema9s , ema66s))

crossoverpoint3 = crossover(ema9s , ema33s) and crossover(ema9s , ema66s) and crossover(ema9s , ema199s)
crossoverpoint4 = (crossover(ema9s , ema19s) and  crossover(ema9s , ema33s) and crossover(ema9s , ema66s))

crossoverpoint5 = (crossover(ema9s , ema19s) and  crossover(ema9s , ema33s) and crossover(ema9s , ema66s))

bgcolor(crossoverpoint1 and showemastrateg  ? color.blue : na , transp = 50)
bgcolor(crossoverpoint2 and showemastrateg ? color.green : na , transp = 50)
bgcolor(crossoverpoint3 and showemastrateg ? color.red : na , transp = 50)
//bgcolor(crossoverpoint4 and showemastrateg ? color.black : na , transp = 50)
//bgcolor(crossoverpoint5 and showemastrateg ? color.purple : na  , transp = 50)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////CROSSUNDERS??????????????????????????/
crossunderpoint1 = (crossunder(ema19s , ema66s) and  crossunder(ema19s , ema199s))
crossunderpoint2 = (crossunder(ema9s , ema33s) and  crossunder(ema9s , ema66s))

crossunderpoint3 = (crossunder(ema9s , ema19s) and  crossunder(ema9s , ema66s) and crossunder(ema9s , ema199s))
crossunderpoint4 = (crossunder(ema9s , ema19s) and  crossunder(ema9s , ema33s) and crossunder(ema9s , ema66s))

crossunderpoint5 = (crossunder(ema9s , ema19s) and  crossunder(ema9s , ema33s) and crossunder(ema9s , ema66s))


bgcolor(crossunderpoint1 and showemastrateg  ? color.blue : na , transp = 50)
bgcolor(crossunderpoint2 and showemastrateg ? color.aqua : na , transp = 50)
bgcolor(crossunderpoint3 and showemastrateg ? color.orange : na , transp = 50)
//bgcolor(crossunderpoint4 and showemastrateg ? color.lime : na , transp = 50)
//bgcolor(crossunderpoint5 and showemastrateg ? color.olive : na  , transp = 50)
/////////////////////////////////////////////////////////////////////////////////
//EMAStrategy__END****************************************************************************************************************************
//******************************************************************************************************************************************
