Dont know what is wrong with my indicator.

 

Hi All, I am new to MQL5 and i somehow wrote a Fractal indicator which identifies 7 pattern discussed in the below link

 

 But due to some reason, the indicator is not working properly. sometimes it is working, sometime it is not working.

Can someone test this code and correct it?

[Code attached]  

Files:
 

please test this.

 

Files:
 
Thank You Poo. Its working fine now.
Reason: