[HELP] With small coding problem of indicator!

 

Hi guys. I have this indicator of La Selle Street in .els need it in mql4 now for my ea. Its real basic but cant get it to work right.

For the first 3 bars the regEMA buffer should equal the close price from there it should go over and do the calculation as u need regEMA[2] for the calculation thus first 3 bars must equal close. Here is my code, help would be gladly appreciated!!!

extern int EMA_Length = 22;
double PctBelow  = 0.5;
double PctAbove  = 0.5;

double Alpha=0.0, PctBelowFactor=0.0, PctAboveFactor=0.0;
int start()
{
int counted_bars=IndicatorCounted();
int limit;
if      (counted_bars < 0) return(-1);
if      (counted_bars > 0) counted_bars--;
limit = Bars-counted_bars;

Alpha = 2/(EMA_Length + 1);
PctBelowFactor  = (1 - (0.5*0.01)); 
PctAboveFactor  = (1 + (0.5*0.01));

int limit2 = Bars - IndicatorCounted();
for (int i = limit2; i>= 0; i--)
{
        if (i > 3)
        {
        regEMABuffer[i] = (regEMABuffer[i+1]*(1+2*0.5) + Alpha*(Close[i]-regEMABuffer[i+1]) - 0.5*regEMABuffer[i+2]) /1.5;
        }
        else
        {
        regEMABuffer[i] = Close[i];
        }

        lowerRemaBuffer[i] = regEMABuffer[i] * PctBelowFactor;
        upperRemaBuffer[i] = regEMABuffer[i] * PctAboveFactor;
} 
        return(0);
}

I also attached a text file with the working easylanguage code for Tradestation as well as a mq4 file with my code where I tried converting it.

Files:
 
e-Invester: thus first 3 bars must equal close.
Bars [0, .. 3] are the last (newest)
 
WHRoeder:
Bars [0, .. 3] are the last (newest)
I have also tried it with -3 also to run 2 for-loops, one to place the value of Close[i] in the first 3 places of the array and then another for-loop to do the calculation from the forth place onward, this also failed.
 
Bars are numbers [0.. Bars-1] there is no -3. 0 is the newest. What is the last (oldest) three bars? Bar-1 Bars-2 Bars-3
Reason: