Copy OrderProfit() to an array in sequence

 

Hello,

I'm trying to copy OrderProfit() to an array, but only the last OrderProfit() value is populating the indexes. I'd like to get, for example the last five values of the OrderProfit(). Here is my code:

double array[5];
   for(int i = 0; i <= OrdersHistoryTotal()-1; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true)
         if(Symbol() == _Symbol)
            if(OrderMagicNumber() == MagicNumber)
               if(OrderType() == OP_SELL)
		ProfitData = DoubleToString(OrderProfit(), 2);
                ArrayFill(array, 0, 4 , ProfitData);
    }
 
  1. Only the last value is populated because that is what ArrayFill does. Why does that supprise you?
    1. Do not assume history has only closed orders.
                OrderType() == 6, 7 in the history pool? - MQL4 programming forum 2017.11.30

    2. Do not assume history is ordered by date, it's not.
                Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum 2012.04.21
                Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 2020.06.08

    3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
                "balance" orders in account history - Day Trading Techniques - MQL4 programming forum

      Broker History
      FXCM
      Commission - <TICKET>
      Rollover - <TICKET>

      >R/O - 1,000 EUR/USD @0.52

      #<ticket>  N/A
      OANDA
      Balance update
      Financing (Swap: One entry for all open orders.)