My code for 'adjust lots after loss', need help?

 
double AdjtLotsByWinRate( int magicnumber,double NormLots)
{
  int i,counter;
  int ProfitAndTime[][2];
  double Profits[];
//----
  ArrayResize(ProfitAndTime,OrdersHistoryTotal());

  for (i=0;i<OrdersHistoryTotal();i++)
  {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
   {
    if (OrderType()<=OP_SELL && OrderMagicNumber()==magicnumber )  // 0  OP_BUY    1  OP_SELL  2 OP_BUYLIMIT  3 OP_SELLLIMIT 4 OP_BUYSTOP  5 OP_SELLSTOP      
    {
    ProfitAndTime[counter][0]=OrderCloseTime();
    ProfitAndTime[counter][1]=OrderProfit();
    counter++;
    }
   }
  }
  ArrayResize(ProfitAndTime,counter);
  ArrayResize(Profits,counter);
  ArraySort(ProfitAndTime);
  
  for (i=0;i<counter;i++)
  {
   Profits[i]=ProfitAndTime[i][1];
  }
  //Print(Profits);
  int err=GetLastError();

  int WinRate_N=0,WinRate_A=5;
  double WinRate;
  for (i=counter;i<counter-WinRate_A+1;i--)
  {
   if (Profits[i]>0){ 
     WinRate_N=WinRate_N+1;
     }
     else if (Profits[i]<0)
     {
     WinRate_N=WinRate_N-1;
     }
     else
     {
     WinRate_N=WinRate_N+0;
     }
   }
   
   
   WinRate=WinRate_N/WinRate_A;
   double NewLots;
   if (WinRate>=0.7)
   {
     NewLots=NormLots*1.5;
   }
   else if (WinRate>=0.5 && WinRate<0.7)
   {
     NewLots=NormLots*1;
   }
   else if (WinRate>=0.3 && WinRate<0.5)
   {
     NewLots=NormLots*0.5;
   }
   else       //if (WinRate<0.3)
   {
     NewLots=NormLots*0.1;
   }
   
   return(NewLots);
}
But it did an error massage "incorrect start position 0 for ArraySort function" during Testing. Anyone can help me to fix it?