How to retrieve my equity balance

 

Dear friends/comrades,

I have the following line of code to show my equity balance at the present moment (live). But I would like to have the equity balance from point of time in the past (example: yesterday's close). How can I get the equity balance with a parameter such as a date and time ?

    Comment("Equity: ",AccountInfoDouble(ACCOUNT_EQUITY))
 
douglas14:

Dear friends/comrades,

I have the following line of code to show my equity balance at the present moment (live). But I would like to have the equity balance from point of time in the past (example: yesterday's close). How can I get the equity balance with a parameter such as a date and time ?

Do you want to capture it in real-time and re-use it later, or are you saying you want to derive what it was at a prior datetime?

 
douglas14:

Dear friends/comrades,

I have the following line of code to show my equity balance at the present moment (live). But I would like to have the equity balance from point of time in the past (example: yesterday's close). How can I get the equity balance with a parameter such as a date and time ?

You have to understand the difference between balance and equity (balance +/- open positions) and - why not - the meaning of the margin.

The historical balances are not recorded by the terminal, so you have to take the actual balance and loop through all deals and subtract amounts that increase the balance and add amounts that reduced the balance from now back to the moment you'd like to know.

 
Carl Schreiber #:

You have to understand the difference between balance and equity (balance +/- open positions) and - why not - the meaning of the margin.

The historical balances are not recorded by the terminal, so you have to take the actual balance and loop through all deals and subtract amounts that increase the balance and add amounts that reduced the balance from now back to the moment you'd like to know.

Yes, exactly why I wanted to know what the OP was after.

Nevertheless if they are after historic balance, there is some code here which may help - not sure if it can be modified for equity... have not tried

https://www.mql5.com/en/forum/302805/page2#comment_23774890

accoount balance history - How can I read the account balance of your last 10 trades?
accoount balance history - How can I read the account balance of your last 10 trades?
  • 2019.02.17
  • www.mql5.com
Something like that for open the trades: ones you have x trades, ex: 10 trades opened and closed, and stored in history automatically, use this script to read the history, and the accountbalance() when the trade were opened: index, it depends on second parameter. This code will print the  account balance of your last 10 trades
 
douglas14: But I would like to have the equity balance from point of time in the past (example: yesterday's close).

Capture it when you will need it, or compute it. Balance(at time t) equals Balance(now) minus all closed orders profits(from t to now).

MT5:
          Retrieving History Positions - General - MQL5 programming forum #3 (2020)

MT4:

  1. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017)

  2. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)

  3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
              "balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017)

    Broker History
    FXCM
    Commission - <TICKET>
    Rollover - <TICKET>

    >R/O - 1,000 EUR/USD @0.52

    #<ticket>  N/A
    OANDA
    Balance update
    Financing (Swap: One entry for all open orders.)

Reason: