Close positions at end of the day
-
Hi,
I would like to know how to close positions at the end of the day. The EA is designed to open orders at NY time and close all positions before the rollover time (between 00:00 and 01:00). However, I can’t find a way to specify this. Could you please help me?
Best regards,
-
Hi. Just use Once a day block, and put the closing time when to close, connect with Close trades block. That's all.
-
@pharmlatex Your logic is correct. You just need to remove the 'if trade' block and then use hour and minute details and not using seconds as you are doing now. I mean you need to use 23:00 instead of 23:00:00. Then it will work.
-
23:00:00 will work the same I use it all the time it is in the valid examples list (although with a date):

I would guess it is the ATR value, but maybe not remove blocks and test until you find the block that's causing the problem. -
Hi,
I appreciate all the advice. I have tried changing the "time filter" and "once a day" settings many times, but I still cannot solve the problem. The attached link contains the minimal structure of the EA. It opens positions and closes positions based on Indicators, but some positions are being closed the next day. I want to open and close positions within a day. Could you help me again?
Thank you!
-
Do these times coincide with your broker market open/close times?
-
@pharmlatex do you want to close when in profit, or just close all?
-
Hi,
Thank you for your reply. I try to close all positions within a day. I'm currently testing the EA using the MT4 strategy tester, and I believe the broker's GMT offset is not an issue.
Best regards,
-
@pharmlatex That should definitely close all your open trades within that time period. If it is not working is because a) other parts of the bot are conflicting it, or b) you are using incompatible time periods on your constants. Otherwise it should work.
-
Did you confirm your input time variable is the string data type ?