How to check if market is open for some symbols? - page 2

 
Fernando Carreiro #:
In the Experts tab.

I don't find it

Is it in MetaEditor or in MT5?

 

For the Strategy Tester, but also on Live trading, you have to always first synchronise the symbol data you plan to use.

Please read the following ... Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access

However, just to prove the point, here is some sample EA code with a quick and dirty way to synchronise the symbol data. Don't use this on a real EA.

For a proper way, read the link above. This was just for a quick sample ...

string sSymbols[] = {
   "EURUSD",   // Enabled on Market Watch
   "GBPUSD",   // Disabled on Market Watch
   "EURGBP",   // Enabled on Market Watch
   "USDJPY",   // Disabled on Market Watch
   "XAUUSD"    // Enabled on Market Watch
   };

void OnTick( void ) {
   // Synchronise first (not very well written, just a quick & dirty way )
      uint nCount, nSymbolCount = sSymbols.Size();
      do {
         nCount = 0;
         for( uint i = 0; i < nSymbolCount; i++ ) {
            string sSymbol = sSymbols[i];
            nCount += iTime( sSymbol, _Period, 0 ) > 0 ? 1 : 0;
            };
      } while( nCount < nSymbolCount );
         
   // Check sessions
      for( uint i = 0; i < nSymbolCount; i++ ) {
         string sSymbol = sSymbols[i];
         datetime dtFrom = WRONG_VALUE, dtTo = WRONG_VALUE;
         ResetLastError();
         if( SymbolInfoSessionQuote( sSymbol, TUESDAY, 0, dtFrom, dtTo ) )
            Print( i, ") ", sSymbol, ": Tuesday from ", dtFrom, " to ", dtTo );
         else
            Print( i, ") ", sSymbol, ": Error ", _LastError );
      };

   // Exit the program
      ExpertRemove();
};
2023.11.20 22:17:56.590 Tester  "(Test)\Test.ex5" 64 bit
2023.11.20 22:17:56.591 Tester  custom group settings applied from file 'MQL5\Profiles\Tester\Groups\RoboForex-ECN_demo.txt'
2023.11.20 22:17:56.869 Tester  EURUSD: history data begins from 2016.01.12 00:00
2023.11.20 22:17:56.871 Tester  EURUSD: preliminary downloading of history ticks started, it may take quite a long time
2023.11.20 22:17:57.885 Tester  EURUSD: preliminary downloading of history ticks completed, 6.22 Kb in 0:00:01.016 (6.12 Kb/sec)
2023.11.20 22:17:57.885 Tester  EURUSD: ticks data begins from 2022.01.03 00:00
2023.11.20 22:17:57.886 Tester  EURUSD: history data begins from 2016.01.12 00:00
2023.11.20 22:17:57.887 Tester  EURUSD: ticks data begins from 2022.01.03 00:00
2023.11.20 22:17:57.887 Core 1  connecting to 127.0.0.1:3000
2023.11.20 22:17:57.889 Core 1  connected
2023.11.20 22:17:57.906 Core 1  authorized (agent build 4040)
2023.11.20 22:17:57.916 Tester  EURUSD,M1 (RoboForex-ECN): testing of Experts\(Test)\Test.ex5 from 2022.01.02 00:00 to 2022.01.31 00:00
2023.11.20 22:17:57.954 Core 1  common synchronization completed
2023.11.20 22:17:57.969 Core 1  EURUSD: ticks synchronized already [43 bytes]
2023.11.20 22:17:59.222 Core 1  GBPUSD: ticks synchronized already [43 bytes]
2023.11.20 22:18:00.374 Core 1  EURGBP: ticks synchronized already [43 bytes]
2023.11.20 22:18:01.509 Core 1  USDJPY: ticks synchronized already [43 bytes]
2023.11.20 22:18:02.705 Core 1  XAUUSD: ticks synchronized already [43 bytes]
2023.11.20 22:18:02.847 Core 1  shutdown finished
2023.11.20 22:18:02.847 Core 1  login (build 4040)
2023.11.20 22:18:02.847 Core 1  account info found with currency USD
2023.11.20 22:18:02.847 Core 1  expert file added: Experts\(Test)\Test.ex5. 6687 bytes loaded
2023.11.20 22:18:02.847 Core 1  initial deposit 10000.00 USD, leverage 1:100
2023.11.20 22:18:02.847 Core 1  successfully initialized
2023.11.20 22:18:02.847 Core 1  6286 bytes of total initialization data received
2023.11.20 22:18:02.847 Core 1  Intel Core i7-4790T  @ 2.70GHz, 16274 MB
2023.11.20 22:18:02.847 Core 1  EURUSD: symbol to be synchronized
2023.11.20 22:18:02.847 Core 1  EURUSD: symbol synchronized already, 18 bytes received
2023.11.20 22:18:02.847 Core 1  EURUSD: load 27 bytes of history data to synchronize in 0:00:00.001
2023.11.20 22:18:02.847 Core 1  EURUSD: history synchronized from 2021.01.04 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  EURUSD: ticks synchronization started
2023.11.20 22:18:02.847 Core 1  EURUSD: load 34 bytes of tick data to synchronize in 0:00:00.000
2023.11.20 22:18:02.847 Core 1  EURUSD: history ticks synchronized from 2022.01.03 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  EURUSD,M1: history cache allocated for 399928 bars and contains 368900 bars from 2021.01.04 00:05 to 2021.12.31 20:00
2023.11.20 22:18:02.847 Core 1  EURUSD,M1: history begins from 2021.01.04 00:05
2023.11.20 22:18:02.847 Core 1  EURUSD,M1 (RoboForex-ECN): generating based on real ticks
2023.11.20 22:18:02.847 Core 1  EURUSD,M1: testing of Experts\(Test)\Test.ex5 from 2022.01.02 00:00 to 2022.01.31 00:00 started
2023.11.20 22:18:02.847 Core 1  EURUSD : real ticks begin from 2022.01.03 00:00:00
2023.11.20 22:18:02.847 Core 1  GBPUSD: symbol to be synchronized
2023.11.20 22:18:02.847 Core 1  GBPUSD: symbol synchronized already, 18 bytes received
2023.11.20 22:18:02.847 Core 1  GBPUSD: load 27 bytes of history data to synchronize in 0:00:00.000
2023.11.20 22:18:02.847 Core 1  GBPUSD: history synchronized from 2021.01.04 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  GBPUSD: ticks synchronization started
2023.11.20 22:18:02.847 Core 1  GBPUSD: load 34 bytes of tick data to synchronize in 0:00:01.000
2023.11.20 22:18:02.847 Core 1  GBPUSD: history ticks synchronized from 2022.01.03 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  GBPUSD,M1: history cache allocated for 399083 bars and contains 368055 bars from 2021.01.04 00:05 to 2021.12.31 20:00
2023.11.20 22:18:02.847 Core 1  GBPUSD,M1: history begins from 2021.01.04 00:05
2023.11.20 22:18:02.847 Core 1  EURGBP: symbol to be synchronized
2023.11.20 22:18:02.847 Core 1  EURGBP: symbol synchronized already, 18 bytes received
2023.11.20 22:18:02.847 Core 1  EURGBP: load 27 bytes of history data to synchronize in 0:00:00.000
2023.11.20 22:18:02.847 Core 1  EURGBP: history synchronized from 2021.01.04 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  EURGBP: ticks synchronization started
2023.11.20 22:18:02.847 Core 1  EURGBP: load 34 bytes of tick data to synchronize in 0:00:01.015
2023.11.20 22:18:02.847 Core 1  EURGBP: history ticks synchronized from 2022.01.03 to 2022.12.30
2023.11.20 22:18:02.847 Core 1  EURGBP,M1: history cache allocated for 399733 bars and contains 368705 bars from 2021.01.04 00:05 to 2021.12.31 20:00
2023.11.20 22:18:02.847 Core 1  EURGBP,M1: history begins from 2021.01.04 00:05
2023.11.20 22:18:02.847 Core 1  USDJPY: symbol to be synchronized
2023.11.20 22:18:02.847 Core 1  USDJPY: symbol synchronized already, 18 bytes received
2023.11.20 22:18:02.847 Core 1  USDJPY: load 27 bytes of history data to synchronize in 0:00:00.000
2023.11.20 22:18:02.847 Core 1  USDJPY: history synchronized from 2021.01.04 to 2022.01.31
2023.11.20 22:18:02.847 Core 1  USDJPY: ticks synchronization started
2023.11.20 22:18:02.847 Core 1  USDJPY: load 34 bytes of tick data to synchronize in 0:00:01.016
2023.11.20 22:18:02.847 Core 1  USDJPY: history ticks synchronized from 2022.01.03 to 2022.01.28
2023.11.20 22:18:02.847 Core 1  USDJPY,M1: history cache allocated for 399743 bars and contains 368715 bars from 2021.01.04 00:05 to 2021.12.31 20:00
2023.11.20 22:18:02.847 Core 1  USDJPY,M1: history begins from 2021.01.04 00:05
2023.11.20 22:18:02.847 Core 1  XAUUSD: symbol to be synchronized
2023.11.20 22:18:02.847 Core 1  XAUUSD: symbol synchronized already, 18 bytes received
2023.11.20 22:18:02.847 Core 1  XAUUSD: load 27 bytes of history data to synchronize in 0:00:00.000
2023.11.20 22:18:02.847 Core 1  XAUUSD: history synchronized from 2021.01.04 to 2022.01.31
2023.11.20 22:18:02.847 Core 1  XAUUSD: ticks synchronization started
2023.11.20 22:18:02.847 Core 1  XAUUSD: load 34 bytes of tick data to synchronize in 0:00:01.063
2023.11.20 22:18:02.847 Core 1  XAUUSD: history ticks synchronized from 2022.01.03 to 2022.01.28
2023.11.20 22:18:02.847 Core 1  XAUUSD,M1: history cache allocated for 383725 bars and contains 352697 bars from 2021.01.04 01:00 to 2021.12.31 20:00
2023.11.20 22:18:02.847 Core 1  XAUUSD,M1: history begins from 2021.01.04 01:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   0) EURUSD: Tuesday from 1970.01.01 00:00:00 to 1970.01.01 23:59:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   1) GBPUSD: Tuesday from 1970.01.01 00:00:00 to 1970.01.01 23:59:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   2) EURGBP: Tuesday from 1970.01.01 00:00:00 to 1970.01.01 23:59:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   3) USDJPY: Tuesday from 1970.01.01 00:00:00 to 1970.01.01 23:59:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   4) XAUUSD: Tuesday from 1970.01.01 01:00:00 to 1970.01.01 23:55:00
2023.11.20 22:18:02.847 Core 1  2022.01.03 00:21:31   ExpertRemove() function called
2023.11.20 22:18:02.847 Core 1  final balance 10000.00 USD
2023.11.20 22:18:02.847 Core 1  removed itself on 3% of testing interval
2023.11.20 22:18:02.847 Core 1  EURUSD,M1: 1 ticks, 1 bars generated. Environment synchronized in 0:00:00.053. Test passed in 0:00:04.891 (including ticks preprocessing 0:00:00.156).
2023.11.20 22:18:02.847 Core 1  EURUSD,M1: total time from login to stop testing 0:00:04.944 (including 0:00:04.141 for history data synchronization)
2023.11.20 22:18:02.847 Core 1  464 Mb memory used including 113 Mb of history data, 64 Mb of tick data
2023.11.20 22:18:02.847 Core 1  log file "C:\Trading\MetaQuotes\MetaTrader 5\Tester\Agent-127.0.0.1-3000\logs\20231120.log" written
2023.11.20 22:18:02.855 Core 1  connection closed
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Organizing Data Access - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Avi #: I don't find it. Is it in MetaEditor or in MT5?

MetaTrader ...


 
Fernando Carreiro #:

MetaTrader ...


Ok

It works in the live chart but not in the debugger

I will try the code

Thank you

 
Avi #: Ok. It works in the live chart but not in the debugger. I will try the code. Thank you

Read my post #12.

⚠️NB! Very, very, important❗ Research and apply the information in the link
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access

How to check if market is open for some symbols?
How to check if market is open for some symbols?
  • 2023.11.20
  • www.mql5.com
SymbolInfoSessionTrade works only for the symbol of the current chart How can I get info about other symbols...
Reason: