IsTradeAllowed

 

EDIT : Ignore this , my mistake on the sessions times , the question is if SymbolInfoSessionTrade will adapt sessions to holidays of that week.

When i run this code on MT4 to get whether or not trading will be possible on monday (tested on AUDUSD) it returns false : 

  MqlDateTime mqt;
  mqt.day=2;
  mqt.mon=1;
  mqt.year=2023;
  mqt.hour=0;
  mqt.min=0;
  mqt.sec=0;
  datetime t=StructToTime(mqt);
  bool is=IsTradeAllowed(_Symbol,t);
  string msg=TimeToString(t,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+" Trading("+is+")";
  Comment(msg);

When i run this code on MT5 to get the trade session for Monday it returns the session as a normal monday .

  datetime from,to;
  bool result=SymbolInfoSessionTrade(_Symbol,MONDAY,0,from,to);
  if(result){
  Print("read trade session");
  Print("From "+TimeToString(from,TIME_MINUTES|TIME_SECONDS)+" To "+TimeToString(to,TIME_MINUTES|TIME_SECONDS));
  }else{
  Print("Cannot read trade session");
  }

Same broker .

Is there a more accurate equivalent for IsTradeAllowed for MT5 or is the MT4 return wrong ? 

Thank you 

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Lorentzos Roussos:

When i run this code on MT4 to get whether or not trading will be possible on monday (tested on AUDUSD) it returns false : 

When i run this code on MT5 to get the trade session for Monday it returns the session as a normal monday .

Same broker .

Is there a more accurate equivalent for IsTradeAllowed for MT5 or is the MT4 return wrong ? 

Thank you 

I checked the ducomentation for SymbolInfoSessionTrade

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

It means it saves the start and end time of a session referred to by "index", in datetime references passed to the function. And if the task is done successfully it returns true. 

So the return value has nothing to do with IsTradeAllowed in MQL4. It is doing something totally different.

 
Lorentzos Roussos:

When i run this code on MT4 to get whether or not trading will be possible on monday (tested on AUDUSD) it returns false : 

When i run this code on MT5 to get the trade session for Monday it returns the session as a normal monday .

Same broker .

Is there a more accurate equivalent for IsTradeAllowed for MT5 or is the MT4 return wrong ? 

Thank you 

Have you tried TerminalInfoInteger(TERMINAL_TRADE_ALLOWED ) for MQL5. I havent tried!

 
Lorentzos Roussos:

When i run this code on MT4 to get whether or not trading will be possible on monday (tested on AUDUSD) it returns false : 

When i run this code on MT5 to get the trade session for Monday it returns the session as a normal monday .

Same broker .

Is there a more accurate equivalent for IsTradeAllowed for MT5 or is the MT4 return wrong ? 

Thank you 

Also This: 

MarketInfo(_Symbol, MODE_TRADEALLOWED)
 
Yashar Seyyedin #:

Have you tried TerminalInfoInteger(TERMINAL_TRADE_ALLOWED ) for MQL5. I havent tried!

Thanks 

Actually the first post is my error .

Both return the proper time as the trading on monday on audusd on my broker starts 5 minutes after midnight . 

On mt4 i was stupidly checking exactly at midnight . So the function works.

If i point the IsTradeAllowed on 24th of December any time of the day it correctly reports that trading was not allowed back then .

The question is rephrased then to 

Will SymbolInfoSessionTrade adapt to holidays ?

Should have tested this last week damit

 
Lorentzos Roussos: When i run this code on MT4 to get whether or not trading will be possible on monday (tested on AUDUSD) it returns false : When i run this code on MT5 to get the trade session for Monday it returns the session as a normal monday . Same broker . Is there a more accurate equivalent for IsTradeAllowed for MT5 or is the MT4 return wrong ? Thank you 

EDIT: My post was too late and you have already clarified the time to 00:05.

Are you sure trading is allowed at 00:00? There is usually a break for swaps.


 
Fernando Carreiro #:

Are you sure trading is allowed at 00:00? There is usually a break to swaps.


That was my mistake , i was polling 00:00:00 on MT4 

 
Lorentzos Roussos #The question is rephrased then to Will SymbolInfoSessionTrade adapt to holidays ? Should have tested this last week damit

Not that I am aware of. It is somewhat static. It even fails for DST in the Strategy Tester as well.

It is only valid for current time, and the broker updates it when a the DST comes into effect (but sometimes they forget and only update it later).

 
Fernando Carreiro #:

Not that I am aware of. It is somewhat static. It even fails for DST in the Strategy Tester as well.

It is only valid for current time, and the broker updates it when a the DST comes into effect (but sometimes they forget and only update it later).

Thank you .

So this means IsTradeAllowed is potentially wrong too , sometimes .

Does it poll the broker's server with each request (because i can request dates from the past , paired with sessions not being updated for holidays , and the fact i got false for a trading holiday ) ?  

 
Lorentzos Roussos #: Thank you . So this means IsTradeAllowed is potentially wrong too , sometimes . Does it poll the broker's server with each request (because i can request dates from the past , paired with sessions not being updated for holidays , and the fact i got false for a trading holiday ) ?  

You should know by now, that everything and anything by MetaQuotes, sometimes works, sometimes not.

In some ways, the MQL4 "IsTradeAllowed" function is more practical that the MQL5 "SymbolInfoSessionTrade" function, and in other ways it is worse. Neither method is 100% and are both very lacking for practical use.

 
Fernando Carreiro #:

You should know by now, that everything and anything by MetaQuotes, sometimes works, sometimes not.

In some ways, the MQL4 "IsTradeAllowed" function is more practical that the MQL5 "SymbolInfoSessionTrade" function, and in other ways it is worse. Neither method is 100% and are both very lacking for practical use.

Maybe this one depends on what the broker provides though . I mean there was a thread the other day about Exness not returning margins required , so yeah maybe not everything is their fault .I guess there are parts in the contracts that they had to be lenient with brokers to get the deals through . 

< Dear mods , it would be very nice when you move threads to inform the OP by PM .I know how to look around and find it ,but someone not familiar with the forum may assume other things and leave. Unless you factored that in and did not PM me in which case i apologize .  Happy new year :) >

Reason: