
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.
There is a bug in the implementation of this function.
Here is the corrected version:
?
I still get 2024.01.04 00:42:43 failed buy limit 0.15 XAUUSD.PRO_xx3b at 2039.41 [Market closed]
Granted I didn't check this on a live (demo) account, only in the strategy tester. Does this function work in the strategy tester?
2024.01.04 it's a Thursday.
in my tester I have :
Just checking, any input appreciated @Dominik Egert
I found this thread while I was on the search for almost the same issue. But I mostly wanted something to confirm that my code below will do as I want it to. If anyone can read my code and tell me that I am bonkers or if "great minds think alike". please.
My goal is...
1. to make my ea to "return" when the day changes, and also the minute is 1 or 2;
2. Each day, i want my ea to "return" when the hour is 23, and also, the minute is 57, 58, 59.
Here's my code... (my fingers are crossed, and face is grimacing, ready to take the flack)
Note my code is below OnTick; first lines in the OnTick.
If it is wrong, please explain why or give sources for me to read. I'd rather teach myself than to simply copy and paste.