A simple script that calculates the percent above or below a moving average.
//@version=2 study("% Above/Below SMA") //inputs len=input(defval=200) //vars c=close sma200=sma(close,len) diff=((c-sma200)/c)*100 // horizontal linenp hline(0) //color the line colr=diff >0 ? white : black //plot plot(diff,color=colr,linewidth=2,style=histogram)