How can I calculate daily P/L?

 

Hello,


Can you help me finding a formula to calculate daily p/l on mt4? Variables are:

1. Opening equity and closing equity

2. Deposits and withdrawals

3. credit in and credit out


thank you 

 

A formula or code ? (building an equity chart eh?)

Generally you go through history trades (and operations) as far back as the oldest trade open time which is still open or closed in that day.(the day you are calculating P/L for).

Now for the open trades :

You can calculate floating P/L at that moment and register it if you are on the PL calculation day ,or
check its P/L at the start of the day and how that has fluctuated.
In the second case you will get additional headaches such as when swaps were applied ,commisions etc.

Furthermore if the order has been partially closed you would need to discover the originating trade.

for the active day : 

  • get the current equity from the terminal
  • subtract all closes that occured in the day
  • subtract all deposits made in the day
  • add all withdrawals
  • go to the start of the day for open trades and check their PL at that point , subtract that too
  • go to all open trades and for trades that opened in the day add the commision and subtract their PL

You now have an estimate of the start of day equity