iBullsPower and iBearsPower are returning the same value per period in Tester - any reason why my code would be doing this?

 

any reason why the following code would print out the same value for iBullsPower and iBearsPower in the following code? -


bool newBar = false;

int start()
  {
 
   newBar();
   if (newBar == false) return;
  
   double bullsPwr = iBullsPower(Symbol(), PERIOD_M15, 13, PRICE_CLOSE, 0);
   double bearsPwr = iBearsPower(Symbol(), PERIOD_M15, 13, PRICE_CLOSE, 0);
  
   Print("BullsPwr = ", bullsPwr, "BearsPwr = ", bearsPwr);
  
   return(0);
  }

void newBar() {
   static datetime newTime = 0;
   newBar = false;
  
   if (newTime != Time[0]) {
      newTime = Time[0];
      newBar = true;
   }
}
 
Tester limitation: You can not get bar zero of other timeframes/pairs
 
WHRoeder:
Tester limitation: You can not get bar zero of other timeframes/pairs

I've backtested this code, and I do get different values for bullsPwr and bearsPwr provided that the timeframe being tested (the "Period" field in the Strategy Tester) is lower than M15. If I run the backtesting on e.g. H1, then I do get the same value for bullsPwr and bearsPwr - and it's not a zero value.

The problem is not that you can't get bar zero of other timeframes. The problem is as follows:

  • The calculation is being done at the start of a new bar in the tester.
  • If the timeframe of the tester is higher than M15, then a new M15 bar has also just started.
  • At this point, bar 0 on M15 consists of a single tick, and the bar's open, high, low, and close are all the same value.
  • The formula for bulls/bears power is current high/low minus exponential moving average.
  • Therefore, if you calculate bulls and bear power on the first tick of a bar, you get the same value for each, because the current high and low are the same.
That's why you get the same values for bulls and bear if the strategy tester timeframe is >= M15, but not if the timeframe is < M15.

In your code it would therefore seem to make more sense to use a bar offset of 1, not zero.
Reason: