Hi there, any one can help with a well detailed code to calculate total profit and loss including swap and commission. Help will be much appreciated.
//+------------------------------------------------------------------+ //| Calculate proftis and losses of the day | //+------------------------------------------------------------------+ double PnL() { HistorySelect(TimeCurrent() - PERIOD_D1, TimeCurrent()); double PnL = 0; for(int i = 0; i < HistoryDealsTotal(); i++) { if(HistoryDealGetTicket(i) > 0) { if(HistoryDealGetInteger(HistoryDealGetTicket(i), DEAL_ENTRY) == DEAL_ENTRY_OUT) { PnL += HistoryDealGetDouble(HistoryDealGetTicket(i), DEAL_PROFIT); } } } return (PnL); }
Carl Emil Bograd #:
//+------------------------------------------------------------------+ //| Calculate proftis and losses of the day | //+------------------------------------------------------------------+ double PnL() { HistorySelect(TimeCurrent() - PERIOD_D1, TimeCurrent());
Current time minus a few seconds is nonsense.
-
If you want the last twenty-four (24) hours, you need:
HistorySelect(TimeCurrent() - PeriodSeconds(PERIOD_D1), TimeCurrent());
-
If you want the current day, you need:
HistorySelect(date(), TimeCurrent());
Find bar of the same time one day ago - MQL4 programming forum #1 & #6
William Roeder #:
Current time minus a few seconds is nonsense.
-
If you want the last twenty-four (24) hours, you need:
-
If you want the current day, you need:
Find bar of the same time one day ago - MQL4 programming forum #1 & #6
Oh yeah, right! My bad, thanks for pointing that out. Wrote it in a jif.
How about just:HistorySelect(iTime(Symbol(), PERIOD_D1, 0), TimeCurrent());Would return the actual current date PnL.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register