EA Question - Close the order if reversal or the same signal occured

 

Hello,

I have a buying criteria and a selling criteria

What I want is to close a buy order if:

1) Selling criteria occurred (Reversal)

or

2) If another Buy signal occurred after opening the first one. I want to close the first buy order and enter a new buy order.


And vice versa for the sell order.


When I put the same buy or sell criteria for closing the order in the script, Metatrader enters and close the order at the same price several times, all I want to do is to tell it to wait one bar after opening the position and check, and I don't know how to do that.

I really appreciate your help in this.

Thank you,

 

Try to put the code that closes the orders before the code that opens them. I assume that you check if there is a new bar before checking to open an order.

 Regards. 

 
assemosman:


2) If another Buy signal occurred after opening the first one. I want to close the first buy order and enter a new buy order.

Why gift the broker the spread everytime, when you can simply keep the trade open?
 
GumRai:
Why gift the broker the spread everytime, when you can simply keep the trade open?

Sometimes when I open a buy order and the price goes down but doesn't reach the stop loss, and then back up again with a new buy entry with a different take profit that maybe like -2 points for the first entry.

The other solution is to modify the stoploss and take profit of the first order if a specific criteria occurs, which I don't know how to do also.

 
xiruko:

Try to put the code that closes the orders before the code that opens them. I assume that you check if there is a new bar before checking to open an order.

 Regards. 

Thank you Xiruko, I will try that.