Hi.. How to make this layer per group remove 1 layer for each group or make it dynamic when layering using martingale..

 
//+------------------------------------------------------------------+
//| Setup Lot
//+------------------------------------------------------------------+
double SetupLot(int orderType)
  {
   double lot    = 0, firstLot = 0,multiplier = Multiplier_,
          MinLot = MarketInfo(Symbol(),MODE_MINLOT),
          MaxLot = MarketInfo(Symbol(),MODE_MAXLOT),
          lotStep  = MarketInfo(Symbol(),MODE_LOTSTEP);
   int    lotDigit = 1;
   if(lotStep == 0.01)
      lotDigit = 2;
   if(lotStep == 0.001)
      lotDigit = 3;
//===============================================================================================
//if(TotalOrder(orderType)+1 >= AtLevelMulti) multiplier = LotExponent;
  
   if(MathMod(TotalOrder(orderType)+1,Layer_Per_Group)==1)
      multiplier = LotExponent;
      
//===============================================================================================
   for(int i = 0; i < OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
           {
            if(OrderType() == orderType)
               lot = MathMax(lot,OrderLots());
           }
        }
     }

   if(lot == 0)
     {
      if(Lots_By_Risk==0)
         lot = Lots_Manual;
      else
         lot = AccountBalance()*Lots_By_Risk/10000;
     }
   else
     {
      if(multiplier > 0)
        {
         lot *= multiplier;
         lot += (0.004);
        }
      else
        {
         if(Lots_By_Risk==0)
            lot = Lots_Manual;
         else
            lot = AccountBalance()*Lots_By_Risk/10000;
        }
     }


   lot = NormalizeDouble(lot,lotDigit);
   if(lot < MinLot)
      lot = MinLot;
   if(lot > MaxLot)
      lot = MaxLot;

   return(lot);
  }
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
double AskPrice(string symbol = "")
  {
   if(symbol == "")
      symbol = Symbol();
   return(MarketInfo(symbol,MODE_ASK));
  }
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
double BidPrice(string symbol = "")
  {
   if(symbol == "")
      symbol = Symbol();
   return(MarketInfo(symbol,MODE_BID));
  }
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
double  StopLevel(string symbol = "")
  {
   if(symbol == "")
      symbol = Symbol();
   return(MarketInfo(symbol,MODE_STOPLEVEL));
  }
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
string OrderCmd(int ordertype)
  {
   string label;

   switch(ordertype)
     {
      case 0:
         label = "Buy";
         break;
      case 1:
         label = "Sell";
         break;
      case 2:
         label = "Buy Limit";
         break;
      case 3:
         label = "Sell Limit";
         break;
      case 4:
         label = "Buy Stop";
         break;
      case 5:
         label = "Sell Stop";
         break;
     }

   return(label);
  }

My code line

if(MathMod(TotalOrder(orderType)+1,Layer_Per_Group)==1) multiplier = LotExponent;

normally if i set 10 layer per each group it open

0.01x10 0.02x10 0.04x10

and so on using martingale layer per group set..

But how to make it -1 each layer per group like this

0.01x10 0.02x9 0.04x8

And so on until left with 1 layer then martingale normally for each layer after that??

i want to make it -1 each layer per group or make it open layer more versatile or dynamic.. Maybe from first group open 10, then next group open 10 also, then 8 then 5 something like this..