State of a partially filled cancelled order and how to force test situation

 

Hi guys,

I am finishing an EA and I am testing it. So far everything is ok, but there are some situations that I couldn't test and it really worries me.

For example: What is the ORDER_STATE of a partially filled order which has the pending part cancelled (IE. By order of 200 AAPL, 100 were executed, then 100 remaining were cancelled).

ORDER_STATE_PARTIAL, ORDER_STATE_CANCELED?

What brings me to the next question: Is there any way to force a situation in test?

Thanks.

 
eric.trevisani:

Hi guys,

I am finishing an EA and I am testing it. So far everything is ok, but there are some situations that I couldn't test and it really worries me.

For example: What is the ORDER_STATE of a partially filled order which has the pending part cancelled (IE. By order of 200 AAPL, 100 were executed, then 100 remaining were cancelled).

ORDER_STATE_PARTIAL, ORDER_STATE_CANCELED?

What brings me to the next question: Is there any way to force a situation in test?

Thanks.

Did you ever find a solution for this?

I also need to perform some testing with similar behavior.

Cheers!

 

The state of a partially filled order is ORDER_STATE_PARTIAL, as it has to inform the user about that fact that only a part of requested volume got filled.

What happens with the remaining volume depends on the filling policy (ENUM_ORDER_TYPE_FILLING) chosen in the initial order (whether you select IOC or Return).


Still, it is difficult (or even impossible) to test it in the backtesting or on demo account.

I would assume that:

- if filling type was "IOC", the order state changes to ORDER_STATE_PARTIAL and the order is moved to historical order database (as the unfllled volume gets canceled)

- if filling type was "Return", the order state changes to ORDER_STATE_PARTIAL and the order is still active - with the unfilled volume being stored in ORDER_VOLUME_CURRENT and the initial order volume in ORDER_VOLUME_INITIAL


Could anyone please confirm or deny?

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
 
Pawel Wojnarowski:


Still, it is difficult (or even impossible) to test it in the backtesting or on demo account.


You can create your own custom symbol and test it with different "filling mode" setting.


 

im also interested how to test ORDER_STATE_PARTIAL in tester.

 
............ ............:

im also interested how to test ORDER_STATE_PARTIAL in tester.

There is no partial fill in tester, nor on demo.

I don't know about the order states, but do know what happens in practice. What can happen with limit orders ORDER_FILLING_RETURN, orders can be split.

Example you buy with limit order 1 lot EURUSD at current ask.

At that price only volume of 0.48 is available, you get filled 0.48.

This creates a buy position in the terminal with a volume of 0.48 and a buy limit order with a volume of 0.52 hanging till it gets filled the 1 lot initial order completely, or canceled.

If you encounter such an example depends on the exchange if any, and or broker.

It is however good practice to get your trade management logic to deal with these situations.

 
Here (translate to English) is a few real situations of partial execution.
Частичное исполнение.
Частичное исполнение.
  • www.mql5.com
На рынке случаются различные эпизоды с исполнением торговых ордеров. Наверное, важно уметь быстро разобраться в той или иной торговой ситуации. MT5 сохраняет довольно много информации в истории
Reason: