how do I set a function within the program?

 

i tried to do the below

 

int updown (int timeframe, int shift)


{ 

 if (  (iClose (NULL,timeframe,shift) - iOpen(NULL, timeframe,shift)) > 0)
   updown = 1;
   

 if ( (iClose (NULL,timeframe,shift) - iOpen(NULL, timeframe,shift)) < 0)
   updown = -1;
}

basically if it's a function to give a 1 when the bar is green and a -1 when the bar is red

 

But when I reference it in the main program, ,as shown below, it always show updown as 0. What's the issue here? 

 if ((updown(PERIOD_M5, 1)==1)&& (updown (PERIOD_M5, 2)==1) && (updown (PERIOD_M5, 3) ==1))
         {Trend = 1;
         
         }

 thanks in advance!

 
yuan83:

i tried to do the below

 

basically if it's a function to give a 1 when the bar is green and a -1 when the bar is red

 

But when I reference it in the main program, ,as shown below, it always show updown as 0. What's the issue here? 

 thanks in advance!

You need to return the value from your function to the code that called it . . .
Reason: