Converted an MT4 to MT5 indicator, but some of the accounting definitions don't work

 

Hi,


I need a little help and other eyes.

I have converted an MT4 indicator to MT5, which only displays info  eg. account balances, profits % and a few other things.

I got most to work but the calculation of the profit and commission is not working, no error, just not picking up the figures.

this is the main section for the profit calc.  any help would be gratefully appreciated.

void DrawCurrentTrades() {
//+------------------------------------------------------------------+
      double buyCount=0, sellCount = 0;
       
      double buyProfit, sellProfit, buyLot, sellLot, buyPip, sellPip = 0;
      double slPip, tpPip;
      double allTPPips, allSLPips = 0;
      double maxLoss, maxProfit = 0;
      color c = White;
      string text = "";
      int colWidth1 = 200;
   
      for (int i = OrdersTotal_MQL4(); i >= 0; i--)
       
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if ( IsValidOrder() ) 
              
            {
        
               slPip = 0;
               tpPip = 0;
               if (OrderType() == OP_BUY) {
                  buyCount++;
                  buyProfit += OrderProfit() + OrderSwap() + OrderCommission();
                  buyLot += OrderLots();
                  buyPip += point2pip(MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice(), OrderSymbol());
   
                  if (OrderStopLoss() > 0.0) slPip = point2pip(OrderOpenPrice() - OrderStopLoss(), OrderSymbol());
                  if (OrderTakeProfit() > 0.0) tpPip = point2pip(OrderTakeProfit() - OrderOpenPrice(), OrderSymbol());
                     
               } else if (OrderType() == OP_SELL) {
                  sellCount++;
                  sellProfit += OrderProfit() + OrderSwap() + OrderCommission();
                  sellLot += OrderLots();
                  sellPip += point2pip(OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_BID), OrderSymbol());
   
                  if (OrderStopLoss() > 0.0) slPip = point2pip(OrderStopLoss() - OrderOpenPrice(), OrderSymbol());
                  if (OrderTakeProfit() > 0.0) tpPip = point2pip(OrderOpenPrice() - OrderTakeProfit(), OrderSymbol());
               }         
               if (slPip != 0) {
                  maxLoss -= pip2money(slPip, OrderLots(), OrderSymbol());
                  allSLPips -= slPip;
   
               }
               
               if (tpPip != 0) {
                  maxProfit += pip2money(tpPip, OrderLots(), OrderSymbol()) + OrderSwap() + OrderCommission();
                  allTPPips += tpPip;
               }
    //            DrawText(0, 30, 20, "OrderTotals = "+ OrdersTotal(), White, FontSize);       
         }
 

in MT5 the history of the trading deals with Deals, Orders and Positions, see here: https://www.mql5.com/en/docs/trading/historyselect.

There is an example script for deals. You can use it as a template.

BTW here is the list of all functions and you can easily search for keywords with ctrl+f: https://www.mql5.com/en/docs/function_indices

Documentation on MQL5: Trade Functions / HistorySelect
Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
HistorySelect - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Carl Schreiber #:

in MT5 the history of the trading deals with Deals, Orders and Positions, see here: https://www.mql5.com/en/docs/trading/historyselect.

There is an example script for deals. You can use it as a template.

BTW here is the list of all functions and you can easily search for keywords with ctrl+f: https://www.mql5.com/en/docs/function_indices

Thanks
I'll give that a go and let you know.