Problem with a simple condition and close prices .

 
I am new here so Hi Everybody !!!


I thought MQL4 would be easy form my but not . First indicator and an incomprehensible issue for my.
I want to create an indicator which will show "1" if today close price is greate then yesterday close and and vice versa "-1" if today close price is smaller then yesterday close.

My code:
int start()
 
  {
 
     double temp;
   
 
   int    counted_bars=IndicatorCounted();
//----
   if (counted_bars < 0 ) return(-1);
   
//----
   if (counted_bars > 0 ) counted_bars-- ;
  
     
 
 
  int pos = Bars - counted_bars ; 
  
 
  
  while ( pos >=0 ){
     
    
   
      if (Close[pos ] >  Close[pos - 1 ] ) { temp = 1;} else{ temp = 0 ;}
    ExtMapBuffer1[pos] = temp; 
   
     
 
     pos-- ; 
  }
  
  
 
 
   return(0);
  }
... and output :




In a yellow box I marked data and result which do not fit to my theory.

Could you help my with this problem and explain me why does it happen ?
 
You consider this (there are mistype in your code)
   
      if (Close[pos ] >  Close[pos + 1 ] ) { temp = 1;} else{ temp = 0 ;}
    ExtMapBuffer1[pos] = temp;
 
Thanks for the answer Roah .

This works but I still dont know how and why . So could you explain my in details becouse my understending is :

"if pos = today then pos + 1 = tomorrow and pos - 1 = yesterday " . According to this my code after yours correction means :

if (Close[today ] >  Close[tomorrow] ) { temp = 1;} else{ temp = 0 ;}
Am I right ?


Thanks forward.
 

"if pos = today then pos + 1 = tomorrow and pos - 1 = yesterday "


Correct your thinking please

pos + 1 = day before

pos - 1 = day after (when pos != 0)

if pos == 0 tomorrow has to be calculated by other means


Chart bars:

| | | | | |

5 4 3 2 1 0

 
CHEERS phy !!!
Reason: