Day of week - MQl 4 ?

 
Hey Guys,



How does the code have to look like, if I want to open a Buy-Order every Monday?



if(DayOfWeek()==0 {



// Place Buy Order





}



sorry im new to mql

 
Spacegrey: sorry im new to mql

Since you are new, answering your question won't solve anything because you will not understand it due to the lack of basic framework.

So, I suggest you first invest some time in researching and learning the basics of MQL and how it all works.

Consult the documentation and study the many examples that are available in the CodeBase

Also, if you are just starting, I suggest you go straight to MQL5 instead of MQL4 (since development on that platform has been halted).

 
if(DayOfWeek()==1 //monday
{
// Place Buy Order
}
 
Spacegrey:



sorry im new to mql


If you want to open a trade every Monday, the following may help:

//---
If((DayOfWeek()==1) //OrderSend();

Where 0 is Sunday
1, Monday
2, Tuesday
3, Wednesday
4 , Thursday
5, Friday
6, Saturday

DayOfWeek

Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.

int  DayOfWeek();

Returned value

Current zero-based day of the week (0-Sunday,1,2,3,4,5,6).

Note

At the testing, the last known server time is modelled.

Example:

  // do not work on holidays.
  if(DayOfWeek()==0 || DayOfWeek()==6) return(0);




https://docs.mql4.com/dateandtime/dayofweek
 
Taras Slobodyanik:
if(DayOfWeek()==1 //monday
Don't hard code constants, use the proper enumerations
 
I think it will look more readable:
if(DayOfWeek() == MONDAY)
{
// Place Buy Order
}
 

You will also need to make provision in your code so that once an order has been opened, the EA will not open additional orders on that same monday.

 

Thank you very much and yes I already ordered some books on amazon about MQL 4 and MQL 5 - but there is actually not a big difference or? I mean the code still looks similar.




The only Problem I have is that I want to close the order the next day.

So everytime a order is opened at Monday, it  should close the order on the next day (Tuesday)


Is there a similar code snippet ?

Reason: