Function define to return a value

 

hi;

i want to define a function such that : count no. of bar those above zero line after last cross zero line.


i wrote this:

.
.
int TOTAL_BAR;
.
int count_bar;
.
.
//+------------------------------------------------------------------+
void OnInit()
{
.
.
}
//+------------------------------------------------------------------+
int OnCalculate(...)
{
.
TOTAL_BAR=rates_total;
.
IsIndicator_domain_above(count_bar);
.
.
Comment(""
           ,"\ncount_bar=",count_bar
       )
.
.
.
//--- done
   return(rates_total);
}
//+------------------------------------------------------------------+
int IsIndicator_domain_above(int count_bar)
  {
   for(int j=0; j<TOTAL_BAR; j++)
      { 
       if(Ext_AO_Buffer[j]>=0.0&&Ext_AO_Buffer[j+1]<=0.0)
       count_bar=j+1; break;
      }
   return(count_bar);
  }

can you please tell me what is the problem?

thank you.

 
TIMisthebest:

hi;

i want to define a function such that : count no. of bar those above zero line after last cross zero line.


i wrote this:

can you please tell me what is the problem?

thank you.

Get rid of the globally declared count_bar variable . . . you don't need it.

Do this . . .

int IsIndicator_domain_above()  //  <--- edited
  {
   int count_bar;   //  <--- added

   for(int j=0; j<TOTAL_BAR; j++)
      { 
       if(Ext_AO_Buffer[j]>=0.0&&Ext_AO_Buffer[j+1]<=0.0)
          {
          count_bar = j + 1;   //  <--- edited
          break;              //  <--- edited
          }
      }
   return(count_bar);
  }

 then call the function like this . . .

 

;
.
.
Comment(""
           , "\ncount_bar=", IsIndicator_domain_above()
       )
 
RaptorUK:

Get rid of the globally declared count_bar variable . . . you don't need it.

Do this . . .

 then call the function like this . . .

thank you;

i see my mistake;

thank again.

 
RaptorUK:

Get rid of the globally declared count_bar variable . . . you don't need it.

Do this . . .

 then call the function like this . . .

 

can you please check about warning ?


 
TIMisthebest:

can you please check about warning ?

with :

.
int count_bar;
.
.
//+------------------------------------------------------------------+
void OnInit()
{
.
.
}
//+------------------------------------------------------------------+

there is no warning & problem solved.

thank you RaptorUK.

 
TIMisthebest:

with :

there is no warning & problem solved.

thank you RaptorUK.

Nope,  that is wrong.

I think this is the correct way to get rid of the warning . . .

int IsIndicator_domain_above() 
  {
   int count_bar = 0;   //  <--- edited

   for(int j=0; j<TOTAL_BAR; j++)
      { 
       if(Ext_AO_Buffer[j]>=0.0&&Ext_AO_Buffer[j+1]<=0.0)
          {
          count_bar = j + 1; 
          break;  
          }
      }
   return(count_bar);
  }
 
RaptorUK:

Nope,  that is wrong.

I think this is the correct way to get rid of the warning . . .

yes.

you are right.

thank you.

Reason: