Storing AccountEquity() Value in variable during a certain time that DOESN'T CHANGE

Gabriel Bérard  

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!

Michalis Phylactou  
Gabriel Bérard:

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!

Search for Global Variables 
William Roeder  
Mohammed Abdulwadud Soubra #: if(iVolume(_Symbol,PERIOD_D1,0)==1)
  1. 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)

  2. 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)

Ahmet Metin Yilmaz  
Gabriel Bérard :

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.

William Roeder  
Ahmet Metin Yilmaz #: 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.

Wrong. The current gain and loss is already in the current equity.

Ahmet Metin Yilmaz  
William Roeder # :

Wrong. The current gain and loss is already in 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.

Gabriel Bérard  

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!

Gabriel Bérard  
Ahmet Metin Yilmaz #:

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.

Oh, so you're saying that I can find the Account Equity value at the beginning of the day using order history to get the sum of profits for all trades taken during the day. That way I can use my beginning account balance value and the sum of PNL for the day to find where I am at?

I would of found it easier to store the value of AccountEquity() but I guess that will work, thanks a lot!
William Roeder  
Gabriel Bérard #:
Oh, so you're saying that I can find the Account Equity value at the beginning of the day using order history t
I would of found it easier to store the value of AccountEquity()
  1. Yes.
  2. So why don't you?