Problem with passed parameters in a function

 
Hi, I am trying to make an EA with many different stoplosses and takeprofits. So I wanted to make functions where I can pass the ticket number and it would automatically do the sl and tp. This will save much time and coding. The code below works properly in that it will modify the order, however where I stipulate that the order number is now 0, it will not change the global variable number for the order, so it will keep going back to try and close the order that is already closed and error 4108(invalid ticket) appears as the order has already been closed. Can I not change global variable Buyticket1_1 in the below function? Thanks
  if(Buyticket1_1==0)
    
   {
      Buyticket1_1 = OrderSend (Symbol(), OP_BUY, 0.1, Ask, 0, 0, 0, "Bt1_1", 0, 0, Green);
  }
  
  
  if(Buyticket1_1 > 0) BStopVer_1(Buyticket1_1);

_____________________________________________________________________________

void BStopVer_1 (int TicketNo)
   {
  
  if(OrderSelect(TicketNo,SELECT_BY_TICKET)==true)
      {
      if(OrderStopLoss()== 0)
         {
         bool res=OrderModify(TicketNo,OrderOpenPrice(),OrderOpenPrice() -0.0010,OrderOpenPrice() +0.0010,0,0);
            if(res==0)Alert(TicketNo,"failed to modify. Error",GetLastError());
         }
         
      if(MarketInfo(OrderSymbol(),MODE_BID)>OrderOpenPrice()+0.0007 )
      
         {
         bool res=OrderClose(TicketNo,OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0,Red);
          {
        if(res==1)TicketNo=0;
        if(res==0)Alert(TicketNo,"failed to close. Error",GetLastError());
      
        
         
          }
      
            if(OrderCloseTime() > 0)
               {
                  
                  
                  TicketNo = 0;
                  
                  return;
               }
            
     
      }
      return;
   }
 }  
 
  1. You can't modify the callers variable unless you pass by reference.
              Passing Parameters - Functions - Language Basics - MQL4 Reference

  2. EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.

 
if(OrderSelect(TicketNo,SELECT_BY_TICKET)==true && OrderCloseTime()==0)