MultiTimeFrameIndicatator Problem with time-compare

 
Hello,

currently i am working on a multiTimeframe indicator for m5 timeframe.
for this i need the position for the candles in upper timeframes.
my idea was to draw the indicator from now to past. so that i can compare times in a nice way.
basically:
   for(int pos=0;pos<=limit;pos++){
      if(timeOfM5!=iTime(Symbol(),PERIOD_M5,pos)){
         timeOfM5=iTime(Symbol(),PERIOD_M5,pos);
         timeOfM15=iTime(Symbol(),PERIOD_M15,posOfM15);        
         timeOfH1=iTime(Symbol(),PERIOD_H1,posOfH1);      
         if((TimeMinute(timeOfM5))<TimeMinute(timeOfM15)){
            posOfM15++;
            timeOfM15=iTime(Symbol(),PERIOD_M15,posOfM15);
      
      
            if(TimeMinute(timeOfM5)<TimeMinute(timeOfH1)){
               posOfH1++;
               timeOfH1=iTime(Symbol(),PERIOD_H1,posOfH1);
            }            
         }     
      }
   }
after reading in re-reading i cant figure out why the code is not working.

maybe somebody has allready made such indicators and could give me a hint.
Reason: