Two ways to show a profit show different results

 

I have written a method for close the position


   bool ClosePosition_real(int currentMagic, double &_profit)
   {
      MqlTradeRequest tradeRequestClose;
      MqlTradeResult tradeResultClose;
      int total=PositionsTotal(); // number of open positions   
            
      for(int i=total-1; i>=0; i--)
      {
         ulong  position_ticket=PositionGetTicket(i);                                      // ticket of the position
         string position_symbol=PositionGetString(POSITION_SYMBOL);                        // symbol 
         ulong  magic=PositionGetInteger(POSITION_MAGIC);                                  // MagicNumber of the position
         int    digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);                       // number of decimal places
         double volume=PositionGetDouble(POSITION_VOLUME);                                 // volume of the position
         ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);    // type of the position
         
         if(magic==currentMagic)
         { 
            ZeroMemory(tradeRequestClose);
            ZeroMemory(tradeResultClose);

            tradeRequestClose.action   =TRADE_ACTION_DEAL;        // type of trade operation
            tradeRequestClose.position =position_ticket;          // ticket of the position
            tradeRequestClose.symbol   =position_symbol;          // symbol 
            tradeRequestClose.volume   =volume;                   // volume of the position
            tradeRequestClose.deviation=tradeRequest.deviation;   // allowed deviation from the price
            tradeRequestClose.magic    = currentMagic;       // MagicNumber of the position

            if(type==POSITION_TYPE_BUY)
            {
               tradeRequestClose.price=SymbolInfoDouble(position_symbol,SYMBOL_BID);
               tradeRequestClose.type =ORDER_TYPE_SELL;
            }
            else
            {
               tradeRequestClose.price=SymbolInfoDouble(position_symbol,SYMBOL_ASK);
               tradeRequestClose.type =ORDER_TYPE_BUY;
            }

            _profit = NormalizeDouble(PositionGetDouble(POSITION_PROFIT), __digits);
            
            double __debugVal;
            OrderCalcProfit(tradeRequestClose.type, symbol, volume, tradeRequestClose.price, currentDealPrice, __debugVal);
            __debugVal = NormalizeDouble(__debugVal, __digits);

            if(OrderSend(tradeRequestClose,tradeResultClose))
            {
               return true;
            }
            else
            {
               PrintFormat("OrderSend error %d",GetLastError());  // if unable to send the request, output the error code
               return false;
            }
         }
      }
      return false;
   }

The first way for viewing profits is the PositionGetDouble function that gives me the 16.6999 number and the second one is the OrderCalcProfit function that gives me 16.7199 number.

So the results are different, but I expect the same result because there are identical input data.

Can you explain to me why the results are different? How to fix it?

Look at the attached file:

Files:
diff.jpg  307 kb