How do I get my martingale code to set the next profit at the same size as the last point loss and keep doing it until it reaches a takeProf?

 
I tried several ways, using if (LastAccountBalance <AccountBalance ())
{do something}.
But I couldn't do it at all ...

I already have the EA, which I coded myself, I just want to know how or what I would use so that if the last order is Loss the next order will set the TakeProf the same amount of last Loss IN POINTS, and in case another Loss, to continue adding the Losses and using them as take points, until an order reach a TakeProf, so it goes back to the initial Take, which is already coded.
Would this be too complicated? Where would I start from? ... Could someone help me?
 
Karolina Nascimento:
I tried several ways, using if (LastAccountBalance <AccountBalance ())
{do something}.
But I couldn't do it at all ...

I already have the EA, which I coded myself, I just want to know how or what I would use so that if the last order is Loss the next order will set the TakeProf the same amount of last Loss IN POINTS, and in case another Loss, to continue adding the Losses and using them as take points, until an order reach a TakeProf, so it goes back to the initial Take, which is already coded.
Would this be too complicated? Where would I start from? ... Could someone help me?
   input double inital_lot=0.1;
   double lot()
     {

      double lot=initial_lot;// set the inital lot size

      bool etape1=false;//bool for check profitable historic trade

      for(int i=OrdersHistoryTotal()-1; i>=0; i--)
        {
         if(etape1==true)
            continue;
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
           {
            if(OrderProfit()<=0 && etape1==false)
              {

               lot=lot+OrderLots();
              }
            if(OrderProfit()>0)
              {
               etape1=true;
              }
           }
        }


      return(lot);
     }
Reason: