DayOfWeek() - page 2

 
//+------------------------------------------------------------------+
//|                                               Check Mkt Open.mq4 |
//|                            Copyright 2015, Edward Hirsch (sxTed) |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Edward Hirsch (sxTed)"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   if (MarketInfo(Symbol(),MODE_TRADEALLOWED)==1) Print("Trade is allowed for symbol ", Symbol());
   else                                           Print("Trade is not allowed for symbol ", Symbol());   
  }
//+------------------------------------------------------------------+
this works in a script, also works in an EA.
 
sxTed:
this works in a script, also works in an EA.

Honestly, thank you. I am able to code, but as I said before 2 times, it did not work (I did try it at the weekend).



 
The expert at week ends reports "Trade not allowed for symbol".
 
sxTed:
The expert at week ends reports "Trade not allowed for symbol".

The expert at weekend reported "Trade IS allowed for symbol".

Maybe it was a failure, maybe not.

If there won't be an other solution, I will try it again at the next weekend.

It is also conceivable that trade is allowed at the weekend, but market is closed, so one can not open trades. It is weird.

 

Hi Ggekko,

 

Hope this can help.

If the code can be used, please check the  market open and close times of your symbol and update the values of "closeH" and "openH" accordingly.

For holiday besides weekend, do you  have any concern? I haven't good idea for the moment.

By the way, I also have an issue of indicator found after back testing and it's easy to find that thread in the forum as I updated it today. It's highly appreciated if you can help ! 

 

extern int closeH=18;
extern int openH=3;

int CurrentDayWeek=-1;
int PreviousDayWeek;
bool OpAllowed=true;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int lday=TimeDayOfWeek(TimeCurrent());
   if(CurrentDayWeek!=lday)
     {
      PreviousDayWeek=CurrentDayWeek;
      CurrentDayWeek=lday;
     }
   if((CurrentDayWeek==5 && Hour()>=closeH) || CurrentDayWeek==6 || CurrentDayWeek==0 || (CurrentDayWeek==1 && Hour()<=openH))
      OpAllowed=false;
  }
//+------------------------------------------------------------------+
 
ggekko:

This EA works perfectly in this method. One can use Timeseries and Indicators Access instead of predefined variables. You are right about tester.

My only need is the knowing of status of the market (open or closed).

  1. If it works perfectly, then why are you posting here?
  2. If there are ticks, the market is open. You can not use time. Weekends, and market holidays depends on the broker.
Reason: