How to determine exact moment of market closure for the weekend

 

There doesn't seem to be any function that indicates whether the market is open or closed. I have looked at:

IsConnected()

IsTradeAllowed()

MarketInfo(Symbol(), MODE_TRADEALLOWED)

However all of these still return true or 1 during the weekend.

Is there a foolproof and good way to truly determine when a market is actually closed?

The only way i can think of is to submit a pending order; if OrderSend returns an error with the value ERR_MARKET_CLOSED then the market truly is closed. However submitting an order consumes resources (such as the single trade context thread), and takes time. It would not be a good solution if for example you want to be able to submit an order on the very final tick before the weekend, or the very first tick after the weekend.

 
hyperdimension:

There doesn't seem to be any function that indicates whether the market is open or closed. I have looked at:

IsConnected()

IsTradeAllowed()

MarketInfo(Symbol(), MODE_TRADEALLOWED)

However all of these still return true or 1 during the weekend.

Is there a foolproof and good way to truly determine when a market is actually closed?

The only way i can think of is to submit a pending order; if OrderSend returns an error with the value ERR_MARKET_CLOSED then the market truly is closed. However submitting an order consumes resources (such as the single trade context thread), and takes time. It would not be a good solution if for example you want to be able to submit an order on the very final tick before the weekend, or the very first tick after the weekend.



Look to the difference in datetime current bar and previous bar markets are closed in between if this is big enough

Start works with tickinput Sending with your EA a pendingtrade when markets are closed can't be done...

 

I've just checked that my expert advisor tried to open a trade at 21;50 UTC and kept trying, during which prices continued change for another 10 minutes. After each attempt there was error 132 ("Market is closed"). This shows that:

A change in price does not necessarily indicate that the market is open.

A pause in price for whatever amount of time does not necessarily indicate that the market is closed.

We need a proper way to check whether the market is actually open, accurate to the tick, without needing to continually query the server which creates unnecessary traffic, takes time and ties up the trade context which prevents an actual order from being submitted from the terminal.


 

may be try a brief open/delete of a StopLoss with some obnoxious, but real price number at each tick and/or every other second and if you get Err 132 - then market is closed. if not- cancel placed order..

Although, I would really make a great use of some MarketOpen() function.. ;)

 
hyperdimension:
I've just checked that my expert advisor tried to open a trade at 21;50 UTC and kept trying, during which prices continued change for another 10 minutes. After each attempt there was error 132 ("Market is closed"). This shows that:

A change in price does not necessarily indicate that the market is open.
The price doesn't change when the market is closed. Your 132 doesn't say the market is closed. It says your broker was closed. For example IBFX (USA) is closed July 4, but not the market.
 
WHRoeder:
The price doesn't change when the market is closed. Your 132 doesn't say the market is closed. It says your broker was closed. For example IBFX (USA) is closed July 4, but not the market.

The MQL4 Error codes page says that error 132 means "Market is closed." Maybe you are confused with the definition of "market".

The price certainly can change in MetaTrader when market is closed, even though it doesn't make sense, and you would know that the market is closed when you get error 132 after submitting a trade operation request (open order, close order, modify order). I have also experienced this before at FXCM after the new year break.

 
tsaitl:

may be try a brief open/delete of a StopLoss with some obnoxious, but real price number at each tick and/or every other second and if you get Err 132 - then market is closed. if not- cancel placed order..

As I wrote above, this creates unnecessary traffic, takes time and ties up the trade context which prevents an actual trade operation request from being submitted from the terminal. The trade context is single threaded, so there can only ever be one trade operation at one time.

 

I think the MODE_TRADEALLOWED MarketInfo variable would be a good way to indicate that the broker has closed the market, but MetaQuotes would need to change the logic in the server such that when the broker sets the market to "closed", MODE_TRADEALLOWED is automatically immediately set to 0. Since the values of the MarketInfo variables are sent to clients on every single tick, MarketInfo(Symbol(), MODE_TRADEALLOWED) would then return 0 in the client. At the moment, MODE_TRADEALLOWED can still be 1 even if you get error 132 after submitting a trade operation request.

 

Friends,

 

I needed to get information to know how to tell if the market is closed and from what I see here we do not have that.  I had to devise a little logic that worked.

Check the platform time second, then check it again after 1.5 seconds.  If the time seconds remain these (not chnaging) that means that platform or market is closed.

 

 

 platSec1 = TimeSeconds(TimeCurrent());

   Sleep(1500);

   platSec2 = TimeSeconds(TimeCurrent());

   if(platSec2 == platSec1){Alert(" ");Alert(" This platform is closed");}

 

Hope that helps 

 
Emmy_o:

Friends,

 

I needed to get information to know how to tell if the market is closed and from what I see here we do not have that.  I had to devise a little logic that worked.

Check the platform time second, then check it again after 1.5 seconds.  If the time seconds remain these (not chnaging) that means that platform or market is closed.

 

 

 platSec1 = TimeSeconds(TimeCurrent());

   Sleep(1500);

   platSec2 = TimeSeconds(TimeCurrent());

   if(platSec2 == platSec1){Alert(" ");Alert(" This platform is closed");}

 

Hope that helps 

Not good.

There are many temporary server freezings, when TimeCurrent() stops working. Look at Market Watch window. Sometimes its time doesn't change for seconds, even minutes.

 
TimeCurrent is the last known server time.  If the Internet looses packets it will be 30-60 seconds until the terminal retries to connect. Until the reconnect there will be no change.
Reason: