SuperCloud
// 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("SuperCloud")
shmac=input(true,'MACD')

showinfo=input(true,'Trend Info')
side=input.int(10,'Sideways MA Length')
e5=ta.ema(close,5)
e10=ta.ema(close,10)
e20=ta.ema(close,20)
e50=ta.ema(close,50)
e100=ta.ema(close,100)
e200=ta.ema(close,200)
xm1=input.int(5,'MA1')
xm2=input.int(50,'MA2')
em1=ta.ema(close,xm1)
em2=ta.ema(close,xm2)
pe=input.int(200,'Candle Plot Reference MA')
p1=ta.ema(close,pe)
d1=e5-e10
d2=e5-e20
d3=e5-e50
d4=e5-e100
d5=e5-e200
o=close-e200
o1=plot(o,display=display.none)

f1=plot(d1,display=display.none,title='MA200')
f2=plot(d2,display=display.none,title='MA100')
f3=plot(d3,display=display.none,title='MA50')
f4=plot(d4,display=display.none,title='MA20')
f5=plot(d5,color=color.white,title='MA5')
sw=side*syminfo.mintick
hline(0,title='0',linewidth = 1,color = color.white)

da=d1<d5
db=d4<d5
dc=d3<d4
dd=d2<d3
ad=d1<d2

fill(f1,f5,color=da?input.color(color.rgb(29, 97, 29),'Cloud Up'):input.color(color.rgb(128, 37, 37),'Cloud Down'),title='MA5Cloud')
fill(f5,f4,color=db?color.rgb(0, 0, 0, 90):color.rgb(0, 0, 0, 90),title='MA12Cloud')
fill(f4,f3,color=dc?color.rgb(0, 0, 0, 70):color.rgb(0, 0, 0, 70),title='MA20Cloud')
fill(f3,f2,color=dd?color.rgb(0, 0, 0, 50):color.rgb(0, 0, 0, 50),title='MA50Cloud')
fill(f1,f2,color=ad?color.rgb(2, 2, 2, 20):color.rgb(2, 2, 2, 20),title='MA100Cloud')
fill(o1,f5,color=o>d5?input.color(color.rgb(0, 255, 0),'Buy'):input.color(color.rgb(255, 0, 0, 0),'Sell'),title='Buy Sell')
sw1=plot(sw,title='Upper Sideways',color=color.gray,display=display.none,offset=100)
sw2=plot(-sw,title='Lower sideways',color=color.gray,display=display.none,offset=100)
fill(sw1,sw2,color = color.rgb(255, 255, 255, 88))

[m,s,h]=ta.macd(close,12,26,9)
mac1=plot(shmac?s:na,color=color.yellow,display=display.none)
mac2=plot(shmac?m:na,color=color.rgb(7, 2, 255),display=display.none)
fill(mac1,mac2,color=m>s?color.rgb(0, 211, 248):color.rgb(253, 4, 87))

//hk=input.bool(true,'HA Candles')
//ha = ticker.heikinashi(syminfo.tickerid)
//[ho, hh, hl, hc] = request.security(ha, timeframe.period, [open, high, low, close])
//hccolor = hc >= ho ?#36b3059c:#af063ea8
//hoa=ho-p1
//hob=hh-p1
//hoc=hl-p1
//hod=hc-p1

//op=hk?hoa:open-(p1)
//hi=hk?hob:high-(p1)
//lo=hk?hoc:low-(p1)
//cl=hk?hod:close-(p1)
//ccolor=open<close?#36b3059c:#af063ea8
//cbcolor=open<close?#36b3059c:#af063ea8
//plotcandle(op,hi,lo,cl,color = hk?hccolor:ccolor,wickcolor = hk?hccolor:cbcolor,bordercolor = hk?hccolor:cbcolor)

plot(em1-e200,color=color.rgb(0, 17, 255),linewidth=2)
plot(em2-e200,color = #ff0055,linewidth=2)
alertcondition(ta.crossover(em1,em2),'EMA Crossover Buy Signal','EMA Crossover Buy Signal')
alertcondition(ta.crossunder(em2,em1),'EMA Crossunder Sell Signal','EMA Crossunder Sell Signal')
plotshape(ta.crossover(close,e20)?d5:na,title='MA20 Crossover',size=size.tiny,color=color.rgb(0, 211, 248),style=shape.circle,location=location.absolute)
plotshape(ta.crossunder(close,e20)?d5:na,title='MA20 Crossunder',size=size.tiny,color=color.rgb(253, 4, 87),style=shape.circle,location=location.absolute)

txtcol=input.color(#fffefe,title='Text Color')
if (showinfo)
    status = table.new(position.middle_right, 11, 20, border_width=1)
    table.cell(status, 1, 1, text='', bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
    table.cell(status, 1, 4, text='Sideway +/-'+str.tostring(sw), bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
    table.cell(status, 1, 5, text='MA Crossover is '+str.tostring(xm1)+'/'+str.tostring(xm2), bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
    table.cell(status, 1, 6, text='Trend Strength is '+str.tostring(d5/syminfo.mintick,'#######.#####'), bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
    table.cell(status, 1, 7, text='(-20) Strength is '+str.tostring(d5[20]/syminfo.mintick,'#######.#####'), bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)
    //trendstr = (d5[0]-d5[20])/syminfo.mintick
    //trendstr2=trendstr>0?'Increasing':trendstr<0?'Decreasing':'neutral'
    //table.cell(status, 1, 7, text='Trend Strength is '+trendstr2, bgcolor=na,text_color=txtcol, text_size=size.small,text_halign=text.align_left)

