Friday Highday!

 

Hello friends,


I made a discovery which i would like to share. So i always wondered on which day of the week the high or low occurs the most often.

ICT always taught its either on Tuesday or Wednesday but i have the data and code to prove him wrong!

I wrote some simple code which runs a for loop which scans the week and adds the highest or lowest day to the counter for that day :


void OnStart()
  {
   int Monday;
   int Tuesday;
   int Wednesday;
   int Thursday;
   int Friday;

   for(int i = 0; i < 520; i = i + 5)
     {
      int Select = iLowest(NULL,1440,MODE_CLOSE,5,i);
      datetime Converted = iTime(NULL,1440,Select);
      int DayNr = TimeDayOfWeek(Converted);

      switch(DayNr)
        {
         case 1:
           {
            Monday = Monday + 1;
           }
         case 2:
           {
            Tuesday = Tuesday + 1;
           }
         case 3:
           {
            Wednesday = Wednesday + 1;
           }
         case 4:
           {
            Thursday = Thursday + 1;
           }
         case 5:
           {
            Friday = Friday + 1;
           }
        }
     }

   Alert("Monday : " + Monday);
   Alert("Tuesday : " + Tuesday);
   Alert("Wednesday : " + Wednesday);
   Alert("Thursday :" + Thursday);
   Alert("Friday : " + Friday);

  }

Running this script on all pairs i came to the conclusion that Friday is on all pairs either the lowest or highest day of the week (statistically speaking ofcourse).

You can check yourself!


Still i doesn't add up to the maximum amount of days, maybe someone else can comment on why that might be?

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Magus I:

Your switch works differently than you intended :)

You forgot about the break operator.

Documentation (сlick on me):

The case keyword with a constant are just labels, and if operators are executed for some case variant, the program will further execute the operators of all subsequent variants until the break operator occurs. It allows to bind a sequence of operators with several variants.

switch(x)
  {
   case 'A':
      Print("CASE A");
      break;
   case 'B':
   case 'C':
      Print("CASE B or C");
      break;
   default:
      Print("NOT A, B or C");
      break;
  }
 
Vladislav Boyko #:

Your switch works differently than you intended :)

You forgot about the break operator.

You are right! Thanks, now it all adds up!
 
Magus I:
int Select = iLowest(NULL,1440,MODE_CLOSE,5,i);
datetime Converted = iTime(NULL,1440,Select);

These functions may return an incorrect value if you do not have the D1 chart window open for that symbol.

Either attach this only to the D1 chart (of the same symbol), or check the correct execution of these functions.

 
Vladislav Boyko #:
attach this only to the D1 chart (of the same symbol)

In this case you can explicitly use the data from the current chart

int Select = iLowest(NULL,PERIOD_CURRENT,MODE_CLOSE,5,i);
datetime Converted = Time[Select];
 
Have you thought how your script will behave if a week contains a number of days other than 5? A hole in quotes, for example. It looks like a hole in the quotes may distort the result
 
Vladislav Boyko #:
Have you thought how your script will behave if a week contains a number of days other than 5? A hole in quotes, for example. It looks like a hole in the quotes may distort the result

Yes i did but i assumed it would be a minor difference in the results.

I think the solution to this would be to continue the for loop until the next Monday so it always starts scanning on that day until Friday.

So it would look something like this:

void OnStart()
  {
   int Monday;
   int Tuesday;
   int Wednesday;
   int Thursday;
   int Friday;

   int CurrentDay;

   for(int i = 0; i < 520 ; i++)
     {
      CurrentDay = TimeDayOfWeek(iTime(NULL,1440,i));

      if(CurrentDay == 1)
        {

         int Select = iLowest(NULL,1440,MODE_LOW,5,i);
         datetime Converted = iTime(NULL,1440,Select);
         int DayNr = TimeDayOfWeek(Converted);

         switch(DayNr)
           {
            case 1:
              {
               Monday = Monday + 1;
               break;
              }
            case 2:
              {
               Tuesday = Tuesday + 1;
               break;
              }
            case 3:
              {
               Wednesday = Wednesday + 1;
               break;
              }
            case 4:
              {
               Thursday = Thursday + 1;
               break;
              }
            case 5:
              {
               Friday = Friday + 1;
               break;
              }
           }
        }
     }

   Alert("Monday : " + Monday);
   Alert("Tuesday : " + Tuesday);
   Alert("Wednesday : " + Wednesday);
   Alert("Thursday :" + Thursday);
   Alert("Friday : " + Friday);

  }


Now the code works like it should i can only say ICT was right (about Tuesday, not Wednesday though), i just made quick assumptions without analyzing the code's functionality on possible flaws.


Thanks for your thoughtful feedback!

 
Magus I #:

Yes i did but i assumed it would be a minor difference in the results.

I think the solution to this would be to continue the for loop until the next Monday so it always starts scanning on that day until Friday.

So it would look something like this:


Now the code works like it should i can only say ICT was right (about Tuesday, not Wednesday though), i just made quick assumptions without analyzing the code's functionality on possible flaws.


Thanks for your thoughtful feedback!

Also i am not sure does the scan function go from left to right or right to left, which makes a difference...

Otherwise you scan from Friday back to Monday.

 
Magus I #:
Also i am not sure does the scan function go from left to right or right to left, which makes a difference...

If you are talking about a cycle, then it is not difficult to check:

void OnStart()
  {
   for(int i = 0; i < 5 ; i++)
      Alert(StringFormat("i = %i, bar %s", i, TimeToString(Time[i])));
  }

But I'm not sure if you're talking about a cycle

 
Magus I #:
Also i am not sure does the scan function go from left to right or right to left, which makes a difference...

If you are talking about iLowest...

iLowest is not some super complicated algorithm. Personally, I'd rather write my own implementation than study the documentation and handle errors of a built-in simple function. That way, I'll know how it works and what to expect from it.

Of course, you can study the documentation and perform a couple of tests to better understand iLowest. But writing your own such function does not take much time and as a gift you get an absolute understanding of how the function works.

I'm not talking about implementing all the functionality of iLowest. I'm talking about a function that will do exactly what you need in this particular case and nothing extra.

 
Magus I #:
i just made quick assumptions without analyzing the code's functionality on possible flaws

When working with other charts (time frames), you must handle possible errors in receiving data from another chart.

If you are creating a simple script, then why do you complicate it by working with other timeframes? Moreover, this is a script. It will not be difficult for you to open the D1 chart before using the script. And you don’t have to complicate the script by handling errors in receiving data from another timeframe.

Replace iTime with Time[] and write your own "iLowest" that will work with Close[] (as in your first code) or Low[] (as in your second code)


I don't like iXXX(), as you may have noticed😄