Skip market close

 

How can I detected market was closed in mql5 code funtion?

Some one know please tell me. Thanks!

 
Pham Duc Minh:

How can I detected market was closed in mql5 code funtion?

Some one know please tell me. Thanks!

Have a look at this function

https://www.mql5.com/en/docs/marketinformation/symbolinfosessiontrade

Documentation on MQL5: Market Info / SymbolInfoSessionTrade
Documentation on MQL5: Market Info / SymbolInfoSessionTrade
  • www.mql5.com
SymbolInfoSessionTrade - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks for your help. Can you give me a code sample ?

 
Pham Duc Minh #:

Thanks for your help. Can you give me a code sample ?

Here is an example

//+------------------------------------------------------------------+
//|                                     430266-MarketCloseDetect.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   datetime          from;                     // session beginning time
   datetime          to;                       // session end time
   bool              result;

      result = SymbolInfoSessionTrade(_Symbol,  MONDAY, 0, from, to);

      Print("");
      PrintFormat
      (
         "SymbolInfoSessionTrade=%-5s [%s %-10s %s %s]",
         string(result),
         _Symbol,
         EnumToString(MONDAY),
         TimeToString(from, TIME_SECONDS),
         TimeToString(to, TIME_SECONDS)
      );

   
      result = SymbolInfoSessionTrade(_Symbol,  SUNDAY, 0, from, to);
      PrintFormat
      (
         "SymbolInfoSessionTrade=%-5s [%s %-10s %s %s]",
         string(result),
         _Symbol,
         EnumToString(SUNDAY),
         TimeToString(from, TIME_SECONDS),
         TimeToString(to, TIME_SECONDS)
      );

  }
//+------------------------------------------------------------------+
Reason: