how to show candle time correctly when change corner attribute

 

hi every one

I used below code for showing candle time, it shows candle time in 3 time frame like        M1    00:12

                                                                                                                                                  M5    03:12

                                                                                                                                                  M15   10:12

I set corner for it, when I select 0 or 1 it worked correctly and changed candle time at top of page in left or right corner

but when I select 2,3 it changed position to the  button of page left or right corner but it didn't show candle's time like above format it shows like        M15    10:12

                                                                                                                                                                                                                                                           M5      03:12

                                                                                                                                                                                                                                                            M1      00:12

it changed M1 and M15 place I want when it changes position to button of page doesn't change M1 and M15 place ..


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 + 17);
   
   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 + 34);
   
  
   
   string time1= "M1  "+ TimeTillNextBarM1(PERIOD_M1);
   string time5= "M5  "+ TimeTillNextBarM5(PERIOD_M5);
   string time15="M15 "+  TimeTillNextBarM15(PERIOD_M15);
  
   ObjectSetText("BarTimer1"  , time1, FontSize, Font, FontColor1);
   ObjectSetText("BarTimer5"  , time5, FontSize, Font, FontColor5);
   ObjectSetText("BarTimer15"  , time15, FontSize, Font, FontColor15);
  
      
  }

  
//+--------------------s----------------------------------------------+
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("%2d d %02d h %02d m %02d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec);
   if(mdt.sec<10) 
  {
   FontColor1=Red;
   } 
   return StringFormat("%02d:%02d ",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("%02d d %02d h %02d m %02d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec);  
   if(mdt.min<1) 
   {
   if(mdt.sec<10)   
   FontColor5=Red;
   } 
    return StringFormat("%02d:%02d ",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("%02d d %02d h %2d m %02d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec); 
   if(mdt.min<1) 
   {
   if(mdt.sec<10)   
   FontColor15=Red;
   }
   return StringFormat("%02d:%02d ",mdt.min,mdt.sec); 
  }

    

                                          

can any one help me?

Best Regards

Neda

                                                                                                                                          

                                                                                                                                              

 

Not tested but this should fix it.

   int y=0;

   ObjectDelete("BarTimer1");
   ObjectCreate("BarTimer1", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("BarTimer1", OBJPROP_BACK, back);
   ObjectSet   ("BarTimer1", OBJPROP_CORNER, corner);
   ObjectSet   ("BarTimer1", OBJPROP_XDISTANCE, xdis);
   if(corner==CORNER_LEFT_UPPER || corner==CORNER_LEFT_UPPER)
      y=ydis;
   else
      y=ydis + 34;
   ObjectSet   ("BarTimer1", OBJPROP_YDISTANCE, y);

   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 + 17);

   ObjectDelete("BarTimer15");
   ObjectCreate("BarTimer15", OBJ_LABEL, 0, 0, 0);
   ObjectSet   ("BarTimer15", OBJPROP_BACK, back);
   ObjectSet   ("BarTimer15", OBJPROP_CORNER, corner);
   ObjectSet   ("BarTimer15", OBJPROP_XDISTANCE, xdis);
   if(corner==CORNER_LEFT_UPPER || corner==CORNER_LEFT_UPPER)
      y=ydis+34;
   else
      y=ydis;
   ObjectSet   ("BarTimer15", OBJPROP_YDISTANCE, y);

Incidentally, why are you deleting and re-creating the objects?

You should create them once in OnInit() and then just set the text in OnTimer().

 
Keith Watford:

Not tested but this should fix it.

Incidentally, why are you deleting and re-creating the objects?

You should create them once in OnInit() and then just set the text in OnTimer().

it worked for 3 corner correctly but it didn't work for right upper...

 
Neda shahbazi:

it worked for 3 corner correctly but it didn't work for right upper...

My mistake the 2 instances of 

   if(corner==CORNER_LEFT_UPPER || corner==CORNER_LEFT_UPPER)

obviously should be 

   if(corner==CORNER_LEFT_UPPER || corner==CORNER_RIGHT_UPPER)
 
Keith Watford:

My mistake the 2 instances of 

obviously should be 

Thanks a lot it worked correctly

I should read codes more carefully

Reason: