Here is a light piece of code, The Indicator Integrator. It sums up a function (like an integral for you calculus folks). Unlike the 'cum' function that does a million bars of look back you can change the look back period, like limits of integration.

Built in is a difference of the close from an SMA. And there is an ROC. By changing what is summed up in the loop you can sum up the differences from the SMA or sum up the ROC. Pick your SMA length/ROC length. Then pick your look back period of how much to add up (bars to add up). There is a built in SMA smoother of three bars on the final summation.

Comments welcomed

Built in is a difference of the close from an SMA. And there is an ROC. By changing what is summed up in the loop you can sum up the differences from the SMA or sum up the ROC. Pick your SMA length/ROC length. Then pick your look back period of how much to add up (bars to add up). There is a built in SMA smoother of three bars on the final summation.

Comments welcomed

//@version=2 study("Indicator Integrator") l = input(defval=20,title="Length for indicator",type=integer) s = input(title="Length of summation",type=integer,defval=40) a= sma(close,l) r=roc(close,l) k=close-a sum = 0 for i = 0 to s sum := sum + k[i] bc = iff( sum > 0, white, teal) plot(sum,color=bc, transp=20, linewidth=3,style=columns) plot(sma(sum,3),color=white) hline(0)