how to show time like 00:00

 

hi every one

I use below codes to show candle time in 3 time frame

It shows time like                             M    0:25

                                                         M5   1:25

                                                        M15  12:25


but I want it shows time like         M      00:25

                                                        M5    01:25

                                                       M15   12:25


I mean it shows minute like--> 01:12

  can any one help me?

char s,m,h,d;
extern color FontColor1=White;
extern color FontColor5=White;
extern color FontColor15=White;
extern int       corner=1;
extern int       xdis=20;
extern int       ydis=25;
extern string    Font="Courier New";
extern int       FontSize=11;
extern bool      back=0;


void OnTimer()
  {
   ObjectDelete("BarTimer1");
   ObjectCreate("BarTimer1"  , OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("BarTimer1"  , OBJPROP_BACK, back);
   ObjectSet   ("BarTimer1"  , OBJPROP_CORNER, corner);
   ObjectSet   ("BarTimer1"  , OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("BarTimer1"  , OBJPROP_YDISTANCE, ydis);
   
   ObjectDelete("BarTimer5");
   ObjectCreate("BarTimer5", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("BarTimer5", OBJPROP_BACK, back);
   ObjectSet   ("BarTimer5", OBJPROP_CORNER, corner);
   ObjectSet   ("BarTimer5", OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("BarTimer5", OBJPROP_YDISTANCE, ydis + 20);
   
   ObjectDelete("BarTimer15");
   ObjectCreate("BarTimer15" , OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("BarTimer15" , OBJPROP_BACK, back);
   ObjectSet   ("BarTimer15" , OBJPROP_CORNER, corner);
   ObjectSet   ("BarTimer15" , OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("BarTimer15" , OBJPROP_YDISTANCE, ydis + 40);
   
  
   
   string time1= "M1   "+ TimeTillNextBarM1(PERIOD_M1);
   string time5= "M5   "+ TimeTillNextBarM5(PERIOD_M5);
   string time15="M15  "+  TimeTillNextBarM15(PERIOD_M15);
   ObjectSetText("BarTimer"  ,"M", FontSize, Font, FontColor1);
   ObjectSetText("BarTimer1"  , time1, FontSize, Font, FontColor1);
   ObjectSetText("BarTimer5"  , time5, FontSize, Font, FontColor5);
   ObjectSetText("BarTimer15"  , time15, FontSize, Font, FontColor15);
  }

string TimeTillNextBarM1(ENUM_TIMEFRAMES tf=PERIOD_CURRENT)
  {
   FontColor1=White;
   datetime now=TimeCurrent();
   datetime bartime=iTime(NULL,tf,0);  
   datetime remainingTime=bartime+PeriodSeconds(tf)-now;
   MqlDateTime mdt;   
   TimeToStruct(remainingTime,mdt);  
   if(mdt.day_of_year>0)
   return StringFormat("%d d %d h %d m %d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec);
   if(mdt.sec<10) 
  {
   FontColor1=Red;
   } 
   return StringFormat("%d : %d ",mdt.min,mdt.sec);
  }
  
  
  string TimeTillNextBarM5(ENUM_TIMEFRAMES tf=PERIOD_CURRENT)
  {
  FontColor5=White;
   datetime now=TimeCurrent();
   datetime bartime=iTime(NULL,tf,0);  
   datetime remainingTime=bartime+PeriodSeconds(tf)-now;
   MqlDateTime mdt;  
   TimeToStruct(remainingTime,mdt);  
   if(mdt.day_of_year>0)
   return StringFormat("%d d %d h %d m %d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec);  
   if(mdt.min<1) 
   {
   if(mdt.sec<10)   
   FontColor5=Red;
   } 
    return StringFormat("%d : %d ",mdt.min,mdt.sec);
  }
  
  
  string TimeTillNextBarM15(ENUM_TIMEFRAMES tf=PERIOD_CURRENT)
  {
  FontColor15=White;
   datetime now=TimeCurrent();
   datetime bartime=iTime(NULL,tf,0);  
   datetime remainingTime=bartime+PeriodSeconds(tf)-now;
   MqlDateTime mdt;   
   TimeToStruct(remainingTime,mdt);  
   if(mdt.day_of_year>0)
   return StringFormat("%d d %d h %d m %d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec); 
   if(mdt.min<1) 
   {
   if(mdt.sec<10)   
   FontColor15=Red;
   }
   return StringFormat("%d : %d ",mdt.min,mdt.sec); 
  }



Best Regards

Neda

 

Like this

StringFormat("%02d d %02d h %02d m %02d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec); 
 
Neda shahbazi:

hi every one

I use below codes to show candle time in 3 time frame

It shows time like                             M    0:25

                                                         M5   1:25

                                                        M15  12:25


but I want it shows time like         M      00:25

                                                        M5    01:25

                                                       M15   12:25


I mean it shows minute like--> 01:12

  can any one help me?



Best Regards

Neda

Read more about [width] in PrintFormat documentation.
 
Fernando Morales:

Like this

thanks a lot worked correctly