The Bears Power oscillator increases after the Bulls divergence

 

I am trying to programm an EA relating to the criteria as described in the Bulls Power Indicator. The fourth criteria to open a buy position "the Bears Power oscillator increases after the Bulls divergence" is not so easy for me to translate as I am quite new to MQL4.

To know if there is a bullish divergence I must find out if the last trough of the indicator is higher than the previous one and if the last trough of the price is below the previous one. As shown on this picture.

For the price I probably can use iLowest and compare the lowest Price of the last time period to the one shiftet before.

E.G. Lowest price of the last five bars: Low1-5 = iLowest(Symbol(),0,0,MODE_CLOSE,5,1);

Lowest price of the five bars before the last five bars: Low6-10 = iLowest(Symbol(),0,0,MODE_CLOSE,5,6);

If I compare those two values, I will know which one is higher / lower and I can find out if there are troughs during the period of the last 10 bars. But how can I do this for the Bulls Indicator? Do I have to use a loop that compares the values of the last 10 bars to each other? Or is there a special function for it, too?

I would be happy about any ideas or hints that could help me to solve this problem.

Thanks in advance!

 

Ok, I like this example. I've tried to create divergence EA in the past but was Un-successful because my coding skills sucked (and still does). Divergence like trend lines pop-up everywhere and I didn't know how best to define it. I hope you don't mind if I modify your example above as case study and post EA here?

As to your question, I know you can use a loop and compare the values of the bulls indicator.

Something tells me you may also be able to use iLowest, within a loop perhaps.

Any other methods, I'm not aware, and we'll just have to wait for the Guru's.

 

"I hope you don't mind if I modify your example above as case study and post EA here?" - no, not at all. Feel free to do so.

"Something tells me you may also be able to use iLowest, within a loop perhaps." - Does someone know if I can pass the Bulls Indicator Values to an array an let the ILowest function check the array? Like that: iLowest(ARRAY,0,0,MODE_CLOSE,5,6); ?

"Any other methods, I'm not aware, and we'll just have to wait for the Guru's." - good idea ;) Hope they will not let us wait to long

 

Ok, I'll go to work on this and see what I can come up with.

Something tells me you may also be able to use iLowest, within a loop perhaps. ---> Nope, I couldn't get the inputs to work.

I'm moving forward with something like this. Bulls_Low=Lowest value within the period. Bulls_Bar is one of the peaks where price and indicator compare.

  for(i=ibars;i>0;i--){
    Bulls_Cur=iBullsPower("EURUSD",PERIOD_M5,ibars,PRICE_CLOSE,i);
    if(Bulls_Cur<Bulls_Low){Bulls_Low=Bulls_Cur;Bulls_Bar=i;}
  }
 

There is a l little discussion of this and posible code to follow here https://www.mql5.com/en/code

 

There is a function to get the Array´s minnimum:

int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)

But how can I pass the iBullPower values to an array?

Somehow like this:

for (int i=0;i=5;i++)
{
double BullsPower[i]=iBullsPower(NULL, 0, 13,PRICE_CLOSE,[i]);

}

It´s not working yet. There are errors...

Reason: