MTF-Indicator from the past to currenttime

 

Hi,

I've always programmed my mtf-indicator with this loop:

   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++;
   ....
   }

but know I have an indicator which shows a widget for the valid time f.e. the whole day. Therefore I only want the signal on the start of the day.

When I programm this with the loop above, I only get the signal on the end of the day, because it calculates from now to the past.

But I also doesn't work when I turn around the for-loop:

for(i=(limit-1),y=(limit-1);i>0;i--)

Why?

 
Why do you have the y variable in your for loop statement ?
 

Sorry, the code is in the following context:

ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),D1_Period); 
for(i=(limit-1),y=(limit-1);i>0;i--) 
 {
  if (Time[i]<TimeArray[y]) y++;
    if(iClose(NULL,D1_Period,y+2)>....)
      SellBuffer[i+(D1_Period/Period())] = ..
 }
 
RaptorUK:
Why do you have the y variable in your for loop statement ?
OK, one of the subtleties of mql4 I hadn't appreciated.
 
Do you mean, I can't do that??
 
sunshineh:
Do you mean, I can't do that??
No, I mean you can do that . . . but I thought it was wrong.
 

sunshineh:

I've always programmed my mtf-indicator with this loop:

   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),D1_Period); 
   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++;
   ....
   }
Unnecessary. Just keep tract of the correct bar for each timeframe
   limit=Bars-counted_bars;
   for(i=0;i<limit;i++)
   {
       int iD1 = iBarShift(NULL, PERIOD_D1, Time[i]);
       double clD1 = iClose(NULL, PERIOD_D1, iD1);
   ....
   }
Reason: