Download MetaTrader 5

What did i code wrong?

To add comments, please log in or register
Mohammad Rizal Bin Rahmat
442
Mohammad Rizal Bin Rahmat  
Hi... i did the following code but it doesn't works... anyone knows why and could correct my error?
Mohammad Rizal Bin Rahmat
442
Mohammad Rizal Bin Rahmat  
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
Moderator
99813
Sergey Golubev  
Mohammad Rizal Bin Rahmat
442
Mohammad Rizal Bin Rahmat  
Sergey Golubev:

Done

Ex Ovo Omnia
3382
Ex Ovo Omnia  
Mohammad Rizal Bin Rahmat:

Done


So, what "does not work" in particular?

Mohammad Rizal Bin Rahmat
442
Mohammad Rizal Bin Rahmat  
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

nicholishen
989
nicholishen  

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());
}
Mohammad Rizal Bin Rahmat
442
Mohammad Rizal Bin Rahmat  
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?

Marco vd Heijden
Moderator
5800
Marco vd Heijden  
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.

To add comments, please log in or register