How to get specific symbol's trading hours !!!

 

Dear Fellow Members

How can I programmatically get the Symbols trading session timings for different assets I plan to trade in?

Trade Timings

So if I want to trade in AMZN Stock, I need to know the timings and programmatically restrict POSITION open and POSITION close just before 'Trade' Hours Close e.g. close at 22:45 Hrs

Looked at Symbol Properties, but could find any one to return me these values.

Highly appreciate the sooner reply.


[Deleted]  

SymbolInfoSessionQuote

Allows receiving time of beginning and end of the specified quoting sessions for a specified symbol and day of week.

SymbolInfoSessionTrade

Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and day of week.

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

This is how to use any of the above two functions in your code:

   for(uint day_of_week=0; day_of_week<7; day_of_week++)
     {
      string str="";
      uint session_index=0;
      datetime from,to;
      while(SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK)day_of_week,session_index++,from,to))
        {
         str+=TimeToString(from,TIME_MINUTES)+"-"+TimeToString(to,TIME_MINUTES)+" ";
        }
      PrintFormat("%10s: %s",EnumToString((ENUM_DAY_OF_WEEK)day_of_week),str);
     }
 
Fernando Carreiro #:

SymbolInfoSessionQuote

Allows receiving time of beginning and end of the specified quoting sessions for a specified symbol and day of week.

SymbolInfoSessionTrade

Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and day of week.

Thanks a lot @Fernando Carreiro

Also thanks for suggesting OrderCalcMargin() in one of my earlier post. At that time I could not understood how you wanted me to use it for currency conversion. However yesterday as I was researching about currency conversion, I got idea as how to use it to calculate 'Amount Invested' in the positions for PortfolioVaR. I needed a little bit of extra code to define ORDER_TYPE (for open positions, it is POSITION_TYPE) as well as code to maintain nominal value as -ve for SHORT positions. It seems to be working fine for now and will back test few strategies to confirm the accuracy.

Regards,

 
amrali #:

This is how to use any of the above two functions in your code:

Thanks a lot @amrali for thinking in advance and making my life easier by providing the code to use these functions. Else I would have really been struggling for it now.

Regards,

[Deleted]  
Topic has been moved to the section: Expert Advisors and Automated Trading