order not always going through, having to retry

 

I would like to know if anyone else has experienced the following with code in the demo account. Part of my code executes a buy order such as:

OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"Comment",1,0,Blue);

Sometimes the order will go through and sometimes it does not and I have to retry and perhaps even setup a loop for the order to be placed. I'm using FXDD in demo mode.

Has anyone else experienced with having to wait and retry an order? Is this because I'm in demo mode? Should this still happen when I go live or can I expect an order such as this to go through more quickly.

Thanks.

Gomer

 

Getting any errors in your terminal > Joural ?

 

Errors can happen for a number of valid reasons, ie. not your programming error. If your EA can wait until the next tick to send the order again (assuming the buy/sell conditions are still valid), there is not much point in retrying. If not, you should put it in a retry loop with:


1) a sleep in the loop between retries

2) a count in the loop and exit above a certain count.


Whatever you do, avoid infinite loops. :)

 

Russel, there are no errors in the Journal and the code is okay because the order will eventually go, just later than I want it. I have looked at the charts and it is not because order conditions such as slippage are not being met.

blogzr3, thanks for the suggestion. I am running my code as a script rather than as an EA which runs every tick. Can you suggest something to create a sleep. I have tried a count in the loop such as trying 100 times then quitting. Sometimes, it won't work despite trying 100 times. A sleep might work but not sure how to create one.

 

Something like this:

while (handle<1 && loopcount<8)
{
handle=DoItHere(order,ordtype);
if(handle<1)
{
err=GetLastError();
Sleep(3000);
}
loopcount++;
}

if (handle<1)
{
Print("Retries failed with err: ",err);
return(-1);
}


Where DoItHere is a function call to OrderSend, OrderClose or OrderModify depending on the parameters (so I don't have to repeat the "while" lines of code).


Retrying 100 times sounds too high, review the error message and see if something else needs to be done.

 

Thanks blogzr3, that helps.

I was not aware of the Sleep(), very handy. Checking errors is also a good idea and something I've not been doing.

Reason: