Close after certain amount of money profit
-
Hi, hope someone can help with this. I would like to have my EA record the balance at 09:00 in the morning (probably in a variable?). This should happen once. Then I want my EA to check the former balance with the current equity on tick. Once that equity is let's say 40$ higher, I want all trades to close and the EA to not trade anymore.
Anyone know how this would look like? The thing is, I don't really know how to write a variable...

Thanks in advance!
-
Would that work? https://fxdreema.com/shared/G9jiq7bKb
Also here a pic of the variable:

-
@sirluk You do not need a variable to do that. This is an inspitation for what you need:
https://fxdreema.com/shared/C5DLuktD
Yoy should substitute block 6 for a 'check profit(unrealized)' one instead. There you should select 40 as your daily target.
-
But this will only check the profits for that specific forex pair I'm running the EA on. I intend to run the same EA on multiple pairs...that's why I want to work with balance. I want to record the balance at the beginning of the day and once I'm up 40$ overall I want all trades to close.
How do I write a variable to record the momentary balance?
-
@l-andorrà Then I'll just run a condition comparing the balance of the balance in the variable recorded in the morning with the current balance adjusted by 40. I guess that will work? (See shared file)
-
@jstap any ideas?
-
@sirluk This is how I do similar stuff: https://fxdreema.com/shared/aUW1EMfDb
-
@jstap will that not only check the profits on the current pair? Will it check profits running on other pairs as well, where the EA is not running?
-
@sirluk That depends on how you have the settings, if you change to any symbol it will do all.
-
Thanks for the help everybody!
-
@sirluk @l-andorrà @jstap
I would like to comment on one detail...
All this will work in backtest, but I believe that in the real market, as soon as your metatrader restarts or your house light or vps forces the metatrader to restart the value obtained at the beginning of the day will be zero (0).
I think the ideal thing is for you to loop in search of the amount of gain or loss for the day and save this in a variable. Every time the EA is restarted no matter the reason it will loop and get the balance of the current day. -
Thank you for your input. Any idea how that would look like? Maybe you could show me how? If I have the account history set to today, won't that always show correctly no matter if I close Mt4 or not?
-
@sirluk believe these blocks will check your brokers history, same as what your MT4/5 does to show all results:
