![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear Coders!
I started a backtest. My expert advisor is trying to open a position immediately at time 00:00. I get 'Market is closed' (TRADE_RETCODE_MARKET_CLOSED, error code: 10018) message, because the trading is start only at time 00:01:
How can I check in advance if it is possible to open a position?
I tried unsuccessfully with this code:Please help me, how can I check the allowed trading periods.
Thank you in advance.
Zsolt
Try the below code, currently in script, but easy enough to incorporate in an EA.
Also I assume you use some sort of version of the IsNewBar function, this market open I beliwve needs to be incorporated to the IsNewBar function
Thank you.
Here is my function to solve the issue:
There is a bug in the implementation of this function.
Here is the corrected version:
There is a bug in the implementation of this function.
Here is the corrected version:
Many thanks, Dominik! As always, very much appreciated.
Thanks.
Your code should verify the trade session times using SymbolInfoSessionTrade(), as trading will not be disabled, just temporarily closed:
You also might sometimes want to avoid leaving a trade open after the market closes (especially if it's in a loss and not a "smart" trade). I made a function which will close any trade that's in a certain loss just before the market would close.