Order execution error
Order execution error
12 Jan 2013, 18:07
Hi,
I have backtested a robot and orders have been placed and trades executed as expected.
While testing the robot for a week real time, the robot tried to place 2 orders. Neither were successfull. The platfrom showed a feedback box stating:
" Order Request Your request to BUY LIMIT ... is being placed" (should be attached to this thread)
The platfrom then locked up and no messages (Print()) after that time were written to log.
When I closed the platfrom a further message box poped up just for a second stating:
"Order execution error".
Here is the code that places the order:
private void placeOrder() { // If all conditions of LONG trades have been met if (FlatLongShort == 1 && orderPlaced == false) { // Calculate the Volume int lots = (int)(Risk/riskInPips); lots = lots/10000; lots = lots*10000; // Round off using integer truncation Volume = lots; // Adjust entry if we are looking for a BetterEntry double entry = targetPrice - (BetterEntry/10000); Trade.CreateBuyLimitOrder(Symbol,Volume,entry,SL,TP,null); orderPlaced = true; } // If all conditions of SHORT trades have been met if (FlatLongShort == 2 && orderPlaced == false) { // Calculate the Volume int lots = (int)(Risk/riskInPips); lots = lots/10000; lots = lots*10000; // Round off using integer truncation Volume = lots; // Adjust entry if we are looking for a BetterEntry double entry = targetPrice + (BetterEntry/10000); Trade.CreateSellLimitOrder(Symbol,Volume,entry,SL,TP,null); orderPlaced = true; } }
[Background:
The logic whether an order should be placed is calculated elsewhere, OnBar
SL,TP etc are calculated elsewhere.
The above
placeOrder()
is called OnTick if a certain Bid/Ask price is reached.
However, the important point here is that the robot tries to create a Limit BUY/SELL order close to market price. Worked back testing, but not in real time.]
I have now added the following code to track the error, but it is unlikely that I will be able to read any error messages as the platform locks up and nothing will then be written to log:
protected override void OnError(Error error) { Print("There has been an Error"); switch (error.Code) { case ErrorCode.BadVolume: Print("Bad Volume"); break; case ErrorCode.TechnicalError:Print("Technical Error"); break; case ErrorCode.NoMoney: Print("No Money"); break; case ErrorCode.Disconnected: Print("Disconnected"); break; case ErrorCode.MarketClosed: Print("Market Closed"); break; } }
Does any one have any tips or hints:
- How to get more information what the Order Execution Error is
- What things cause Order Execution Errors (it does not necessarily come from the robot. It could be a platform or Internet problem)
- Any ideas?
Thanks for reading this and your advice,
/M
Replies
TraderM
19 Jan 2013, 15:23
Hi,
I will run the robot another week real time just to check that the error does not result from network problems (to save you going through the code).
I would still be interested if there are additional error codes related to an Order Execution Error which I can intercept.
I know about these:BadVolume, TechnicalError, NoMoney, Disconnected, MarketClosed
Are there any other error messages that might relate to an Order Execution Error?
Thanks,
TraderM
@TraderM
admin
21 Jan 2013, 12:16
Those are the only error codes.
You would have to move this statement orderPlaced = true to the OnPendingOrderCreated.
Due to asynchronous operation the pending order would probably not have been placed right after the statements to create the limit orders.
@admin
mattcarr
26 Jan 2013, 17:34
Hi,
thank you for the tip about moving orderPlaced = true to OnPendingOrderCreated. I have done this.
I hadn't considered anything being asynchronous. Does this often cause problems, maybe there is some documentation I could read about this?
Having added the above eror codes I got a "Disconnected" error last week. I guess that this means that the Internet connection was down temporarily. I will get some network monitoring software to see if I can match any problems with cAlgo with Internet problems.
Just to be sure: "Disconnected" means that there was no connection, rather than that the connection was ended by the server for some reason? Is that right?
Thanks,
TraderM
@mattcarr
admin
28 Jan 2013, 10:59
Disconnected means that cAlgo is disconnected from the server. It could be either one, the server beitng temporarily down or your network connection.
Asynchronous operation simply means that the program will continue operation while waiting for communication with the server. It does not produce errors.
It applies to any of the trade commands (see trade). You can use Trade.IsExecuting to check if an operation is being executed.
Just be aware that you need to use the methods OnPositionOpened to confirm that the position has been opened and OnPendingOrderCreated to confirm that the order has been created. We will add more description in the documentation concerning asynchronous operation.
@admin
admin
14 Jan 2013, 09:38
Could you please post or email us the full code. It will be helpful for us to identify the problem quicker. Thank you.
@admin