OrderClose : bugs or expected ? - page 2

 

Thanks for the input Ais.

 

I have some questions about the functioning of the platform :

Imagine i want to turn on some EA-symbol : EA1-EURUSD, EA1-NZDUSD, EA2-EURUSD 

If a tick on EURUSD arrives, are the two EA1-EURUSD and EA2-EURUSD executed in the same time ?

If a tick on NZDUSD arrives while  EA1-EURUSD and/or EA2-EURUSD have not finished there execution, is EA1-NZDUSD executed ?

The pools of orders, opened orders and historical orders, share the same ticket incrementation ?

If the history list size is set to maybe 30, and then a 31 closing/deleting order arrives, there should be a "disappearing ticket" (a gap in the indexing ticket of orders), what happen when a new opened order arrives ? It fills the gap, or it is place after the greater ticket ?

 

Seems like precise questions, if a metaquotes developer can respond to them... :)

 
  1. If a tick on EURUSD arrives, are the two EA1-EURUSD and EA2-EURUSD executed in the same time ? Yes

  2. If a tick on NZDUSD arrives while EA1-EURUSD and/or EA2-EURUSD have not finished there execution, is EA1-NZDUSD executed ? Yes

  3. The pools of orders, opened orders and historical orders, share the same ticket incrementation ? Ticket numbers are random increasing. They're only consecutive under the tester

  4. If the history list size is set to maybe 30, and then a 31 closing/deleting order arrives, there should be a "disappearing ticket" (a gap in the indexing ticket of orders), what happen when a new opened order arrives ? It fills the gap, or it is place after the greater ticket ? Only consecutive under the tester.


Always count down so closes (TP/SL/and EA modifications) don't affect your loop.
    for(int pos = OrdersTotal()-1; pos >= 0; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)            // Only my orders w/
    &&  OrderMagicNumber() == Magic.Number         // my magic number
    &&  OrderSymbol()      == Symbol() ){          // and period and symbol
 

Hi WHRoeder,

thanks for your response, but... (it's maybe because english is not my primary language) i don't understand your response to 3 and 4.

 

For the "invert loop", I think if it work most of the time it's because there is little chance that the pool of orders is altered while the closing function is executed by an EA-symbol. But this chance exists :

Example :

- You have 4 orders opened by EA1-EURUSD.

- EA1-EURUSD is executing the closing function (that close dynamically partially or totally an order, or not at all of course) : it is processing the order 3 (second to be executed).

- A pending order from the EA2-USDJPY (or even a pending order from EA1-EURUSD should have the same effect) is executed and then there is now 5 orders in the pool of opened orders.

- The invert counting is now searching the third order to be processed by the closing function :

- From a pool of  5 orders, the third order is then the order... 3.

 

So, the order 3 will be processed two times, and depending of the conditions/operations/functioning of the closing functions/EA that could be disastrous. (And the last order will not be processed).

 

Yes, it has little chance to happen, but if you multiply the number of EA-Symbol running in same time this chance increases.

 

I'm trying to make my systems the most robust possible, to not be surprised in a few years if this happen and "broke" all my automated strategies.

 

up,

 

any thoughts/reactions about what i said ? :) 

 

Yes the same order will be processed twice if another EA closes (active) or deletes (pending) an earlier one, (one with a lower position index.)

So what?

If it's not yours, your code will reject it because it doesn't have your magic number and keep on going down the list.

If it's yours, your code will want to set/modify the SL again and find nothing to do.

Additions add to the list (higher index) and won't be seen, but they're not yours and shouldn't be handled anyway.

 
WHRoeder:

Yes the same order will be processed twice if another EA closes (active) or deletes (pending) an earlier one, (one with a lower position index.)

So what?

If it's not yours, your code will reject it because it doesn't have your magic number and keep on going down the list.

If it's yours, your code will want to set/modify the SL again and find nothing to do.

Additions add to the list (higher index) and won't be seen, but they're not yours and shouldn't be handled anyway.


Like i said : "and depending of the conditions/operations/functioning of the closing functions/EA that could be disastrous."

This is not even a problem of filtering by magic (the "wrong" magics will not be processed at all this is not the problem here). In my example the order 3 (in each pass) have the good magic so it will be processed 2 times. 

WHRoeder:

If it's yours, your code will want to set/modify the SL again and find nothing to do.

You're making assumption that all EA function like that.

 

 

I know that this "problem" seems really not important because of the low chance that it could happen and be disastrous.

But i'm developing a framework to manage multiple strategies-symbols combination so the parallel computing problems have to be taken seriously.

 

use a global variable as a semaphor


//z

 
zzuegg:

use a global variable as a semaphor


//z


  That's a good idea. But it can't work for pending orders that still can be "activated".
 

AFAIK you can never guarantee 100% that only one process/EA has access to the OrderList(). Not even with with a semaphor.

But regarding the pending orders, this i think is not a problem, because the pending is allready includet in the OrdersTotal() and will (if triggerd) only change type. The think you have to be worried about OrderClose(), OrderCloseBy(), and OrderSend(). and even that calls should not harm a correct coded EA. At worst case the OpendedOrders are not managed during ONE tick. At next tick all should be fine again.

Can you give me a example in which this problems a realy messing up your trading EA?

 
zzuegg:

But regarding the pending orders, this i think is not a problem, because the pending is allready includet in the OrdersTotal() and will (if triggerd) only change type

 Yes, i didn't thought about that. Seems that finally the semaphore can guarantee a thread-safe closing between multiple EA.

  

zzuegg:

Can you give me a example in which this problems a realy messing up your trading EA?

 I admit i don't have a really messing up example, but i'm developer (I work for an American society in France) and when i develop a framework or a simple library of functions i have to make them "any eventual problem - safe"