Expert Standard Library: logic error in signal Williams' Percent Range

 

Even probably this code is not much used, I'm reporting this day zero bug for completeness, in case MQ wants to correct it.

Williams' %R oscillator (WPR) is in many way similar to RSI, with upper and lower ranges for detecting overbought and oversold price action. The theory is that one could look at reversals in these areas only to form trading decisions. 

However, due to what I believe is a bug of distraction, the code looks instead outside these areas:

MQL5\Include\Expert\Signal\SignalWPR.mqh

int CSignalWPR::LongCondition(void) 
...
   //--- if the model 1 is used, search for a reverse of the oscillator upwards behind the level of overselling
   if(IS_PATTERN_USAGE(1) && Diff(idx+1)<0.0 && WPR(idx+1)>-80.0)
      result=m_pattern_1;      // signal number 1
... 
int CSignalWPR::ShortCondition(void)
...
   //--- if the model 1 is used, search for a reverse of the oscillator downwards behind the level of overbuying
   if(IS_PATTERN_USAGE(1) && Diff(idx+1)>0.0 && WPR(idx+1)<-20.0)
      result=m_pattern_1;      // signal number 1

In both the if() statements, the WPR value check is done in error, as it should use less instead of greater, and viceversa.
Which cause the condition to be valid only when a reversal happens outside the range of oversold/overbought, that is, in the non decisive area. Just flip the chevrons around to get what Larry Williams wanted to convey.
It could have been caused by the peculiar negative scale of the oscillator as originally developed, which goes from 0 to -100, although the documentation duly notes this. In fact, the almost identically coded SignalRSI.mqh works fine, no surprise, as it uses a positive scale of 0 to +100.

 
Thanks. Will be checked, but the priority is low.