Open Trade at Specific Dates of Years

 

Hello MLQ4 Community,

I try to develop an Expert that needs to open, for testing purposes, buys and sells operations at specific dates of years.


This is the codes I know to open at specific hour every day; but not apply for the purposes, because not always needs to open operations during the week.

void HF1()

{int datetime1 = TimeLocal();

int hour0 = TimeHour(datetime1);

int minute0 = TimeMinute(datetime1);

if (hour0 == OpenHour && minute0 == OpenMinute)

below is an example of format date that I have.

2011.09.02 8:30
2011.08.05 8:30
2011.07.08 8:30
2011.06.03 8:30
2011.05.06 8:30
2011.04.01 8:30
2010.11.05 8:30
2010.10.08 8:30
2010.09.03 8:30
2010.08.06 8:30
2010.07.02 8:30
2010.06.04 8:30
2010.05.07 8:30
2010.04.02 8:30
2008.10.03 8:30
2008.09.05 8:30
2008.08.01 8:30
2008.07.03 8:30
2008.06.06 8:30
2008.05.02 8:30
2008.04.04 8:30
2007.11.02 8:30
2007.10.05 8:30
2007.09.07 8:30
2007.08.03 8:30
2007.07.06 8:30
2007.06.01 8:30
2007.05.04 8:30
2011.03.04 9:30
2011.02.04 9:30


I will appreciate any help.

Thanks.

 
paulsom:
I try to develop an Expert that...
  1. Then post your code.
  2. No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
 
paulsom:

Hello MLQ4 Community,

I try to develop an Expert that needs to open, for testing purposes, buys and sells operations at specific dates of years.


This is the codes I know to open at specific hour every day; but not apply for the purposes, because not always needs to open operations during the week.

void HF1()

{int datetime1 = TimeLocal();

int hour0 = TimeHour(datetime1);

int minute0 = TimeMinute(datetime1);

if (hour0 == OpenHour && minute0 == OpenMinute)

below is an example of format date that I have.

2011.09.02 8:30
2011.08.05 8:30
2011.07.08 8:30
2011.06.03 8:30
2011.05.06 8:30
2011.04.01 8:30
2010.11.05 8:30
2010.10.08 8:30
2010.09.03 8:30
2010.08.06 8:30
2010.07.02 8:30
2010.06.04 8:30
2010.05.07 8:30
2010.04.02 8:30
2008.10.03 8:30
2008.09.05 8:30
2008.08.01 8:30
2008.07.03 8:30
2008.06.06 8:30
2008.05.02 8:30
2008.04.04 8:30
2007.11.02 8:30
2007.10.05 8:30
2007.09.07 8:30
2007.08.03 8:30
2007.07.06 8:30
2007.06.01 8:30
2007.05.04 8:30
2011.03.04 9:30
2011.02.04 9:30

I will appreciate any help.

Thanks.








paulsom,

In General you should code the following:

1. Save trade date and time data into an array.

2. Complete a while loop to evaluate the current date and time against the array.

3. If match then perform the trade function.

 
ForexSurfr:


paulsom,

In General you should code the following:

1. Save trade date and time data into an array.

2. Complete a while loop to evaluate the current date and time against the array.

3. If match then perform the trade function.


too complicated can be easier done.......
 

from a beginning coder here, but I'm kind of copy my EA around to get what i wanted... You can simply void out the date u don't want to trade,

just put it before order send function.

link to "day of year" calendar: http://www.esrl.noaa.gov/gmd/grad/neubrew/Calendar.jsp

you might spend half an hour adding the correct DayofYear, but each year is different anyway, so it doesn't hurt to know how.

https://docs.mql4.com/dateandtime/DayOfYear

The code below is from my EA, I only trade on specific day for the purpose of specific news; code filter out days in Jan 2013.


// stop trading on the following DayofYear, EA will trade any days that are not listed below. 
  if(DayOfYear()==1 || DayOfYear()==2 || DayOfYear()==3 || DayOfYear()==7 || DayOfYear()==8 || DayOfYear()==9 || DayOfYear()==10
  || DayOfYear()==11 || DayOfYear()==14 || DayOfYear()==18 || DayOfYear()==21|| DayOfYear()==22 || DayOfYear()==23 || DayOfYear()==25
  || DayOfYear()==2 || DayOfYear()==29) return(true);


// does not trade Mon & Fri.
  if(DayOfWeek()==1 || DayOfWeek()==5) return(0);
Reason: