MQL5 Profit calculation (points?)

 
Hi together,

I (think I) read alot about how to calculate profits and loss of open tickets/deals.
In some MQL4/5 talks there so many different opinions and guesses. Im really confused now what is the way or the best way to calculate PnL for the open tickets/deals.
The last thing I read that should work good and correctly is following:

bool  OrderCalcProfit(
ENUM_ORDER_TYPE       action,           // type of the order (ORDER_TYPE_BUY or ORDER_TYPE_SELL)
string                symbol,           // symbol name
double                volume,           // volume
double                price_open,       // open price
double                price_close,      // close price
double&               profit            // variable for obtaining the profit value
);

In snippet.txt you can see my (actual) function

void calcit2(string msymbol)
{
   if(m_position.Select(msymbol)) { // select the position for further work
      double profit=m_position.Profit();
      //--- request trade history
      if(!HistorySelectByPosition(m_position.Identifier())) {
         Print("Error HistorySelectByPosition");
         return;
      }
      //---
      uint history_deals_total=HistoryDealsTotal();
      double price_in=0.0;
      long time_in=TimeCurrent()+3600*24*3;
      int decimals = SymbolInfoInteger(msymbol, SYMBOL_DIGITS); // Anzahl der Dezimalstellen für das Symbol
      double pointValue = SymbolInfoDouble(msymbol, SYMBOL_POINT); // Kurswert in Points
      //--- for all deals
      for(uint i=0; i<history_deals_total; i++) {
         ulong ticket=HistoryDealGetTicket(i);
         if(ticket) {
            profit+=HistoryDealGetDouble(ticket,DEAL_COMMISSION)+HistoryDealGetDouble(ticket,DEAL_SWAP)+HistoryDealGetDouble(ticket,DEAL_PROFIT);
            if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_IN) {
               long deal_time=HistoryDealGetInteger(ticket,DEAL_TIME);
               double deal_price=HistoryDealGetDouble(ticket,DEAL_PRICE);
               if(deal_time<time_in) {
                  time_in=deal_time;
                  price_in=deal_price;
               }
            }
         }
      }
      if(price_in>0.0) {
         double price_diff=MathAbs(m_position.PriceCurrent()-price_in);
         int points_profit=(int)(price_diff/pointValue);
         PrintFormat("position Ticket %d, position ID %d, profit %.2f, points profit %d, symbol %s: ",
                     m_position.Ticket(),m_position.Identifier(),profit,points_profit, msymbol);
      }
   }
}

void OnTick()
{
   // Check for New Bar
   if (!IsNewBar()) return;

   // Candles
   MqlRates rates[];
   ArraySetAsSeries(rates, true);
   int copied = CopyRates(Symbol(), 0, 0, 10, rates);

   if (copied != 10) {
      Print("Failed to get history data for the symbol ", Symbol());
      return;
   }

   for (int i = 0; i < ArraySize(symbols); i++) {
      calcit2(symbols[i]);
   }

   Print("");
   Print("");
   Print("");

   for (int i = 0; i < ArraySize(symbols); i++) {
      tradefunction(symbols[i]);
   }
}
And here all my question to this and why I'm confused:

Is still don't really understand why there is no function that shows me 1:1 the same as the StrategyTester GUI. As we can see in the picture, the output from the function and the GUI are completely different. And for me GUI PnL looks correct.
What is now the best and optimum way to calculate profits and loss? (I'm actually only want to trade Forex also JPY pairs and maybe later gold)
Is there no best way and I should work with € or $ for profits and loss as inputs?
What I'm doing wrong or what I'm missing here?
Is there a simple way to get PnL (correctly) and just read too much?
I like to work with points, that is (still) possible for PnL?
And when using OrderCalcProfit correctly, what does the term 'profit value' mean? In my case, would the correct 'profit value' be 200 points = 200, $5 = 5, or €5 = 5? I'm confused

Thanks in advance!
Chris

Documentation on MQL5: Trade Functions / OrderCalcProfit
Documentation on MQL5: Trade Functions / OrderCalcProfit
  • www.mql5.com
OrderCalcProfit - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Euro.jpg  241 kb
Points.jpg  235 kb
Print.jpg  94 kb