How to find out if the market is closed? (mql4) - page 5

 

I still haven't figured out how to get adequate information from DayOfWeek. It gives the correct value on the day the robot starts and in some other cases (sometimes). It seems to me that it gives out a correct value when I open orders. If you don't open anything, it will give you the weather.

I have solved the problem this way:

...
int realDay=DayOfWeek();
int curHour=TimeHour(TimeLocal());
   while(!IsStopped())
      {
      if (TimeHour(TimeLocal())<curHour) realDay++; 
      curHour=TimeHour(TimeLocal());
      if (realDay==7) realDay=0;        
...     

But I haven't tested it yet )))) It should work.

 
winsight:

I still haven't figured out how to get adequate information from DayOfWeek. It gives the correct value on the day the robot starts and in some other cases (sometimes). It seems to me that it gives out a correct value when I open orders. If you don't open anything, it will give you the weather.

I have solved the problem this way:

But I haven't tested it yet ))) It should work.

It's easier - use TimeDayOfWeek:

int dayOfWeek = TimeDayOfWeek(TimeCurrent());
 
Ihor Herasko:
In this way you will only get the permission status of the instrument to trade. If the instrument is traded, you will get true for it any day of the week.

Alert(bool(MarketInfo(Symbol(),MODE_TRADEALLOWED));

false

 
Vasyl Nosal:

Alert(bool(MarketInfo(Symbol(),MODE_TRADEALLOWED));

false

My version is as follows:

   Alert("Trade allowed by MarketInfo: ", bool(MarketInfo(Symbol(),MODE_TRADEALLOWED)));
   Alert("Trade allowed by IsTradeAllowed: ", bool(IsTradeAllowed()));
   Alert("Trade allowed by IsTradeAllowed 2-nd version: ", bool(IsTradeAllowed(Symbol(), TimeLocal())));

Result:

2015.12.20 16:41:21.196 Test EURUSD,H1: Alert: Trade allowed by IsTradeAllowed 2-nd version: false
2015.12.20 16:41:21.196 Test EURUSD,H1: Alert: Trade allowed by IsTradeAllowed: true
2015.12.20 16:41:21.196 Test EURUSD,H1: Alert: Trade allowed by MarketInfo: true

On my computer the time is GMT+2.

That's why I don't understand how you managed to get false in the first case. Perhaps, you took an instrument that is not traded in principle.

The following are the conclusions:

  1. The first and second options are essentially indentical. They only point to the fact that autotrading for the instrument is enabled and there is free trade flow.
  2. The third variant is just what we need. It allows you to know the permission to trade on an instrument with reference to its working schedule.
 
Ihor Herasko:

My version is this:

Result:

On my computer the time is GMT+2.

It is therefore not clear how you managed to get false on the first option. Perhaps, you took an instrument that is not traded in principle.

The following are the conclusions:

  1. The first and second options are essentially indentical. They only point to the fact that autotrading for the instrument is enabled and there is free trade flow.
  2. The third variant is just what we need. It allows you to know the permission to trade on an instrument given its work schedule.
EURUSD fxOpen
 
Vasyl Nosal:
EURUSD fxOpen

Indeed, this broker has the result of the script above:

2015.12.20 17:19:18.685 Test GBPUSD,H4: Alert: Trade allowed by IsTradeAllowed 2-nd version: false
2015.12.20 17:19:18.685 Test GBPUSD,H4: Alert: Trade allowed by IsTradeAllowed: false
2015.12.20 17:19:18.685 Test GBPUSD,H4: Alert: Trade allowed by MarketInfo: false

Started checking other brokers. Broker G**X:

2015.12.20 17:18:14.339 Test EURUSD,M314: Alert: Trade allowed by IsTradeAllowed 2-nd version: false
2015.12.20 17:18:14.339 Test EURUSD,M314: Alert: Trade allowed by IsTradeAllowed: false
2015.12.20 17:18:14.339 Test EURUSD,M314: Alert: Trade allowed by MarketInfo: true

Broker A***i:

2015.12.20 17:20:40.372 Test EURUSD,M15: Alert: Trade allowed by IsTradeAllowed 2-nd version: false
2015.12.20 17:20:40.372 Test EURUSD,M15: Alert: Trade allowed by IsTradeAllowed: true
2015.12.20 17:20:40.372 Test EURUSD,M15: Alert: Trade allowed by MarketInfo: true

Broker I***a F***x:

2015.12.20 17:21:38.663 test GBPUSD,H1: Alert: Trade allowed by IsTradeAllowed 2-nd version: false
2015.12.20 17:21:38.663 test GBPUSD,H1: Alert: Trade allowed by IsTradeAllowed: false
2015.12.20 17:21:38.663 test GBPUSD,H1: Alert: Trade allowed by MarketInfo: false

My first test today was on A*****l M*****s.

Thus, we get that not all brokers have correctly working IsTradeAllowed (first version) and MODE_TRADEALLOWED. And on the other hand, the second version of IsTradeAllowed works correctly everywhere. So, it is better to use it.

 
Ihor Herasko:

Indeed, this broker has the result of the script above:

Started checking other brokers. Broker G**X:

Broker A***i:

Broker I***a F***x:

My first test today was on A*****l M*****s.

Thus, we get that not all brokers have correctly working IsTradeAllowed (first version) and MODE_TRADEALLOWED. And on the other hand, the second version of IsTradeAllowed works correctly everywhere. So, it is better to use it.

And today

IsTradeAllowed(Symbol(), TimeCurrent())

it shows cowardly

By the way, why do you have Local time?

 
Vasyl Nosal:

And today

IsTradeAllowed(Symbol(), TimeCurrent())

shows cowardly

By the way why do you have Local time?

Today is a holiday so it's hard.
 
Alexey Busygin:
It's a holiday weekend, so it's hard.
The fact is that none of the recognition features are working 100%.
 
Vasyl Nosal:
The fact is that none of the recognition functions work 100%.
In some cases, the response must come from the DC server! And the DCs do not really care about it. That's why it works somehow.
Reason: