Calculate previous month's profit
This could be because there is a commission in entry deals also.
//--- double GetProfit() { double profit = 0; //--- int timeDay = 24 * 60 * 60; datetime startMonth = iTime(_Symbol, PERIOD_MN1, 1); datetime endMonth = iTime(_Symbol, PERIOD_MN1, 0) - timeDay; if(HistorySelect(startMonth, endMonth)) { int total = HistoryDealsTotal(); for(int i = 0; i < total; i++) { ulong dealTicket = HistoryDealGetTicket(i); if(HistoryDealGetInteger(dealTicket, DEAL_ENTRY) == DEAL_ENTRY_OUT) { datetime dealTime = datetime(HistoryDealGetInteger(dealTicket, DEAL_TIME)); if(dealTime >= startMonth && dealTime <= endMonth) { double dealProfit = HistoryDealGetDouble(dealTicket, DEAL_PROFIT); double dealCommission = HistoryDealGetDouble(dealTicket, DEAL_COMMISSION); double dealSwap = HistoryDealGetDouble(dealTicket, DEAL_SWAP); profit += dealProfit + dealSwap + dealCommission; } } if(HistoryDealGetInteger(dealTicket, DEAL_ENTRY) == DEAL_ENTRY_IN) { datetime dealTime = datetime(HistoryDealGetInteger(dealTicket, DEAL_TIME)); if(dealTime >= startMonth && dealTime <= endMonth) { double dealCommission = HistoryDealGetDouble(dealTicket, DEAL_COMMISSION); profit += dealCommission; } } } } return profit; }
Hello everybody.
I developed the code below to return last month's profits. For some reason beyond my knowledge, the returned value is different from the MT5 one.
Could someone tell me where I'm going wrong?