Functions : sqGetClosedPLInMoney and sqGetClosedPLInPips returning PL of one order only

If we look to the MQL5 code of the function GetClosedPLInMoney and GetClosedPLInPips,



it will return the ProfitLoss of only one deal of the selected magic number, but it will not add up the ProfitLoss of all ANY magic number or ANY direction :


Why does it need to check out deals which have the opposite direction ? 




double sqGetClosedPLInMoney(string symbol, int magicNo, int direction, string comment, int shift) {    int index = 0;    HistorySelect(startTime, TimeCurrent());    for(int i=HistoryDealsTotal()-1; i>=0; i--) {       ulong ticket = HistoryDealGetTicket(i);       if(HistoryDealGetInteger(ticket, DEAL_ENTRY) != DEAL_ENTRY_OUT) continue;       if(dealFits(ticket, symbol, magicNo, direction * -1, comment)) {    //we need to check out deals which have the opposite direction          if(index == shift) {             return(HistoryDealGetDouble(ticket, DEAL_PROFIT));          }          index++;       }    }    return(0); } double sqGetClosedPLInPips(string symbol, int magicNo, int direction, string comment, int shift) {    int index = 0;    HistorySelect(startTime, TimeCurrent());    for(int i=HistoryDealsTotal()-1; i>=0; i--) {       ulong ticket = HistoryDealGetTicket(i);       if(HistoryDealGetInteger(ticket, DEAL_ENTRY) != DEAL_ENTRY_OUT) continue;     if(dealFits(ticket, symbol, magicNo, direction * -1, comment)) {     //we need to check out deals which have the opposite direction          if(index == shift) {           double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);             double volume = HistoryDealGetDouble(ticket, DEAL_VOLUME);             return profit/(SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE) * volume)/10;          }        index++;       }    }    return(0); }








Attachments
image-0.png
(40.05 KiB)
  • Votes +1
  • Project AlgoWizard
  • Type Bug
  • Status New
  • Priority Normal

History

E
#1

Emmanuel

20.09.2023 15:01

Task created

E
#2

Emmanuel

20.09.2023 15:01
Voted for this task.
E
#3

Emmanuel

20.09.2023 15:55

Description changed:

If we look to the MQL5 code of the function GetClosedPLInMoney and GetClosedPLInPips,



it will return the ProfitLoss of only one deal of the selected magic number, but it will not add up the ProfitLoss of all ANY magic number or ANY direction :


Why does it need to check out deals which have the opposite direction ? 




double sqGetClosedPLInMoney(string symbol, int magicNo, int direction, string comment, int shift) {    int index = 0;    HistorySelect(startTime, TimeCurrent());    for(int i=HistoryDealsTotal()-1; i>=0; i--) {       ulong ticket = HistoryDealGetTicket(i);       if(HistoryDealGetInteger(ticket, DEAL_ENTRY) != DEAL_ENTRY_OUT) continue;       if(dealFits(ticket, symbol, magicNo, direction * -1, comment)) {    //we need to check out deals which have the opposite direction          if(index == shift) {             return(HistoryDealGetDouble(ticket, DEAL_PROFIT));          }          index++;       }    }    return(0); } double sqGetClosedPLInPips(string symbol, int magicNo, int direction, string comment, int shift) {    int index = 0;    HistorySelect(startTime, TimeCurrent());    for(int i=HistoryDealsTotal()-1; i>=0; i--) {       ulong ticket = HistoryDealGetTicket(i);       if(HistoryDealGetInteger(ticket, DEAL_ENTRY) != DEAL_ENTRY_OUT) continue;     if(dealFits(ticket, symbol, magicNo, direction * -1, comment)) {     //we need to check out deals which have the opposite direction          if(index == shift) {           double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);             double volume = HistoryDealGetDouble(ticket, DEAL_VOLUME);             return profit/(SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE) * volume)/10;          }        index++;       }    }    return(0); }








E
#4

Emmanuel

20.09.2023 15:57

Subject changed from Functions : sqGetClosedPLInMoney and sqGetClosedPLInPips to Functions : sqGetClosedPLInMoney and sqGetClosedPLInPips returning PL of one order only


Votes: +1

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please