Question about Daily Highs and Lows

To add comments, please log in or register
Yellowbeard1881
23
Yellowbeard1881  

Is there a way to get the day, ( Monday, Tuesday, Wednesday, Thursday, Friday ) of a previous daily candle?  Able to get date and time.  Trying to figure out the day.

Thanks!

Marco vd Heijden
Moderator
8169
Marco vd Heijden  

Yes;

Try TimeDayOfWeek(); and iTime(...

Yellowbeard1881
23
Yellowbeard1881  

I use iTime to find date and time.  But as far as DayOfWeek() goes, it only seems to work for the current candle.


Thanks!

Marco vd Heijden
Moderator
8169
Marco vd Heijden  
int Day=TimeDayOfWeek(iTime(_Symbol,_Period,bar));

Bar number specifies the candle so bar 0 is current candle, bar 1 is last Day (if PERIOD_D1) and etc.

TimeDayOfWeek() not DayOfWeek() that is another function...

Alternatively you could use:

struct MqlDateTime 
  { 
   int year;           // Year 
   int mon;            // Month 
   int day;            // Day 
   int hour;           // Hour 
   int min;            // Minutes 
   int sec;            // Seconds 
   int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) 
   int day_of_year;    // Day number of the year (January 1st is assigned the number value of zero) 
  };
See Here and Here
TimeDayOfWeek - Date and Time - MQL4 Reference
TimeDayOfWeek - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeDayOfWeek - Date and Time - MQL4 Reference
Yellowbeard1881
23
Yellowbeard1881  

TimeDayOfWeek(), works.  


 int DT = TimeDayOfWeek(dT);
     
   switch(DT)  //  
     {
      case 1: f="MONDAY";    break;
      case 2: f="TUESDAY";   break;
      case 3: f="WEDNESDAY"; break;
      case 4: f="THURSDAY";  break;
      case 5: f="FRIDAY";    break;
      case 6: f="SATURDAY";  break;
      case 0: f="SUNDAY";    break;
     }
Yellowbeard1881
23
Yellowbeard1881  
Thank You!
Marco vd Heijden
Moderator
8169
Marco vd Heijden  

The other function is actually MQL5 

So you can spot the small differences between.

//+------------------------------------------------------------------+ 
//| Returns the name of the day of the week                          | 
//+------------------------------------------------------------------+ 
string DayOfWeek(const datetime time) 
  { 
   MqlDateTime dt; 
   string day=""; 
   TimeToStruct(time,dt); 
   switch(dt.day_of_week) 
     { 
      case 0: day=EnumToString(SUNDAY); 
      break; 
      case 1: day=EnumToString(MONDAY); 
      break; 
      case 2: day=EnumToString(TUESDAY); 
      break; 
      case 3: day=EnumToString(WEDNESDAY); 
      break; 
      case 4: day=EnumToString(THURSDAY); 
      break; 
      case 5: day=EnumToString(FRIDAY); 
      break;    
      default:day=EnumToString(SATURDAY); 
      break; 
     } 
//--- 
   return day; 
  } 
If you add this i think it should work on MQL4 too.
To add comments, please log in or register