Please help, school project indicator buffer help.

 

I have a school project for calculus 2 and its an indicator based off the the Autoregressive price extrapolator by gpwr except it prints the predicted values into bars. I would like to add a confidence cloud to the indicator, but I've been having problems implementing it. Another two issues are I want it to recalculate only if there is a new bar not every tick and It is supposed to print blue bars if they are up and red bars if they are down, but it only prints blue ones. The cloud needs to have a linear moving average between the first predicted bar and the last predicted (Nfuture) bar so that the confidence cloud isnt fluctuating because that iMA is what the cloud will use to derive its curve.

The 2 period iMA equation for the first predicted bar to the last predicted bar (I think?):

operup[Nfuture-i]=iMA(NULL,0,2,0,MODE_SMA,PRICE_OPEN);

The equation (I think) for the upper confidence line would be:

ConfidenceUpBuffer[Nfuture-i]=MathSqrt(operup[Nfuture-i])*(dev+1);

The equation (I think) for the lower confidence line:

ConfidenceDownBuffer[Nfuture-i]=(operup[Nfuture-i])-(MathSqrt(operup[Nfuture-i]*(dev+1)));

The equation to fill the difference between upper and lower confidence lines:

ConfidenceCloudBuffer1[Nfuture-i]=(ConfidenceUpBuffer[Nfuture-i]-operup[Nfuture-i])-(operup[Nfuture-i]-ConfidenceDownBuffer[Nfuture-i]);

The Current indicator looks like this:

The indicator with added confidence cloud (NOTE: the red line indicates the iMA, but it should not be visible when placed on a chart):

 

Files: