Previous trade lot size.

 
I'm trying to double the previous trade lotsize if the last trade was negative in the following code :
double last_lot;
double lotSize = AccountBalance() * percentage / (StopLossPips * MarketInfo(Symbol(), MODE_TICKVALUE));
int total_orders = OrdersHistoryTotal();
int loss_trades_count = 0;

for (int i = total_orders - 1; i >= total_orders - Losses; i--)
{
  if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
  {
    if (OrderMagicNumber() == MagicNumber) // Check magic number
    {
      if (OrderProfit() < 0)
      { 
        loss_trades_count++;
      }
    }
  }
}

if (loss_trades_count >= Losses) 
{ 
  int last_trade_ticket = OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
  last_lot =OrderLots();
  lotSize = last_lot * 2;
}


Unfortunately the trades still used the first declaration of the lotsize although loss_trades_count>losses (condition is met) .

 
nidalzd: I'm trying to double the previous trade lotsize if the last trade was negative in the following code :
  1. Hedging, grid trading, same as Martingale.
              Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)

    Martingale, guaranteed to blow your account eventually. If your strategy is not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)

    Why it won't work:
              Calculate Loss from Lot Pips - MQL5 programming forum (2017)
              THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020)

  2. Your code processes all history orders, it is not processing just the last order.

    1. Do not assume history has only closed orders.
                OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017)

    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)
                Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)

    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 (2017)

      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.)