sequence of SL and EA

 

I am writing a small EA, using sellstop and/or buystop with SL.

So when the current price, for example, drops below the sellstop order, the order will change to sell automatically by the system, not by my EA.

Also, if the price goes higher than the SL of the sell order, it will SL and the order will be gone, again by the system.

If I understand correctly, the start function of the EA will be executed on every new tick.

My question is:

When a new tick comes and if the newly come price is, for example, higher than the SL of the sell order, which one performs its task first? Will it be SLed first and my start function will be executed? Or my start function will be executed first and then the order will be SLed?

Same question with changing from sellstop to sell order!

Does anyone have an idea?

 
To-me your question is not too clear. However, my understanding is if your order already have a pre-determined Stoploss and that price hits, your EA wouldn't need to be Opened or On for the broker to close the order. Which executes first, your EA start() function or your order closing, I really don't know.
 

Let me make my question very simple.

If I have an order with SL. My EA does checks if there is an order or not. If there is an order, I print out the order information, for example. If there is no order, my EA doesn't do anything.

If new price hits the SL value of the order, what happens?

If the system SLs the order first, my EA doesn't do anything because there is no order.

But if my EA is executed first, my EA will print the information of the order because still there is an order, because it is not SLed yet by the system.

So what is the sequence of execution in this case?

 
I strongly believe the Broker terminal would close the order first because it takes priority. Maybe a safer alternative would be to also search through the order history pool. Of course this depends on what type of information you're looking for.
 

Question: Which happens first? Answer: Both.

The order is closed on the broker's server. A tick is sent to your machine.

In my modify stops routine, in the for/select loop, I was able to see the order being a fraction of a pip below the stop, but when I tried to force it closed, I get invalid ticket. I changed the test for Bid <= SL - pip and the message was suppressed.

Most of the time the EA won't see the order as open, sometimes it will.

 
If you still need to make sure your orders sequence is in line with your conditions then identify & monitor their states each & every tick arrival & compare their states with previous before doing anything else. Also need to consider MODE_FREEZELEVEL.
Reason: