I have written some code that does basically the following,
i) When price reaches a zone, defined by a horizontal upper line and horizontal lower line a pending buy order is set.
ii) if price continues down to the lower line I want to delete the buy order and remove the ea
iii) if price goes above the upper line I want to remove the ea and leave the order.
The issue I am having is that when using ExpertRemove() it seems to remove all the orders.
I cannot seem to remove the ea and still leave any order on the chart,
The code Iines are attached. The rest of the code works it just when I attempt to remove the ea the issue starts.
I tried this crazy code:
void OnTick() { static int cnt = 0; if (cnt==0) OrderSend(_Symbol,OP_BUYSTOP,0.01,Ask*2,1,0,0); if (cnt==20) ExpertRemove(); else Print (cnt++); }
and my buystop still remains...
so it's probably time you show your whole code :).
I tried this crazy code:
and my buystop still remains...
so it's probably time you show your whole code :).
Hi Seng Joo Thio,
Thanks for the reply, I really appreciate it.
I had been working on different solutions and eventually found one that worked out well.
I'ts a bit of a work around and removes the expert at the SL and TP levels.
If a trade is not entered it is removed at SL
If trade is entered it is either removed at SL or TP, code attached.
I will have a look again and try the code you gave.
Thanks again
Cobh63: If a trade is not entered it is removed at SL
The issue I am having is that when using ExpertRemove() it seems to remove all the orders.
- False. The pending order remains unless your delete it.
- Please don't post image of code. Please edit your (original)
post and use the
CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Removing the EA does nothing to the order. Your code must be doing that.
- OrdersTotal() >= 1 && Price_A>=TP will never be true if Price_A is the Bid. The order will already have closed, and OrdersTotal() would be zero.
- Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code
is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
- False. The pending order remains unless your delete it.
- Please don't post image of code. Please edit your
(original) post and use the
CODE button (Alt-S)! (For large amounts of code,
attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Removing the EA does nothing to the order. Your code must be doing that.
- OrdersTotal() >= 1 && Price_A>=TP will never be true if Price_A is the Bid. The order will already have closed, and OrdersTotal() would be zero.
- Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your
code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
Hi William,
Thanks for the advice, I have edited and added all the code.
I tried Seng Joo Thio's but the pending are still deleted.
The basic idea is to place one pending sell order, when price goes up into the zone between the Entry line and the Stop Loss Line
If price keeps going and passes the Stop_Loss_Line Then remove the Sell Stop and remove the EA
If price turns around and the sell stop is entered to remove the ea at the Take_Profit_Line and leave the order in place with SL and TP
I tried this but it didn't work and eventually I came up with the workaround in the above code.
The work around removes the expert at the SL and TP levels.
If a trade is not entered it is removed at SL
If trade is entered it is either removed at SL or TP, code attached.
The workaround is ok and allows the ea to be removed but it's not ideal.
Thanks for taking the time to comment.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello All,
I am learning mql4 and am struggling with one particular issue.
I have written some code that does basically the following,
i) When price reaches a zone, defined by a horizontal upper line and horizontal lower line a pending buy order is set.
ii) if price continues down to the lower line I want to delete the buy order and remove the ea
iii) if price goes above the upper line I want to remove the ea and leave the order.
The issue I am having is that when using ExpertRemove() it seems to remove all the orders.
I cannot seem to remove the ea and still leave any order on the chart,
The code Iines are attached. The rest of the code works it just when I attempt to remove the ea the issue starts.
Any advice would be greatly appreciated.
Thank you