My EA does a double entry - page 5

 
Klammeraffe:

The line regarding "each tick" might be why it doesn't happen anymore.

The function is only executed, when a new bar appears. So, most likely, only the first tick of a bar can execute a trade. After the first bar, the code get's a 'return' until new bar appears. Maybe this solved it for me.

I think this piece of code is from the articles:

This is another work around but if there is any error return by the broker or somewhere else, your signal is not valid anymore unless you keep a loop to check again and again.
 
doshur:
  • The code posted initially by doshur, can explain why he can see in his log "Position opened in..." while no trade has been opened. This is because, even if PositionOpen() return true it doesn't mean a trade is placed. See documentation. But it can't explain why a "double" trade was placed.
correction. There is a double "Position opened in..." and 2 trade has been opened.
Of course. I mean "why he could see...". The point here is that there is nothing in your code that can explain why you got this 2 trades.
 
angevoyageur:
Of course. I mean "why he could see...". The point here is that there is nothing in your code that can explain why you got this 2 trades.
Ok. Understand. 
 
angevoyageur:

I think it's very important to found the reason behind this issue, of course it's also important to have a workaround (Sleep ?) until we can understand fully what's happening. So I try to resume the situation :

* When using the method PositionOpen from CTrade class, at least 3 users got at some time, 2 deals in the same direction instead of 1, resulting to a position with a doubled volume relative to what is expected.

I use both methods, for opening new position = "old fashion way", modifying the stoploss = "CTrade class".


* This problem seems occur on the same broker, with a symbol where Depth of Market is activated (can the concerned people confirm this please).

Yes the server of broker X, Depth of Market is activated.


* This problem occurs with synchronous order, asynchronous order wasn't used (please confirm).

Yes, asynchronous order wasn't used.


* The problem occurs randomly.

Yes, but only during busy market hours (macro economic events).



 

In my opinion this problem can easily be solved.


The EA should always wait for a response/answer if the "PositionSelect(Symbol())" function is used and the terminal has updated the data of the function, before it can resume with the execution of the code.

The EA should always wait for a response/answer if the "OrderSend(mrequest,mresult)" function is used and the terminal has updated the data of the function, before it can resume with the execution of the code.


I also mention the terminal itself because the data of the function will be copied to the terminal and this will also take some time. 

This way the current position size will always be calculated correctly, so the double order will not take place anymore.


What do you think?

 
snelle_moda:

In my opinion this problem can easily be solved.


The EA should always wait for a response/answer if the "PositionSelect(Symbol())" function is used and the terminal has updated the data of the function, before it can resume with the execution of the code.

The EA should always wait for a response/answer if the "OrderSend(mrequest,mresult)" function is used and the terminal has updated the data of the function, before it can resume with the execution of the code.


I also mention the terminal itself because the data of the function will be copied to the terminal and this will also take some time. 

This way the current position size will always be calculated correctly, so the double order will not take place anymore.


What do you think?

Not sure what you mean by "always wait for a response..." ?

Anyway I filled a request to ServiceDesk to ask for advice. We will see.

 
angevoyageur:

Not sure what you mean by "always wait for a response..." ?

Anyway I filled a request to ServiceDesk to ask for advice. We will see.

"Not sure what you mean by "always wait for a response..." ?"


The EA should wait/stop until the PositionSelect(Symbol()) function has completed copying data about a position into the program environment.

See it as a forced sleep() function.

 
snelle_moda:

"Not sure what you mean by "always wait for a response..." ?"


The EA should wait/stop until the PositionSelect(Symbol()) function has completed copying data about a position into the program environment.

See it as a forced sleep() function.

Ok understood. But I can't satisfy myself of such a solution, either there is something we don't understand or there is a bug somewhere.
 
I just hope there will be a solution. 

Anyway merry Christmas to all.
 
Any updates from the service desk?
Reason: