Hey everyone,
I'm trying to create an entry rule for my EA that prevents trading if my account equity goes under as an example 3% of my starting daily equity.
I understand how to code everything EXCEPT how to store my AccountEquity() in a variable at a certain point in time.
Here's the code I wanted to use:
If(Hour() == 0 && Minute() == 0)
{
StartingDailyEquity = AccountEquity();
}
But using this code once StartingDailyEquity becomes = to AccountEquity() it changes during the whole day.
Any help would be appreciated. Thanks!
-
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019) -
You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
MT4: New candle - MQL4 programming forum #3 (2014)
MT5: Accessing variables - MQL4 programming forum #3 (2022)I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011)
Hey everyone,
I'm trying to create an entry rule for my EA that prevents trading if my account equity goes under as an example 3% of my starting daily equity.
I understand how to code everything EXCEPT how to store my AccountEquity() in a variable at a certain point in time.
Here's the code I wanted to use:
If(Hour() == 0 && Minute() == 0)
{
StartingDailyEquity = AccountEquity();
}
But using this code once StartingDailyEquity becomes = to AccountEquity() it changes during the whole day.
Any help would be appreciated. Thanks!
There is more than one solution. The most reliable one can be as follows: You can calculate the daily gain and loss amount and add this amount to the current equity.
Of course, the current profit and loss is within the current equity!
I mean, the daily profit and loss sum; If we subtract it from balance if it is positive, or if we add it to balance if it is negative, we find the accıunt balance at the beginning of the day.
Hey everyone,
Thanks for the inputs on my current problem. I do however have difficulty understanding how to store AccountEquity() in a variable.
Here's my thought process, tell me if I'm wrong:
if @ 12 AM X = AccountEquity()
Then
@ 1 pm X is still = AccountEquity()
& @ 2 pm X is still = AccountEquity()
BUT, @ 1 pm I want the value of AccountEquity() @ 12 am not the new value of accountyEquity().
AccountEquity() updates constantly right, what I want is to store it's value at a place in time to where it won't change as time goes on.
How would I go about that?
Thanks!
Of course, the current profit and loss is within the current equity!
I mean, the daily profit and loss sum; If we subtract it from balance if it is positive, or if we add it to balance if it is negative, we find the accıunt balance at the beginning of the day.
I would of found it easier to store the value of AccountEquity() but I guess that will work, thanks a lot!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey everyone,
I'm trying to create an entry rule for my EA that prevents trading if my account equity goes under as an example 3% of my starting daily equity.
I understand how to code everything EXCEPT how to store my AccountEquity() in a variable at a certain point in time.
Here's the code I wanted to use:
If(Hour() == 0 && Minute() == 0)
{
StartingDailyEquity = AccountEquity();
}
But using this code once StartingDailyEquity becomes = to AccountEquity() it changes during the whole day.
Any help would be appreciated. Thanks!