Market Open or Close - how can I find it?

 

Hi,

How can I find market Open or Close?

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

Thank you.

 

What do you mean exactly by Market Open???

Do you mean the opening price of each week? If so, get the info using:

https://docs.mql4.com/series/iOpen

Specifying the weekly bar

 

I don´t think open or close price. I mean if market open or close.

example: Sometimes is market closed during day (comodities, futures, softs etc.) Every market have individual open-close hours. And I need my EA identified if market open or close.

 
Your EA will only work if the market is open. How can something that is not receiving ticks to enable processing carry out any checks???
 
endy5:

Hi,

How can I find market Open or Close?

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

Thank you.

In a loop, if the last server time is the same with the current server time while the last local time is different with current local time, and you have connection, then market is close.

Got it ?

:D

 

"Your EA will only work if the market is open"

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)

I do not want manually set open/close hour for every markets. I want to do automatically inside my code EA .

 

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

return 1 - if market open else return 0

 
endy5:

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

return 1 - if market open else return 0

When market close, there is no tick, so in the end you still need a loop.

:D

 
endy5:

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

return 1 - if market open else return 0


Although some 3 years after the fact, I found your solution when searching for an answer to the same question and let me congratulate you. It is superb! And of course it doesn't matter that there is no tick if you are using OnTimer() (instead of start() or OnTick()). I tried with IsTradeAllowed() but it didn't work, and so I thought it wouldn't work with MarketInfo but, alas, it does. There are other reasons which could cause trading not to be allowed but, as far as I know, your solution is as close as it gets. :)

 
Ricardo1:


Although some 3 years after the fact, I found your solution when searching for an answer to the same question and let me congratulate you. It is superb! And of course it doesn't matter that there is no tick if you are using OnTimer() (instead of start() or OnTick()). I tried with IsTradeAllowed() but it didn't work, and so I thought it wouldn't work with MarketInfo but, alas, it does. There are other reasons which could cause trading not to be allowed but, as far as I know, your solution is as close as it gets. :)

Hi guys,

There is no MarketInfo() in MT5. Also, this kind of solution works for holidays and days off?

Thanks

 
Gustavo Hennemann:

Hi guys,

There is no MarketInfo() in MT5. Also, this kind of solution works for holidays and days off?

Thanks

Hello,

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


datetime prevTimeCurrent=TimeCurrent();
bool infoMarket;



int OnInit()
  {
//--- create timer
   EventSetTimer(5);
      
   return(INIT_SUCCEEDED);
  }



void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }



//+------------------------------------------------------------------+
//| 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;
      }
  }


Hope this will help you.

Massimo

Reason: