Download MetaTrader 5

repeat ordersend till its successful

To add comments, please log in or register
Nurudeen Amedu
42202
Nurudeen Amedu 2016.07.19 16:25 

i want my function to send an order and if the order is not successful, the order should be sent repeatedly till it is

i know how to check if the send was successful

if(OrderSend(Symbol(),OP_SELLLIMIT,0.01,1.24344,10,0,0,NULL,1234,0,clrRed)==true){Sleep}else{Repeat}

 how do i tell it to repeat the ordersend?

Marco vd Heijden
Moderator
4727
Marco vd Heijden 2016.07.19 16:34  
Nurudeen Amedu:

i want my function to send an order and if the order is not successful, the order should be sent repeatedly till it is

i know how to check if the send was successful

 how do i tell it to repeat the ordersend?

You could use

do OrderSend()
while Ticket<0

but its not recommended because if the sl or tp or any value is wrong it will result the robot to be stuck in an endless loop.

just a check

if(ticket>0)
 {
  //Ok
 }
else if(ticket<0)
 {
  Print("OrderSend Error!");
 }
Nurudeen Amedu
42202
Nurudeen Amedu 2016.07.19 16:34  
Marco vd Heijden:

You could use

but its not recommended.

just a check

ok thanks
Nurudeen Amedu
42202
Nurudeen Amedu 2016.07.19 16:37  
Marco vd Heijden:

You could use

but its not recommended.

just a check

 

how do i count the order to increment ticket value

do i say?

do ticket=OrderSend();
while (ticket<0)

 

Marco vd Heijden
Moderator
4727
Marco vd Heijden 2016.07.19 16:49  
Nurudeen Amedu:
   do 
     { 
      ticket=OrderSend(.......)
     } 
   while(ticket<0);

But its not recommended it can result in an endless loop and disconnection from the server due to choking requests if your values are not correct.

In stead you can check the return value in most cases it will try to order another time on the next tick if the condition is still valid.

Nurudeen Amedu
42202
Nurudeen Amedu 2016.07.19 21:16  
Marco vd Heijden:

But its not recommended it can result in an endless loop and disconnection from the server due to choking requests if your values are not correct.

In stead you can check the return value in most cases it will try to order another time on the next tick if the condition is still valid.

thank you very much
Vasyl Nosal
2
Vasyl Nosal 2016.07.20 09:31  
Marco vd Heijden:

But its not recommended it can result in an endless loop and disconnection from the server due to choking requests if your values are not correct.

In stead you can check the return value in most cases it will try to order another time on the next tick if the condition is still valid.

 

ushort try=0;
do 
     { 
      ticket=OrderSend(.......)
try++;
     } 
   while(ticket<0 && try<200);
To add comments, please log in or register