Calculating average WPR retrace over x bars

 

Dear experts,

I was hoping to code up something to determine how far price retraces when a certain iWPR values is hit.

For example, price goes up and eventually hits iWPR > -5 and we're calling it an overbought, price eventually retraces. I want to determine somehow by how much on average this happens IF it happens at all (negative number if it doesn't).

Could this be done without the strategy tester? I'm fairly new with MQL, I noticed I can use buffers in indicators to access older values?

So, say I start the function I'd write at -1000 bars, get the iWPR value until it hits and overbought/oversold level...then when that happens, note price and continue shifting bars forward until the opposite signal is detected?

How would you code that, and what difficulties would you expect?

Sincerely,

Caal 

 
caal:

How would you code that, and what difficulties would you expect?

Just a simple while loop . . .

int BarIndex, iWPRPeriod = 14;


BarIndex = 1000;

while(BarIndex > 0)
   {
   if(iWPR(NULL, 0, iWPRPeriod, BarIndex) > -5.0 )
      {
      Print("Overbought at bar: ", BarIndex, " at price (Bar High): ", High[BarIndex]);
      }
   
   if(iWPR(NULL, 0, iWPRPeriod, BarIndex) < -95.0 )
      {
      Print("Oversold at bar: ", BarIndex, " at price (Bar Low): ", Low[BarIndex]);
      }   
   
   BarIndex--;
   }

 not compiled or tested.

You don't ever need to use the Strategy Tester if you don't want to . . .  but it is a good place to test your code. 

Reason: