Errors 'LotsOptimized' - function declarations are allowed on global, namespace or class scope only

 
//---------------------------------------------- Input parameters ---!
input double         StartLotSize  = 0.01;     // The starting lot size
input double         StartBalance  = 100.0;    // The starting balance
//---------------------------------------------- Money management ---!
double LotsOptimized(){
   double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP),LotSize=0;
   if(LotStep==0.1){LotSize=NormalizeDouble(StartLotSize*(AccountFreeMargin()/StartBalance),1);}
   if(LotStep==0.01){LotSize=NormalizeDouble(StartLotSize*(AccountFreeMargin()/StartBalance),2);}
   if(LotSize<MarketInfo(Symbol(),MODE_MINLOT)){LotSize=MarketInfo(Symbol(),MODE_MINLOT);}
   if(LotSize>MarketInfo(Symbol(),MODE_MAXLOT)){LotSize=MarketInfo(Symbol(),MODE_MAXLOT);}
   return(LotSize);
   }
 
You have a missing close bracket above that code.
Reason: