How to compute WPR value of an indicator buffer? - page 3

 

I just took a look at the WPR by MQ and I noticed a strange thing.

   while(i >= 0)
     {
       double dMaxHigh = High[Highest(NULL, 0, MODE_HIGH, ExtWPRPeriod, i)];
       double dMinLow = Low[Lowest(NULL, 0, MODE_LOW, ExtWPRPeriod, i)];      
       if(!CompareDouble((dMaxHigh - dMinLow), 0.0))
           ExtWPRBuffer[i] = -100*(dMaxHigh - Close[i]) / (dMaxHigh - dMinLow);
       i--;
     }

There are no such Highest() and Lowest() functions defined but yet it compiles and it works. Somehow the compiler must identify them as iHighest() and iLowest() but it probably shouldn't be doing that. I wonder what would happen if there were user functions called Highest() and Lowest().

Edit: I tried it, the compiler threw up a bunch of errors when I made a function called Highest().

 
SDC:

I just took a look at the WPR by MQ and I noticed a strange thing.

There are no such Highest() and Lowest() functions defined but yet it compiles and it works. Somehow the compiler must identify them as iHighest() and iLowest() but it probably shouldn't be doing that. I wonder what would happen if there were user functions called Highest() and Lowest().

Edit: I tried it, the compiler threw up a bunch of errors when I made a function called Highest().

Highest and Lowest are still supported but obsolete: https://docs.mql4.com/obsolete
 
RaptorUK:
Highest and Lowest are still supported but obsolete: https://docs.mql4.com/obsolete

Oh ok I didn't know they used to be the function names I never encountered them before.
 
RaptorUK:
OK, sorry to trouble you.


RaptorUK:

I took other's idea to take a break, and think I own you an apologize. So...Sorry for my words to you!

It just because I eager to get the problem resolved so much.

Anyway, the person who offer other people helps should not be treated like this, Sorry again!

By the way, by the time i take a rest, I solved the problem by myself and think maybe there's other people may need this.

So below is my resluts.

 

The first way is to use ArrayMaximum/Minimum() function to compute the local high/low.

the code:

//----Oscillator of Detrended Signal Computing Method 02
   ArraySetAsSeries(DtdValue,false);
   ArraySetAsSeries(DtdValueMax,false);
   ArraySetAsSeries(DtdValueMin,false);
   ArraySetAsSeries(DtdOsc,false);
   for(i=Osc_Period-1+counted_bars; i<=Bars; i++)
   {
      int indexmax = ArrayMaximum(DtdValue,Osc_Period,i-Osc_Period+1);
      DtdValueMax[i] = DtdValue[indexmax];
      int indexmin = ArrayMinimum(DtdValue,Osc_Period,i-Osc_Period+1);
      DtdValueMin[i] = DtdValue[indexmin];
      
      DtdOsc[i] = -1*(DtdValueMax[i]-DtdValue[i])/(DtdValueMax[i]-DtdValueMin[i])*100;
   }
   ArraySetAsSeries(DtdValue,true);
   ArraySetAsSeries(DtdValueMax,true);
   ArraySetAsSeries(DtdValueMin,true);
   ArraySetAsSeries(DtdOsc,true);

just part of the most important code....

the reslut pics:

01

the first signal is the MT4 iWPR, the second signal is the reslut export by my code.

you can see the dynamics is the same, but the exact value is different, it's because I use the "close" as the import data. and the iWPR use the "High/Low" as the import data.

 

the second way is to use the "for" loop to compute the local high/low.

the code:

//---- Oscillator of Detrended Signal Computing Method 01
   for(i=0; i<=limit-Osc_Period; i++)
   {
      DtdValueMin[i] = 999999;
      DtdValueMax[i] = -999999;
      for(int k=i; k<=Osc_Period+i-1; k++)
      {
         if(DtdValue[k] > DtdValueMax[i])
            DtdValueMax[i] = DtdValue[k];
         if(DtdValue[k] < DtdValueMin[i])
            DtdValueMin[i] = DtdValue[k];
      }
      DtdOsc[i] = ((DtdValue[i]-DtdValueMin[i])/(DtdValueMax[i]-DtdValueMin[i])-0.5)*2;
   }

the reslut pic is exactly the same as the last pics.

Reason: