What did i code wrong?

 
Hi... i did the following code but it doesn't works... anyone knows why and could correct my error?
 
int start()

{

if((CLOSE_ORDER_PRICE_BUY && (Bid>=BUY_TAKE_PROFIT || Ask<=BUY_STOP_LOSS)))

{

for(i=OrdersTotal()-1;i>=0;i--)

{

if(!OrderSelect(i, SELECT_BY_POS) || OrderSymbol()!=_Symbol)

continue;

int type   = OrderType();

             

bool result = false;

              

switch(type)

{case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );}

          

if(result == false)

{Sleep(0);}  

}

Print ("!!ORDER CLOSE!!ORDER CLOSE!!");

return(0);

}  



if((CLOSE_ORDER_PRICE_SELL && (Ask<=SELL_TAKE_PROFIT || Bid>=SELL_STOP_LOSS)))

{

for(i=OrdersTotal()-1;i>=0;i--)

{

if(!OrderSelect(i, SELECT_BY_POS) || OrderSymbol()!=_Symbol)

continue;

             

switch(type)

{case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );}

          

if(result == false)

{Sleep(0);}  

}

Print ("!!ORDER CLOSE!!ORDER CLOSE!!");

return(0);

}  



   

Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),

        " ","ORDER CLOSE");

   

return(0);

}



Above is part of the code

It doesn't delete the Stop/Limit order once Bid/Ask hit the Price stated....

What i'm trying to do is, I have an open order and Stop Order. If Bid/Ask reach XXXXXX price, it will delete the Stop Order
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
 
Sergey Golubev:

Done

 
Mohammad Rizal Bin Rahmat:

Done


So, what "does not work" in particular?

 
Ex Ovo Omnia:

So, what "does not work" in particular?


It doesn't delete the Stop/Limit order once Bid/Ask hit the Price stated....

What i'm trying to do is, I have an open order and Stop Order. If Bid/Ask reach XXXXXX price, it will delete the Stop Order

 

Here is your code simplified. It looks like you may have an issue with your upstream logic.

void DeletePendingOrders()
{
   if((CLOSE_ORDER_PRICE_BUY && (Bid>=BUY_TAKE_PROFIT || Ask<=BUY_STOP_LOSS)))
      for(int i=OrdersTotal()-1;i>=0;i--)
         if(OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderType()==OP_SELLSTOP)
            if(!OrderDelete(OrderTicket()))
               Print("DeleteOrderError: ",GetLastError());

   if((CLOSE_ORDER_PRICE_SELL && (Ask<=SELL_TAKE_PROFIT || Bid>=SELL_STOP_LOSS)))
      for(int i=OrdersTotal()-1;i>=0;i--)
         if(OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderType()==OP_BUYSTOP)
            if(!OrderDelete(OrderTicket()))
               Print("DeleteOrderError: ",GetLastError());
}
 
nicholishen:

Here is your code simplified. It looks like you may have an issue with your upstream logic.


Thank you.....

But i get error.... do  need to add return(0) at the end of it?

 
Mohammad Rizal Bin Rahmat:

Thank you.....

But i get error.... do  need to add return(0) at the end of it?

Which error.

It's a void so it don't return anything.

Reason: