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

 
William Roeder #:

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

Hmmm... Thanks Willian.  At least a couple of interesting libraries there.  Although for relatively simple tasks (which I think this one should be...?) I prefer to roll my own... if I've at least understood what's required correctly for this (per my response to Fernando above)...?

 
Detnator #: 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? 😉). 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? 

That is quite a bit to read and answer, so I will just summarise.

Yes, the deals are the "things" that affect everything to do with the money in your account (profit or loss, commission, swap costs, and fees), regarding your actual trading activity.

However, deals are not just related to the actual trading orders. There are also other activities that affect your balance, such as deposits, withdrawals, additional charges or bonuses, interest, dividends, commissions calculated separately from individual trades, etcetera. All these things are still reflected in the "deals" history but have a different Deal Type (ENUM_DEAL_TYPE).

So, in essence you only need to analyse the Deal History to calculate your Balance over time but you need to consider all the data, not just the trading ones.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Deal Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

That is quite a bit to read and answer, so I will just summarise.

Yes, the deals are the "things" that affect everything to do with the money in your account (profit or loss, commission, swap costs, and fees), regarding your actual trading activity.

However, deals are not just related to the actual trading orders. There are also other activities that affect your balance, such as deposits, withdrawals, additional charges or bonuses, interest, dividends, commissions calculated separately from individual trades, etcetera. All these things are still reflected in the "deals" history but have a different Deal Type (ENUM_DEAL_TYPE).

So, in essence you only need to analyse the Deal History to calculate your Balance over time but you need to consider all the data, not just the trading ones.

Ok.  I'm pretty sure all that makes sense. Thank you so much.

I'll review all that and try it out, and I'll come back if there's anything else I'm confused about, but it sounds like you've covered everything.  Thank you again!

Reason: