getting value in a function

 
i create a custom function but i dont know how to get the value from it and compare them in if statement
double checkbar()
{
popen = iOpen(Symbol(),0,1);
pclose = iClose(Symbol(),0,1);
phigh = iHigh(Symbol(),0,1);
plow = iLow(Symbol(),0,1);
int bar1;
if (popen > pclose)
bar1 = 1;
if (popen < pclose)
bar1 = 2;
if ((popen + pclose)/2 > popen)
bar1 = 3;
return (bar1);
}
 
ddock:
i create a custom function but i dont know how to get the value from it and compare them in if statement

bar1 = checkbar();

if bar1 == some value    \\ or use the CompareDoubles() function

 {

   do this.....

 

DD

Examples

int iCheckBar;

iCheckBar = checkbar();

if (iCheckBar == 1) 
{
   // Do something

}

if (iCheckBar == 2) 
{
   // Do something else

}

you could also paramaetize the function as

double checkbarshift(int iShift)
{
popen = iOpen(Symbol(),0,iShift);
pclose = iClose(Symbol(),0,iShift);
phigh = iHigh(Symbol(),0,iShift);
plow = iLow(Symbol(),0,iShift);
int barshift;
if (popen > pclose)
barshift = 1;
if (popen < pclose)
barshift = 2;
if ((popen + pclose)/2 > popen)
barshift = 3;
return (barshift);
}

which allows reuse of code in a handy way, such as

int iCheckBar1, icheckBar2;

iCheckBar1 = checkbarshift(1);
iCheckBar2 = checkbarshift(2);

if ((iCheckBar1 == 1) && (iCheckBar2 == 1)) 
  {   // Do something

  }

if ((iCheckBar1 == 2) && (iCheckBar2 == 2)) 
  {   // Do something else

}

Good Luck

-BB-

 
oh, thank you for the reply, things getting clear in my ea now, also that bar shift example is awsome, never though about that
Reason: