Need help with OrderDelete() !!!!!!!

 
double iHi;
double xHig;
double iLo;
double xLo;
double out=10;
int i;
int Range_n=4;
double lotsize=0.1;
double stoploss=1;
double takeprofit=100;
double bsl;
double btp;
double ssl;
double stp;
double magicnumber1=1111;
double magicnumber2=2222;
double k=0;
static double giamua;
static double giaban;
double lotsizebu;

int start()
  {
//----
lotsizebu=3*lotsize;
//----
{
    if(stoploss==0)bsl=0;
       else bsl= xLo-out*Point;
                  
    if(takeprofit==0)btp=0;
       else btp= xHig+out*Point + takeprofit*Point;
                  
    if(stoploss==0)ssl=0;
       else ssl= xHig+out*Point;
                  
    if(takeprofit==0)stp=0;
       else stp= xLo-out*Point - takeprofit*Point;  
}
//----
 if(Bars<Range_n) return(0);
   i=Bars-Range_n;
   
   while(i>=0)                      // Loop for uncounted bars
   {
      
       iHi=iHighest(NULL,0,MODE_HIGH,Range_n,i);        //Highest bar in n bars
       xHig=iHigh(NULL,0,iHi);                  //Value of highest in n bars
     
     
       iLo=iLowest(NULL,0,MODE_LOW,Range_n,i);          //Lowest bar in n bars
       xLo=iLow(NULL,0,iLo);                    //Value of lowest in n bars
       
   
      i--;
   }
//----
if(Isnewcandle())
  {   
      
    if(Hour()==16)
          {
             danh(1);
                 giamua=xHig+out*Point;
               Print("giamua=",giamua);
               Print("Bid=",Bid);
             danh(4);
                 giaban=xLo-out*Point;
               Print("giaban=",giaban);
               Print("Ask=",Ask);
             k=1;  
          }
     
  } 
 
//----VaoLenh 
if(k==1)
   {   
      if(Ask>=giamua) 
         {   
            k=2;
            danh(5);   
         }
      if(Bid<=giaban) 
         {  
            k=3;
            danh(6);
         }   
    }
//----RaLenh            
if(k==2)                                                    //LenhMua
   { 
      if(Ask>=giamua+takeprofit*Point)                      //Thang
         {
           Dong(2);   
         }  
   }
if(k==3)                                                     //LenhBan
   {  
      if(Bid<=giaban-takeprofit*Point)                       //Thang
         {                                                    
            Dong(3); 
         } 
   }   
//----
   return(0);
  }
//----
bool Isnewcandle()
{
static int Baronchart =0;
   if(Bars==Baronchart)
      return(false);
      Baronchart=Bars;
      return(true);

}
void danh(int dk)
{

            if(dk==1)
               {
                  int mua1=OrderSend(Symbol(),OP_BUYSTOP,lotsize,xHig+out*Point,3,bsl,btp,"",magicnumber1,TimeCurrent()+86400,Blue); 
               }
           
      
            if(dk==4)
               {
                  int ban1=OrderSend(Symbol(),OP_SELLSTOP,lotsize,xLo-out*Point,3,ssl,stp,"",magicnumber1,TimeCurrent()+86400,Red); 
               }
               
            if(dk==5)
               {
                  int ban2=OrderSend(Symbol(),OP_SELLSTOP,lotsizebu,xLo-out*Point,3,ssl,stp,"",magicnumber2,TimeCurrent()+86400,Red); 
               }
               
            if(dk==6)
               {
                  int mua2=OrderSend(Symbol(),OP_BUYSTOP,lotsizebu,xHig+out*Point,3,bsl,btp,"",magicnumber2,TimeCurrent()+86400,Blue); 
               }   
}
void  Dong(int a)
{
   int PositionIndex;
   int TotalNumberOfOrders;
   TotalNumberOfOrders = OrdersTotal(); 
   
      if(a==2)
         { 
            for(PositionIndex=OrdersTotal()-1; PositionIndex>=0 ; PositionIndex--) 
                if(! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;
                  if(OrderType()==OP_SELLSTOP)
                      if(OrderMagicNumber()==magicnumber2)
                           bool xoa=OrderDelete(OrderTicket());
                              if(xoa==false) Print("Err=", GetLastError());  
         }
      if(a==3)
         { 
            for(PositionIndex=OrdersTotal()-1; PositionIndex>=0 ; PositionIndex--) 
                if(! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;
                  if(OrderType()==OP_BUYSTOP)
                      if(OrderMagicNumber()==magicnumber2)
                               xoa=OrderDelete(OrderTicket()); 
                                   if(xoa==false) Print("Err=", GetLastError());     
         }
}
//+------------------------------------------------------------------+
Can you show me why OrderDelete() do not work. Thank pro!!
 

What is the error code is Print() returning?

If the orders are not being deleted and you are not getting an error report then the problem is in the previous code that calls the Dong function

I can't follow your code at all because it is too much work to try to work out what the variables are because the variable names give no clue.

 
toi10005doi:
Can you show me why OrderDelete() do not work. Thank pro!!
Probably because k is a double . . . does it need to be ? why can't it be an int ? have you read and understood this ? Can price != price ?
 
GumRai:

What is the error code is Print() returning?

If the orders are not being deleted and you are not getting an error report then the problem is in the previous code that calls the Dong function

I can't follow your code at all because it is too much work to try to work out what the variables are because the variable names give no clue.


It return "Err=0";
 
toi10005doi:

It return "Err=0";
Do you know for a fact that the OrderDelete() is actually being called ?