Download MetaTrader 5
To add comments, please log in or register
Have you discovered something really important? Write an article and receive 200 USD!
Edward Hirsch
709
Edward Hirsch 2015.05.26 17:43  
//+------------------------------------------------------------------+
//|                                               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.
Gordon Gekko
622
Gordon Gekko 2015.05.26 18:09  
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).



Edward Hirsch
709
Edward Hirsch 2015.05.26 18:36  
The expert at week ends reports "Trade not allowed for symbol".
Gordon Gekko
622
Gordon Gekko 2015.05.26 18:42  
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.

moonsboy
889
moonsboy 2015.05.27 03:34  

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;
  }
//+------------------------------------------------------------------+
whroeder1
14201
whroeder1 2015.05.27 10:56  
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.
/ /12
To add comments, please log in or register