"Closed P/L in pips" funciton is working improperly

Hello folks,



I have identified that "Closed P/L in pips" function is not working properly. Please look at both functions below:


================  sqGetClosedPLInPips   ========================


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);
            return(sqConvertToPips(symbol, profit));
         }


         index++;
      }
   }


   return(0);




And now: 

============== sqConvertToPips  ===================================  


double sqConvertToPips(string symbol, double value) {
   if(symbol == "NULL" || symbol == "Current") {
      return(value / gPointCoef);
   }


   // recognize point coeficient         
   double ticksize = sqGetMarketTickSize(symbol);
   if(ticksize < 0){
      ticksize = calculatePointCoef(correctSymbol(symbol));
   }


   return(value / ticksize);
}


====================================================================




Value is the last trade PROFIT,  The function is only dividing PROFIT by gPointCoef  (by tick size). IT is not providing PROFIT in PIPS. It is only Profit Multiplier.


Proper PL in PIPS should result with the last Closed Order :  Abs(ClosePrice - OpenPrice).




I'm trying to implement automated position size reduction when the strategy is reaching specific Draw Dawn. It is hard to implement it when I don't have PL in PIPS, so it is very valuable feature.



BTW, did you thought about implementing it as a predefined function? Example: if you have 20 strategies in Portfolio and some of them reach  specific value of DD which should be the trigger for the strategy to be switched off, they could switch to reduce position size to minimum (i.e. 0.01 lot) and continue to work that way until DD comes back to normal.... Would be great to have such a feature.


Thank you, Piotr 



Attachments
No attachments
  • Votes +1
  • Project AlgoWizard
  • Type Bug
  • Status Fixed
  • Priority Normal

History

p
#1

pitro

15.09.2021 21:26

Task created

Dw
#2

Diwi

21.02.2022 18:56
Voted for this task.

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