ADX Trend Filter
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderharikrishna

//@version=5
indicator("ADX Trend Filter")
txtcol=input.color(color.gray,'Text Color')
[p,m,a]=ta.dmi(14,14)
plot(a,style = plot.style_area,color=color.red)
m1=ta.ema(close,12)
m2=ta.ema(close,50)
mcolor=m1>m2?color.rgb(79, 163, 81):color.rgb(77, 23, 28)
plot(p,color=color.rgb(4, 104, 1),style = plot.style_columns,title='Buy')
plot(m,color=color.rgb(163, 2, 2),style = plot.style_columns,title='Sell')
barcolor(p>m and a>20?color.rgb(4, 104, 1):p<m and a>20?color.rgb(163, 2, 2):color.rgb(247, 222, 4))
plot(20,style = plot.style_area,color=mcolor,title='MA BAND')
plotshape(ta.crossover(p,m) and p>m?2:na,title = 'ADX up',color=color.rgb(3, 136, 8),location=location.absolute,style = shape.triangleup,size=size.tiny)
plotshape(ta.crossunder(p,m) and p<m?18:na,title = 'ADX Down',color=color.rgb(243, 38, 11),location=location.absolute,style = shape.triangledown,size=size.tiny)
alertcondition(ta.crossover(p,m) and p>m,title='ADX Up',message = 'ADX Crossed Up')
alertcondition(ta.crossunder(p,m) and p<m,title='ADX Down',message = 'ADX Crossed Down')

status = table.new(position.top_right, 11, 20, border_width=1)
emtrend=m1>m2?color.green:color.red
adxdir=p>m?color.green:color.red
adxstren=p>m and a>20?color.rgb(4, 104, 1):p<m and a>20?color.rgb(163, 2, 2):color.rgb(247, 222, 4)
candle=open<close?color.green:color.red
adxcx=ta.barssince(ta.cross(p,m))

table.cell(status, 0, 1, text='', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 0, 2, text='Candle is', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 0, 3, text='ADX Direction is',  bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 0, 4, text='ADX Strength is', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 0, 5, text='EMA Trend is', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)


table.cell(status, 1, 1, text='', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 1, 2, text=' ', bgcolor=candle,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 1, 3, text=str.tostring(adxcx),  bgcolor=adxdir,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 1, 4, text=' ', bgcolor=adxstren,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
table.cell(status, 1, 5, text=' ', bgcolor=emtrend,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
