How to close open positions at Friday market close

 

How can I know when the market is say an hour from the Friday closing or right at market close? I use demo accounts with two different brokers and they are on different server times and I would like to code my EA to close all open positions before the Friday market close. This is just for testing puposes but it is something I would like to know regardless. I don't want to hard code a time due to the fact that different brokers use different server times. Is this possible? I know I can detect market opening but due to the gap behavior seen at times on market openings I would be more comfortable closing positions before the Friday market close.

Thanks!

 
icwalter:

How can I know when the market is say an hour from the Friday closing or right at market close? I use demo accounts with two different brokers and they are on different server times and I would like to code my EA to close all open positions before the Friday market close. This is just for testing puposes but it is something I would like to know regardless. I don't want to hard code a time due to the fact that different brokers use different server times. Is this possible? I know I can detect market opening but due to the gap behavior seen at times on market openings I would be more comfortable closing positions before the Friday market close.

Thanks!

I use something like this, if you find a better way please let me know.


int CurrentDayWeek;  
int PreviousDayWeek;  
bool OpAllowed = true;

int start()
{

if (CurrentDayWeek!=TimeDayOfWeek(TimeCurrent()))
      {
      PreviousDayWeek=CurrentDayWeek;
      CurrentDayWeek=TimeDayOfWeek(TimeCurrent());
      }
 
 
 if ((CurrentDayWeek==5 && Hour()>=18) || CurrentDayWeek==6 || CurrentDayWeek==0 || (CurrentDayWeek==1 && Hour()<=3))
   OpAllowed=false;

. . .

}
 
lococo wrote >>

I use something like this, if you find a better way please let me know.

int CurrentDayWeek;  
int PreviousDayWeek;  
bool OpAllowed = true;

int start()
{

if (CurrentDayWeek!=TimeDayOfWeek(TimeCurrent()))
      {
      PreviousDayWeek=CurrentDayWeek;
      CurrentDayWeek=TimeDayOfWeek(TimeCurrent());
      }
 
 
 if ((CurrentDayWeek==5 && Hour()>=18) || CurrentDayWeek==6 || CurrentDayWeek==0 || (CurrentDayWeek==1 && Hour()<=3))
   OpAllowed=false;


}

I'm really new at this coding stuff. I'd tried to use the previously posted code, but when I tried to compile I got an error message that I had an unbalance parenthisis. And unexpected periods (just before the closing Parenthisis. I removed the periods and it compiled. The above posted code is what I ended up with that successfully compiled. Now to see if it will actually work for me. I'll let you know.

Alan