MQL5 - Return the day of the week - page 3

 
William Roeder #:

So I ask again, why do you have to rename the file? Just create it with the proper name to start with.

I am not trying to rename an extg. file. I've already created it with a proper name. but part of the name should be the date (which should be dynamically generated daily) - and for this reason, i'm hoping to generate this within the OnStart so that different functions doing different things can share the same filename. like a global variable. 

But as i mentioned earlier, i discovered there's no way for OnStart to accept parameters nor can it return a result which i can assign to a variable....in my limited knowledge, i cannot find a way around this and so am stuck...

will very much appreciate just a point to the right direction.

 
Inside your function On start you assign the filename string to a global variable.

This gives you access to the filename. But to me it would be more of use to store the handle to the file which was opened in OnStart.

If you want to rename the file automatically, you will need to watch the date in your code and if it changes to the next day, you will have to close the current file, generate a new filename and open/create this new file. Then update the file handle with this newly opened file and all your functions would be writing to your new file.


 
Dominik Egert #:
Inside your function On start you assign the filename string to a global variable.

This gives you access to the filename. But to me it would be more of use to store the handle to the file which was opened in OnStart.

If you want to rename the file automatically, you will need to watch the date in your code and if it changes to the next day, you will have to close the current file, generate a new filename and open/create this new file. Then update the file handle with this newly opened file and all your functions would be writing to your new file.


thanks dominik but i dont quite understand how assigning a filename string to a global variable inside the OnStart will allow my other functions(outside OnStart) to access the filename since as i mentioned, in my limited knowledge, it seems OnStart does cannot output or return a variable which i can then assign to another outside itself nor can it accept parameters by reference. ...I am not trying to rename a file but trying to generate a filename dynamically daily with date as part of this filename. ....hope its ok to  seek further clarification since it's fuzzy to me. 

 
JimSingadventure #: i dont quite understand how assigning a filename string to a global variable inside the OnStart will allow my other functions(outside OnStart) to access the filename
If it is globally declared, every function as access. Learn to code.
 
hello what this is problem? idont really why this is false.
Files:
Untitled.png  193 kb
 
MANIGHORBANPOUR #: hello what this is problem? idont really why this is false.
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  3. “Why this is false?” What is “this”.

    Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  4. You have a loop. If the call was in error, you print and break out of the loop. Otherwise, you loop again. Shouldn't that be the other way around?
 
  MqlDateTime servertime;

   TimeToStruct(TimeCurrent(),servertime);


servertime.day_of_week != 0 // ( not sunday please)



/* comments about mqldate time. use it in mql5 !!! comments all below:

MqlDateTime

The date type structure contains eight fields of the int type:

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)
  };

*/

//
 

this is the basic function : 

int DayofWeek()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.day_of_week);
  }
returned value (1 = Friday) 
 
  1. Wissam Hussein #: returned value (1 = Friday) 
    Wrong. FRIDAY equals 5
    int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday)
  2. #define DoWi(now) ENUM_DAY_OF_WEEK((now-D'1970.01.04')/86400 %7)
              MetaTrader 5 Platform update build 3660: Improvements and fixes - General - MQL5 programming forum - Page 10 #93 (2023)
              One simple script for MT5 B and four questions & problems - General - MQL5 #81 (2023)
Reason: