Realized Profit MT5

 

On MT5 I try to calculate the realized profit for a running EA by using Historyselect(0,TimeCurrent()),

loop through TotalNumberOfDeals=HistoryDealsTotal() and then query for each deal

OrderProfit=HistoryDealGetDouble(TicketNumber,DEAL_PROFIT) and add them to get a total.

This method has some issues and I wonder if there is some built-in function returning the total realized profit

for all deals (buy and sell) for a specific EA in a specific time frame.

Or to return realized profit since the EA was

activated.

On another point, the profit returned by HistoryDealGetDouble(TicketNumber,DEAL_PROFIT):

1) does not include fees, swaps so that must be included to get a total net profit.

2) Includes cash deposit balance, which must be substracted to the get a total net profit purely of trading operations.


Perhaps all the above has been resolved in some function or method I am missing.

Any advice very much appreciated.

 
  1. cmarconetti: On MT5 I try …

    Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and inive about your problem

    We can't see your broken code.

    Show us your “try.”

  2. cmarconetti: I wonder if there is some built-in function …

    Did you look and find any in the documentation?

    Are you too lazy to write the three lines of code to do the summation by following the example in Historyselect?

  3. cmarconetti: Or to return realized profit since the EA was activated.

    Did you remember in persistent storage (files, global variables w/flush) when you first activated the EA? Remembering the last OnInit will not work (chart change, terminal/OS restarts, etc.). Did your EA use a unique Magic Number since it was first activated?

  4. cmarconetti: On another point, the profit returned by HistoryDealGetDouble(TicketNumber,DEAL_PROFIT):

    1) does not include fees, swaps so that must be included to get a total net profit.

    2) Includes cash deposit balance, which must be substracted to the get a total net profit purely of trading operations.

    Perhaps you should read the manual. HistoryOrderGetDoubleENUM_DEAL_PROPERTY_DOUBLE → DEAL_FEE
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  5. What does deposits and withdraws have to do with a sum of profits?

 

What does deposits and withdraws have to do with a sum of profits?

Well, if you look at the History tab on the Tester, cash balance is an item in the Profit columns.(always MT5)

In fact if you query using HistoryDealGetDouble(TicketNumber,DEAL_PROFIT) that will also return cash

balances.

By the way, since you like educating so much for your own education a few tips:

it is not "withdraws" (withdraw is not a noun) but withdrawal.

I could go on about some of your other points (or rather darts) but not necessary. Thank you for the quick answer but not

for the arrogance.

 
cmarconetti #:

What does deposits and withdraws have to do with a sum of profits?

Well, if you look at the History tab on the Tester, cash balance is an item in the Profit columns.(always MT5)

Why would you process non-deals, or deals not generated with the EA's Magic Number? Everything else has nothing to do with sum of profits.