counting loop problem

 

Hi all,

I'm trying to loop through a sentence in order to count bars.

I'm using the following code that it's not functioning as it should.

please, any thoughts?


 int CountBars()
  {
   int bars;
      
   for(int i=1; i<Bars-1; i++)
     {
      
      
      if(iCustom(NULL,0,"Heiken Ashi",3,i)>iCustom(NULL,0,"Heiken Ashi",2,i))
        
        {
         bars++;
         
        } 
         
       else
       
        {
       
       bars=0;
       
        }
       
     }
   return(bars);

thank you in advance.

KR

 

What do you mean by "not functioning as it should" ?

What should it count if it is set to 0 once and a while?

Maybe this helps you, even though it's mainly for MT5:

    Before learning to code in MQL5 learn to search as there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you!
    => Search in the articles: https://www.mql5.com/en/articles
    => Search in the codebase: https://www.mql5.com/en/code
    => Search in general: https://www.mql5.com/en/search or via Google with: "site:mql5.com .." (forgives typos and variants)
    If you place the cursor on an MQL function and press F1, you will see the reference directly, many with examples to copy and paste - the fastest form to code!
    https://www.mql5.com/en/articles/496
    https://www.mql5.com/en/articles/100
    https://www.mql5.com/en/articles/599
    https://www.mql5.com/en/search#!keyword=cookbook
    and for debugging: https://www.metatrader5.com/en/metaeditor/help/development/debug
    learn to understand the error messages in the logs!!

Beside that you start to learn a language that will die sooner or later: End of MT4: https://www.mql5.com/en/forum/454319

MQL5 Articles
MQL5 Articles
  • www.mql5.com
MQL5 Programming Articles
 

Thank you, Carl for the tips.

indeed, I've tried to search for a same issue as mine but no luck this time.

As you stated, the idea it's to return the count zero when the sentence fails. tried to put also at the end bars-- 

is there a chance to put me in the right direction?