Delox EMA Cross
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Cryptoleal 


//@version=5
indicator("Delox EMA Cross", overlay= true)
EmasGrup        = 'EmasGrup'
showBarwhite   = input.bool (true, 'Show Bar White', group=EmasGrup)

EmaFast= input.int(14, title="Ema Fast", minval=1, group=EmasGrup)
EmaSlow= input.int(21, title="Ema Slow", minval=1, group=EmasGrup)

stochasticGrup        = 'Stochastic Grup'
periodK = input.int(14, title="%K Length", minval=1, group=stochasticGrup)
smoothK = input.int(1, title="%K Smoothing", minval=1, group=stochasticGrup)
periodD = input.int(3, title="%D Smoothing", minval=1, group=stochasticGrup)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)






///// Emas 

Ema14 = ta.sma(close,EmaFast)
Ema21 = ta.sma(close,EmaSlow)

h0=plot(Ema14, title = "Ema Fast 14", color = Ema14>Ema21 ? color.green : color.red)

h1=plot(Ema21,  title = "Ema Slow 21", color = Ema14>Ema21 ? color.green : color.red)

LongCross= ta.crossover(Ema14,Ema21)
DownCross= ta.crossunder(Ema14,Ema21)


WhiteBar= ta.cross(Ema14,Ema21)

barcolor(WhiteBar and showBarwhite? color.rgb(255, 255, 255) : na)


fill(h0, h1, color = Ema14>Ema21 ? color.rgb(76, 175, 79, 32) : color.rgb(255, 82, 82, 36))





// Table Props
gr50        = 'Table'
showTable   = input.bool (true, 'Showtable', group=gr50)
tabPosI_    = input.string('Top', 'Table Position', ['Top', 'Middle', 'Bot'], group=gr50)
tabPos_     = tabPosI_=='Top'? position.top_right : tabPosI_=='Bot'? position.bottom_right : position.middle_right
tabColor    = input.color(color.black , 'Background', group=gr50)

TrendColor  = input.color(color.rgb(165, 21, 178), 'backgroundBollcolor', group=gr50)
stochasticBluecolor  = input.color(color.rgb(1, 132, 203, 21), 'backgroundBollcolor', group=gr50)
stochasticOrangecolor = input.color(color.rgb(240, 123, 5, 20), 'backgroundBollcolor', group=gr50)
borderCol   = input.color(color.black , 'Border', group=gr50)
tabTextCol  = input.color(color.white, 'tabTextColor', group=gr50)


trendtext = 'Hi Error '

if Ema21<Ema14
    TrendColor:= color.rgb(4, 255, 54, 44) 
    trendtext:= 'Upward trend 🎉🦾📈'

else if Ema21>Ema14
    TrendColor:= color.rgb(252, 5, 5, 46) 
    trendtext:= 'Downward trend 🪂📉'

/////// Table plot 


saTable     = table.new(tabPos_, 10, 10, tabColor, borderCol, 1, borderCol, 1)
if showTable
    table.cell(saTable, 0, 0, 'Ema  14: ' +str.tostring(Ema14)    , text_color=tabTextCol, text_size=size.small,bgcolor= TrendColor)
    table.cell(saTable, 0, 1, 'Ema  21 ' + str.tostring(Ema21)  , text_color=tabTextCol, text_size=size.small,bgcolor= TrendColor)
    table.cell(saTable, 0, 3,  trendtext , text_color=tabTextCol, text_size=size.small,bgcolor= TrendColor)
    table.cell(saTable, 0, 4,  'Stochastic K Blue :'+ str.tostring(k) , text_color=tabTextCol, text_size=size.small,bgcolor= stochasticBluecolor)
    table.cell(saTable, 0, 5,  'Stochastic  D Orange :' + str.tostring(d), text_color=tabTextCol, text_size=size.small,bgcolor= stochasticOrangecolor)



bgcolor(LongCross and d< 40? color.rgb(0, 230, 46, 41) :na)
bgcolor(DownCross and d> 60? color.rgb(255, 0, 0, 45) :na)




alertcondition(LongCross and d< 40, title='Buy Alert', message='Buy Alert')
alertcondition(DownCross and d> 60, title='Sell Alert', message='Sell Alert')


alertcondition(WhiteBar, title='White Bar', message='White Bar')


    

