Lot and Take Profit Increase

 

Hello friends I have written a code in mql4 everything is right but I am unable to add the lot and tp increment function into the EA. I request anyone with the knowledge to assist me in writing the code of this ne function. Here is the logic of the function and also keep in mind after the trade hits tp after the losses it should reset and go back to original settings: 

Every time a multiple of "n_op" successive loss-making operations is reached, the EA increases both the lot and the TP. If e.g. n_op=5 and we have just closed the fourth trade at a loss, the fifth trade will have tp and lot as follows set Y = (number of subsequent losing operations +1) / n_op. When Y is an integer we apply the lot and TP change to the trade we are opening, holding and using the Y value as follows lot: lot_start + lot_incr x Y tp: opening quota + take_profit x take_profit_molt x Y

//+------------------------------------------------------------------+
//|                                                 Ml_Fiverr_V1.mq4 |
//|                                        Copyright 2023,Dev Ernest |
//|                                          ernestakoyi56@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023,Dev Ernest"
#property link      "ernestakoyi56@gmail.com"
#property version   "1.00"
#property strict


extern int magic_number = 1111;
extern int ticks_apertura = 100;
extern float lotto_inizio = 0.1;
extern float lotto_incr = 0.02;
extern int take_profit = 100;
extern float take_profit_molt = 1.5;//Take profit multiplier
extern int n_op = 4; // Successive loss operation
extern int stop_loss=1000;
//extern int periodo_media=10;

extern int                   ma_period         = 10; //Period
extern int                   ma_shift          = 0; //Shift
extern ENUM_MA_METHOD        ma_method         = MODE_SMA; //MA method
extern ENUM_APPLIED_PRICE    ma_price          = PRICE_CLOSE; //Apply to
bool starting=true;
int verso_aperture=0;
int posCounter=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   closeAllMarketPositions();
   posCounter=0;
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
  // double mm=iMA(Symbol(),Period(),periodo_media,0,0,0,0);
  double mm = iMA(Symbol(),0,ma_period,ma_shift,ma_method, ma_price,1);
   if(starting)
   {
      
      //definisce orientamento iniziale rispetto media
      closeAllMarketPositions();
      if(Bid < mm)
         verso_aperture = 1;
      else
         verso_aperture = -1;
      if(verso_aperture!=0)
         starting=false;
   }
   
   openIfNeeded();
   closeForTP();

}

void openIfNeeded()
{
 // double mm=iMA(Symbol(),Period(),periodo_media,0,0,0,0);
  double mm = iMA(Symbol(),0,ma_period,ma_shift,ma_method, ma_price,1);
  if(verso_aperture>0)
  {
    if(Bid < mm - ticks_apertura*Point)
    {
      if(countLongOpenOrders()==0)
      {
         closeAllMarketPositions();
         
         posCounter++;
         int opened=OrderSend(Symbol(),OP_BUY,calcLotto(),Ask,50,Ask-stop_loss*Point,0,""+posCounter,magic_number);
         if(opened>0)
         {

            verso_aperture=-1;
         }
         else
            posCounter--;
      }
    }
  
  }
  else if(verso_aperture<0)
  {
    if(Bid > mm + ticks_apertura * Point)
    {
      if(countShortOpenOrders()==0)
      {
         closeAllMarketPositions();
        
         posCounter++;
         int opened=OrderSend(Symbol(),OP_SELL,calcLotto(),Bid,50,Bid+stop_loss*Point,0,""+posCounter,magic_number);
         if(opened>0)
         {
            
            verso_aperture=1;
         }
         else
            posCounter--;
      }
    }
  }
 
}

void closeForTP()
{
   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderMagicNumber()==magic_number)
         {
            if(OrderType()==OP_BUY)
            {
               
               if(Bid-OrderOpenPrice()>=take_profit*Point)
                  if(OrderClose(OrderTicket(),OrderLots(),Bid,40*Point))
                  {
                     verso_aperture=-1;
                     i--;
                     posCounter=0;
                  }
               
            }
            else if(OrderType()==OP_SELL)
            {
               
               if(OrderOpenPrice()-Ask>=take_profit*Point)
                 if(OrderClose(OrderTicket(),OrderLots(),Ask,40*Point))
                  {
                     verso_aperture=1;
                     i--;
                     posCounter=0;
                  }
            }
         }
      }
   }
}

double calcLotto()
{

   return lotto_inizio;
 
}

int countLongOpenOrders()
{
   int orders=0;
   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderMagicNumber()==magic_number && OrderType()==OP_BUY)
            orders++;
      }
   }
   return orders;
}

int countShortOpenOrders()
{
   int orders=0;
   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderMagicNumber()==magic_number && OrderType()==OP_SELL)
            orders++;
      }
   }
   return orders;
}

void closeAllMarketPositions()
{
   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderMagicNumber()==magic_number)
         {
            if(OrderType()==OP_BUY)
            {
               if(OrderClose(OrderTicket(),OrderLots(),Bid,40*Point))
                  i--;
               
            }
            else if(OrderType()==OP_SELL)
            {
               if(OrderClose(OrderTicket(),OrderLots(),Ask,40*Point))
                  i--;
            }
         }
      }
   }
   
}
//+------------------------------------------------------------------+