Query Account Balance at some point in the past (eg. yesterday 5pm EST)

 

Hi all. 

I'm aware I can query the current account balance of course.

I'm aware I can query historical data for bars, deals, and orders (for information at some point in the past).

Is there any way to query what the account balance was at some point in the past.  eg. if I need to know what the account balance of my account was at 5pm EST yesterday (or whatever), is there any way to do that?  

Or... is the only way I can know what the account balance was at 5pm yesterday is if I did the query at that time, and stored it somewhere?

Thanks!

 
Detnator: I'm aware I can query the current account balance of course. I'm aware I can query historical data for bars, deals, and orders (for information at some point in the past). Is there any way to query what the account balance was at some point in the past.  eg. if I need to know what the account balance of my account was at 5pm EST yesterday (or whatever), is there any way to do that?  Or... is the only way I can know what the account balance was at 5pm yesterday is if I did the query at that time, and stored it somewhere?

You have to either store the value or calculate it working backwards using the current balance and the trade history.

 
Fernando Carreiro #:

You have to either store the value or calculate it working backwards using the current balance and the trade history.

Ok.  Makes sense.  Thanks!

 
What about using services which analyse the trade history, like the signal services MQL5 offers, they can even calculate drawdown?
 
Mohammad Hossein Sadeghi # :
What about using services which analyse the trade history, like the signal services MQL5 offers, they can even calculate drawdown?

If the signal is publicly available in the Signals service, then you can use the following commands: Signal Properties

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Signal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Signal Properties
  • www.mql5.com
Signal Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mohammad Hossein Sadeghi #:
What about using services which analyse the trade history, like the signal services MQL5 offers, they can even calculate drawdown?

Hi! thanks for the suggestion. Drawdown is exactly one of the reasons for this question. Although I'm sorry I think I don't understand.

The signals service says "Signals is a copy-trading service allowing you to automatically copy provider's deals on your trading account."

I'm building my own EA, meaning of course I'm generating my own trades.  Please correct me if I'm wrong, but I'm pretty sure copy-trading is something else entirely...?

Is there something in the signals services that can calculate drawdown, or help me calculate account balance at a previous time, or etc. for my own EA?

Thanks!

 
Detnator #:

Hi! thanks for the suggestion. Drawdown is exactly one of the reasons for this question. Although I'm sorry I think I don't understand.

....

Hi, it is a copy trading service. You can be a provider and your trades as signal can be private and paid. Usually copy trading services provide statistics of trading performance, this include balance growth and drawdown and many more useful factors.
And as Vladimir says, if you make it public you can get some properties through code.
 
Detnator #: Hi! thanks for the suggestion. Drawdown is exactly one of the reasons for this question. Although I'm sorry I think I don't understand. The signals service says "Signals is a copy-trading service allowing you to automatically copy provider's deals on your trading account." I'm building my own EA, meaning of course I'm generating my own trades.  Please correct me if I'm wrong, but I'm pretty sure copy-trading is something else entirely...? Is there something in the signals services that can calculate drawdown, or help me calculate account balance at a previous time, or etc. for my own EA? Thanks!

Signals can also be used privately just for tracking the trading statistics, and not necessarily just for Copy-Trading.

However, my opinion is contrary to that of Vladimir and Mohammad, and that is that an EA should be self contained and not have to depend on external calculations and setup of a Signal.

My advice, is calculate the balance (or any other metric) based off the trade history, because you never know how you will use the EA and on which account, and you can't always have to create a signal just to calculate the balance or whatever other metrics you wish to track.

 
Fernando Carreiro #: calculate it working backwards using the current balance and the trade history.

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

 
Fernando Carreiro #:

Signals can also be used privately just for tracking the trading statistics, and not necessarily just for Copy-Trading.

However, my opinion is contrary to that of Vladimir and Mohammad, and that is that an EA should be self contained and not have to depend on external calculations and setup of a Signal.

My advice, is calculate the balance (or any other metric) based off the trade history, because you never know how you will use the EA and on which account, and you can't always have to create a signal just to calculate the balance or whatever other metrics you wish to track.

Hi Fernando. Your advice makes sense. Would it be ok if you (or anyone else) could clarify/confirm the following please?

I've had some difficulty understanding history, partly because I've had difficulty understanding the differences between Order, Deal, Position, and Trade.  I think I've figured it out (though I've just posted another rather lengthy and comprehensive question about that, so no need to go into that here). Other than...

Briefly, my understanding of a Deal is it's a single event -- the fulfillment or execution of a (successful) Order.  The order might be an instruction/request to take one action: open a trade, adjust a stop loss on an existing trade, add volume to a trade, close a trade, or other things.  An order requests one of these events, the deal executes it and makes it happen (if it can, otherwise the order is rejected). At least that's my understanding.  Is this basically correct?

If this is correct, then it seems the Deal history is the thing I need for calculating a past account balance -- the Deals are the only things that involve money adding to or subtracting from the account balance.  Is this correct?

And then finally, does MT5's deal history only record the actual trade information (by which I mean just the buy and sell prices I think), or does it accurately record EVERY factor that affects account balance (including commissions, swap fees, everything else)?  I would assume the latter, but would be grateful for someone who knows for sure to confirm (or point me to documentation that spells it out clearly if need be).

(I'm hoping the answer to all that is simply:  "yes, that's all correct: (1) yes that's what a deal is (or close enough), (2) yes, deal history is the only history I need to consider for this, and (3) Yes, every factor affecting account balance is included in each deal." Any chance? 😉)

Thanks again!


Update, 10 minutes later:  I was looking in the wrong place. If the first two parts of the above are correct,  then it seems this:

https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties#enum_deal_property_double 

answers the third part, or at least mostly. It shows that for any deal I can get a lot of info.  

It seems what I need to do is, for each deal as I'm walking back in time, calculate:

(profit - (commission + swap + fee)) 

and adjust the account balance by the result of that.  Is that correct?  Or  (other than manual top ups and withdrawals) are there any other factors that could affect account balance not included there? 
Order vs Deal vs Position vs TRADE (yes, again -- but more than past answers).
Order vs Deal vs Position vs TRADE (yes, again -- but more than past answers).
  • 2022.03.23
  • www.mql5.com
Hi all. Thanks for all the help so far with a few questions I've posted recently. Here's another. Well, a bunch of related ones...
 
Vladimir Karputov and Mohammad Hossein Sadeghi, it seems Fernando's advise is the way to go.  But I do appreciate your input. Thank you.
Reason: