Errors during compilation

 
Please, I would like some help for errors that are happening when time compile the EA, I'm not getting correct


ERROR -> ')' - not all control paths return a value

double countprofit(int mode){
   double profit=0;
   if(OrdersTotal()>0){
      for(i=OrdersTotal()-1;i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic){
            if(mode==0)profit=profit+(OrderClosePrice()-OrderOpenPrice())/pt;
            if(mode==1)profit=profit+OrderProfit();
         }
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==magic){
            if(mode==0)profit=profit+(OrderOpenPrice()-OrderClosePrice())/pt;
            if(mode==1)profit=profit+OrderProfit();
         }
      }
      return(profit);
   }

}



---------------------------------------------------------------------------------------------------------------------------------

and second error --->>


void movetrailingstop(int mode,double trailingstart,double trailingstop){
   RefreshRates();
   if(OrdersTotal()>0){
      for(i=OrdersTotal()-1;i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(mode==0){
            if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
               if(OrderType()==OP_BUY){
                  if(nd(Ask,dg)>nd(OrderOpenPrice()+trailingstart*pt,dg) && nd(OrderStopLoss(),dg)<nd(Bid-(trailingstop+trailingstep)*pt,dg)){
                     OrderModify(OrderTicket(),OrderOpenPrice(),nd(Bid-trailingstop*pt,dg),OrderTakeProfit(),0,Blue);
                     return(0);
                  }
               }
               else{
                  if(nd(Bid,dg)<nd(OrderOpenPrice()-trailingstart*pt,dg) && (nd(OrderStopLoss(),dg)>(nd(Ask+(trailingstop+trailingstep)*pt,dg))) || (OrderStopLoss()==0)){                
                     OrderModify(OrderTicket(),OrderOpenPrice(),nd(Ask+trailingstop*pt,dg),OrderTakeProfit(),0,Red);
                     return(0);
                  }
               }
            }
         }
 
double countprofit(int mode){
   double profit=0;
   if(OrdersTotal()>0){
      for(i=OrdersTotal()-1;i>=0;i--){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic){
            if(mode==0)profit=profit+(OrderClosePrice()-OrderOpenPrice())/pt;
            if(mode==1)profit=profit+OrderProfit();
         }
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==magic){
            if(mode==0)profit=profit+(OrderOpenPrice()-OrderClosePrice())/pt;
            if(mode==1)profit=profit+OrderProfit();
         }
      }
   }
 return(profit);
}

void movetrailingstop(int mode,double trailingstart,double trailingstop){
   RefreshRates();
   if(OrdersTotal()>0){
      for(i=OrdersTotal()-1;i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(mode==0){
            if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
               if(OrderType()==OP_BUY){
                  if(nd(Ask,dg)>nd(OrderOpenPrice()+trailingstart*pt,dg) && nd(OrderStopLoss(),dg)<nd(Bid-(trailingstop+trailingstep)*pt,dg)){
                     OrderModify(OrderTicket(),OrderOpenPrice(),nd(Bid-trailingstop*pt,dg),OrderTakeProfit(),0,Blue);
                     return;
                  }
               }
               else{
                  if(nd(Bid,dg)<nd(OrderOpenPrice()-trailingstart*pt,dg) && (nd(OrderStopLoss(),dg)>(nd(Ask+(trailingstop+trailingstep)*pt,dg))) || (OrderStopLoss()==0)){                
                     OrderModify(OrderTicket(),OrderOpenPrice(),nd(Ask+trailingstop*pt,dg),OrderTakeProfit(),0,Red);
                     return;
                  }
               }
            }
         }
 
Ernst Van Der Merwe:

Thank you! it really helped, I could compile it!

But when I backtesting he walked five days and stopped with this error below:


What can this be?
Reason: