Please consider the following code:
Shouldn't the line that contains ExpertRemove() remove the EA from the chart? Or not?
Btw, the ExpertRemove docs is here.
Inserted Code
extern bool RemoveEA=true; void OnDeinit(const int reason) { Comment(""); ObjectsDeleteAll(); } void OnTick() { if (TotalOrdersCount()>0) { CloseOpenedTrades(); ClosePendingTrades(); if(RemoveEA) {while(TotalOrdersCount()==0) ExpertRemove();} //this is what doesn't work } } int TotalOrdersCount() { int result=0; for(count=0;count<OrdersTotal();count++) { if(OrderSelect(count,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicNumber)) result++; } return (result); } void CloseOpenedTrades() {// too long to be entered here, but it works fine} void ClosePendingTrades() {// too long to be entered here, but it works fine}
Btw, the ExpertRemove docs is here.
Using the RobotFX EAs for a while https://www.robotfx.org/