Calculations Confusion

 

Hey Folks,

I have the following problem with this code: It is not showing the things I want it to show (obvious, otherwise I wouldn't be posting here).

With the Maximum Potential Range Efficiency (I know, a pretty hyped up name, but couldn't think of anything better) I wanted to determine wether we are trending (using the Maximum movement) or if we are ranging. So my thought was:

If the market is clearly trending up, the accumulated price Movement of x Candles would be pretty much the overall price Movement...so look at this:



We add all the candles up and divide the sum by the overall price movement over these six bars and take the result times 100. What we just did was percentage calculations. So it should turn out to be 100%. But it doesnt. I have entered the MPRE Period at 6 and get the following result: (The bottom one is the MPRE)




I have attached the code for you to see what's wrong.

Here's the essential bit. It's not perfect yet and unefficient but I need to solve this problem first...to after that optimize on calc speed:

//---- MPRE Calculations
   for(int i=0; i<limit; i++)
      {
      Sum=0;
      for(int n=MPREPeriod*(-1); n<=0; n++)
         {
         Sum=Sum+MathAbs(Open[n+1]+Open[n]);
         }
      MPREBuffer[i]=(MathAbs(Open[MPREPeriod+i]+Open[i])/Sum)*100;
      }
//---- Done
Thanks...
Files:
mpre.mq4  2 kb
 

Just need to ask again...

Reason: