function returns 0, pls help

 
Hi all,

I am trying to make an indicator that draws the value of the opening price of the current bar divided by the opening price of the bar with a pre set time, in this example 00:00. 
When calculating the value of the current bar i, it should loop backwards starting from bar i to find the bar with time 00:00 in the function basis.  This function should return the bar shift of the bar with time 00:00.
I tried to do this with the code below, but the function basis only returns 0. 

Could someone please have a look and point out what I am doing wrong?


   
 


extern string ex_time= "00:00";

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
//---- calculate values
   for(int i=0; i<limit; i++) {
   
      int basis = basis(i);
        
      USD[i]=(1/(iOpen("EURUSD",0,i)))/(1/(iOpen("EURUSD" ,0,basis))); 
            
   } 
   return(0);
  }
  
  
int basis(int a)
{
int i;
for (i=a; i==i-1440;i--)
    {
    if (TimeToStr(Time[i], TIME_MINUTES) == ex_time) return (i);        

    }
}  
 
for (i=a; i==i-1440;i--)
This loop will never be executed, not even once, because the condition
i==i-1440
will evaluate to false already before the first iteration. It will always be false. You should read the manual about how the for() loop works, what its three arguments mean and how it is used.
 
Your loop code looks strange:

for (i=a; i==i-1440;i--)




//try this one :

int basis(int a)
{
int i;
for (i=a; i<limit;i++)
    {
    if (TimeToStr(Time[i], TIME_MINUTES) == ex_time)    break;      

    }

return (i);       


}  

 
thanks 7bit and sergery. I've adjusted it and it works fine now.
Reason: