Download MetaTrader 5
To add comments, please log in or register
Any questions regarding MQL5 Cloud Network? FAQ will help you!
samatii
9
samatii 2012.07.13 16:01 
Does anyone have already built a code for having the time countdown on a candletick? Thank you in advance for haring it if you have one.
onewithzachy
2274
onewithzachy 2012.07.13 17:03  
samatii:
Does anyone have already built a code for having the time countdown on a candletick? Thank you in advance for haring it if you have one.

Hi samatii

:D 

  datetime bar_0 [1], next_time, time_left;
  if (CopyTime (Symbol(), Period(), 0, 1, bar_0)== 1)
     {
     next_time = bar_0 [0] + PeriodSeconds(PERIOD_CURRENT);
     time_left = next_time - TimeCurrent();
     Alert(TimeToString (time_left, TIME_DATE|TIME_SECONDS));
     }


samatii
9
samatii 2012.07.24 16:01  
onewithzachy:

Hi samatii

:D 


Thanks a lot. I am little bit new to MT. Could you please explain me how to run it, i have no knowledge of the dev. on this platform.
onewithzachy
2274
onewithzachy 2012.07.25 02:42  
samatii:
Thanks a lot. I am little bit new to MT. Could you please explain me how to run it, i have no knowledge of the dev. on this platform.

Hi samatii,

1. Open MetaEditor 5 > Click File menu > Click New > Select Custom Indicator > click next > Name your Indicator > click next > Select OnCalculate (... prices) > Click Finish.

2. Copy paste this in to inside int OnCalculate ()

  datetime bar_0 [1], next_time, time_left;
  MqlDateTime data_time;
  string text, name;
  bool created;
  
  if (CopyTime (Symbol(), Period(), 0, 1, bar_0)== 1)
     {
     next_time = bar_0 [0] + PeriodSeconds(PERIOD_CURRENT);
     time_left = next_time - TimeCurrent();
     TimeToStruct (time_left, data_time);
     
     // extracting time left
     if (Period() == PERIOD_MN1)   text = data_time.day+" ";
        else
        if (Period() > PERIOD_D1 ) text = (data_time.day - 1)+" ";
     
     // converting to military time writing style
     if (StringLen (data_time.hour) == 1) text = text+"0"+data_time.hour+":";  else text = text+data_time.hour+":";
     if (StringLen (data_time.min) == 1)  text = text+"0"+data_time.min+":";   else text = text+data_time.min+":";
     if (StringLen (data_time.sec) == 1)  text = text+"0"+data_time.sec;       else text = text+data_time.sec;

     name = MQL5InfoString(MQL5_PROGRAM_NAME);
     created = ObjectCreate(0,name, OBJ_LABEL, 0, 0, 0);
     if (created == true)
       {
       ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
       ObjectSetString( 0, name, OBJPROP_TEXT, text);
       ObjectSetInteger(0, name, OBJPROP_CORNER, 3);     
       ObjectSetInteger(0, name, OBJPROP_XDISTANCE, 10);
       ObjectSetInteger(0, name, OBJPROP_YDISTANCE, 10);
       ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
       ObjectSetInteger(0, name, OBJPROP_SELECTED, false); 
       ObjectSetString (0, name, OBJPROP_FONT, "System");
       ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 30);
       ObjectSetInteger(0, name, OBJPROP_COLOR, clrRed);
       }
     }

3. Add this below void OnTradeTransaction()

void OnDeinit(const int why)
  {
  ObjectDelete(0,MQL5InfoString(MQL5_PROGRAM_NAME));
  }
//+------------------------------------------------------------------+

4. Compile it. If you paste those into correct places, you will have a lot of warnings but no error. Don't worry about those warnings. If you paste them wrong, you will have an errors.

:D 

/
To add comments, please log in or register