SymbolInfoSessionTrade

 

Hi all,

please see screenshot

   string   str_start = TimeToString(start, TIME_MINUTES),
            str_end   = TimeToString(end, TIME_MINUTES),
            str_now   = TimeToString(now, TIME_MINUTES);

I'm getting 00:00 for start and end

How can I determine that the market is open for trading?

This is the code on how I check

   start = StringToTime(str_start);
   end   = StringToTime(str_end);
   now   = StringToTime(str_now);

   if(start <= now && now <= end) return(true);
 
Dua Yong Rew: Hi all, please see screenshot I'm getting 00:00 for start and end How can I determine that the market is open for trading?

If you want help then please show your actual code for obtaining the session times as well as the log output from printing those values.

 
Dua Yong Rew:

Hi all,

please see screenshot

I'm getting 00:00 for start and end

How can I determine that the market is open for trading?

Here is the list of all function with explanation, you can search for keywords: https://www.mql5.com/en/docs/function_indices

And here is (from there) the function about the session time: https://www.mql5.com/en/docs/marketinformation/symbolinfosessionquote

There is more on the left side...

Documentation on MQL5: List of MQL5 Functions
Documentation on MQL5: List of MQL5 Functions
  • www.mql5.com
List of MQL5 Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Dua Yong Rew:

Hi all,

please see screenshot

I'm getting 00:00 for start and end

How can I determine that the market is open for trading?

That is not an issue if you are reading todays weekday as the datetime will never display 24:00 but 00:00 . So it is probably correct , however , if you want to make sure check a weekday that ends earlier , friday for example , where you should get 23:55

 

sorry, missed out the code

updated in the first thread

When the start and end is 00:00

my checking code will fail

for other brokers that begins with 00:02 till 23:58, this code will have no issues.

 

A proposition how to determine whether the market is open:


bool IsMarketOpen(const string symbol) {
  datetime from, to;
  datetime serverTime = TimeTradeServer();
  MqlDateTime dt;
  TimeToStruct(serverTime,dt);
  const ENUM_DAY_OF_WEEK day_of_week = (ENUM_DAY_OF_WEEK) dt.day_of_week;
  const int time = (int) MathMod(serverTime,PeriodSeconds(PERIOD_D1));
  int session = 0;
  while (SymbolInfoSessionTrade (symbol, day_of_week, session, from, to)) {
    if(time >=from && time <= to ) {
      return true;
    }
    session++;
  }
  return false;
}
Please adapt it for your needs 
 
Dr Matthias Hammelsbeck #:

A proposition how to determine whether the market is open:


Please adapt it for your needs 

Hello,

May I know what does the session variable do?