Market Open or Close - how can I find it? - page 2

To add comments, please log in or register
Keith Watford
Moderator
15779
Keith Watford  
MassimoMondo:

Hello,

I found a simple solution with OnTimer routine. Let's see the MQL code:

Hope this will help you.

Massimo

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if (TimeCurrent() == prevTimeCurrent){
      Comment ("Market is CLOSED - Local Time : ",TimeLocal());
      infoMarket=FALSE;
   }
   else {
      Comment ("Market is OPEN - Local Time : ",TimeLocal());
      infoMarket=TRUE;
      }
  }


If it was working ( it doesn't as prevTimeCurrent is never updated)

This will only tell you that there have been no ticks for 5 seconds.

Pavel Soukup:

Yes. I know it. But I need trading more markets at the same time and ALL MARKETS MUST BE OPEN (gold, oil, S&P, fx)

It will not tell you if any particular market is open.

Taskin Osman
795
Taskin Osman  
Especially during holidays in december these times will change a lot and this might confuse your strategy. The fact is that these times depend on your broker and the markets you trade AND the major holidays. There is no simple super solution for your problem.
MattewMoRy
8
MattewMoRy  
Pavel Soukup:

I find solution for me: MarketInfo(Symbol(), MODE_TRADEALLOWED);

return 1 - if market open else return 0

Thank You for share the solution.


MQL4 Code:

   if((MarketInfo(Symbol(),MODE_TRADEALLOWED))>0)
     {
      Print(" Market is Open and Trade is Allowed on This Symbol.");
     }
   else
     {
      Print ("Trade is not Allowed on This Symbol RightNow.");
     }
Marco vd Heijden
Moderator
8836
Marco vd Heijden  
if(GetLastError()==ERR_MARKET_CLOSED)
  {
   Print("Market is closed!");
  }

You can also analyze the error when your ordersend call fails.

Nikolaos Pantzos
32141
Nikolaos Pantzos  
Pavel Soukup:

Hi,

How can I find market Open or Close?

dunction GetLastError()? What value return function? Or other function/way? Other solution?

Thank you.

You can to use this reference... to check day by day the time to beggin and time to end the market session.

bool  SymbolInfoSessionTrade( 
   string            name,                // symbol name 
   ENUM_DAY_OF_WEEK  day_of_week,         // day of the week 
   uint              session_index,       // session index 
   datetime&         from,                // session beginning time 
   datetime&         to                   // session end time 
   );

12
To add comments, please log in or register