Your switch works differently than you intended :)
You forgot about the break operator.
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; }
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.
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!
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.
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
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.
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😄
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 :
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?