Function not defined error

 

I'm sure I'm making a newb mistake.

 

if (whatever){
  if (whatever && whoCares){
     CloseBuyPositions(); /////// Gets error: 'CloseBuyPositions' - function not defined       
  }
}

 
void CloseBuyPositions(){ /////// Gets error: 'CloseBuyPositions' - function declarations are allowed on global, namespace or class scope only

   for(int i=OrdersTotal()-1; i >=0; i--){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      string CurrencyPair=OrderSymbol();
         if (_Symbol==CurrencyPair){
            if (OrderType()==OP_BUY){
               OrderClose(OrderTicket(),OrderLots(),Bid,10,Red);
            }
         }
   }
}

I've checked it over and over again buy I'm not able to see what I'm doing wrong. 

Do I need to declare that there's a function above the ontick or something? 

 
function declarations are allowed on global, namespace or class scope only

This tells you that, where you try to declare the function, is still inside another function. Fix your missing braces.

Reason: