Problem with updating a value

 

I try to do a random choice between two values​​, as shown below. The problem is that sometimes the value is not updated timely and the new value instead of using new uses old and new open order is wrong. Interestingly, then is updated, but it is too late. Where could be a problem? I trade on offline chart with no problem, but may be something is wrong?

//+------------------------------------------------------------------+
//|  function of issuing trade siglnal                               |
//+------------------------------------------------------------------+
int yourFunction(int workPeriod)
   {
   int res=OP_BALANCE;
   
   
 
 if ( iClose(NULL,0,23)>iClose(NULL,0,12) )                     
        {
         int integer=1;   
        }
    else
     {
   
             integer=2; 
        
     }
 
 
 
  
 
  
    
    if ( iClose(NULL,0,integer+1)< iClose(NULL,0,integer))     res=OP_BUY;
    if ( iClose(NULL,0,integer+1)> iClose(NULL,0,integer))     res=OP_SELL;
   

   //----
   return (res);   
   } 
 

??????????

Question does not fit the code shown.

 

if ( iClose(NULL,0,23)>iClose(NULL,0,12) ) then integer =1

Then:

if ( iClose(NULL,0,2)< iClose(NULL,0,1)) res=OP_BUY;

if ( iClose(NULL,0,2)> iClose(NULL,0,1) res=OP_SELL;

OR

if ( iClose(NULL,0,23)<iClose(NULL,0,12) ) then integer =2

Then:

if ( iClose(NULL,0,3)< iClose(NULL,0,2)) res=OP_BUY;

if ( iClose(NULL,0,3)> iClose(NULL,0,2) res=OP_SELL;

 

Where is the random check? What value is not updated?

What does workPeriod do

Why are you setting res=OP_BALANCE

 
//+------------------------------------------------------------------+
//|  function of issuing trade siglnal                               |
//+------------------------------------------------------------------+
int yourFunction()
{
int res ;

if ( iClose(NULL,0,23)>iClose(NULL,0,12) )
  {//True
   if ( iClose(NULL,0,2) < iClose(NULL,0,1) )  
      res=OP_BUY;
   else
      res=OP_SELL; 
  }
  else
  {//False
   if ( iClose(NULL,0,3) < iClose(NULL,0,2) ) 
      res=OP_BUY;
   else
      res=OP_SELL; 
  }
   return (res);   
}