You have indeed. Thanks for sticking with this. Your solution of mucking around with CountOpenTrades() was so clearly wrong that it sent me looking elsewhere. The culprit was within void CloseAllTradesBelongingToEA(), which was closing only those trades held within the FifoTicket array. Only those trades belonging to the currently selected symbol would be held in this array.
Peasants, my latest attempted fix is in post 1 - V 1k.
Classy people, compare the new function with the existing one:
Code: Select all
void CloseAllTradesBelongingToEA()
{
WholePositionForceTradeClosure = false;
if (OrdersTotal() == 0) return;
bool result = false;
for (int pass = 0; pass <= 1; pass++)
{
if (OrdersTotal() == 0 || OpenTrades == 0)
break;
for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
{
if (!BetterOrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
if (OrderMagicNumber() != MagicNumber) continue;
while(IsTradeContextBusy()) Sleep(100);
if (OrderType() < 2)
{
result = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, CLR_NONE);
if (result)
{
cc++;
OpenTrades--;
}//(result)
if (!result) ForceTradeClosure= true;
}//if (OrderType() < 2)
if (pass == 1)
if (OrderType() > 1)
{
result = OrderDelete(OrderTicket(), clrNONE);
if (result)
{
cc++;
OpenTrades--;
}//(result)
if (!result) WholePositionForceTradeClosure = true;
}//if (OrderType() > 1)
}//for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
}//for (int pass = 0; pass <= 1; pass++)
//If full closure succeeded, then allow new trading
if (!WholePositionForceTradeClosure)
{
OpenTrades = 0;
BuyOpen = false;
SellOpen = false;
}//if (!ForceTradeClosure)
}//End void CloseAllTradesBelongingToEA()
This code examines every open trade and only rejects those that have the wrong magic number.
Poor Relations in the US: this basket closure is still available to you, I think, despite your government's ludicrous FIFO rules. Every time a trade closure fails, it will set the WholePositionForceTradeClosure flag which in turn tells the bot to keep on trying to close trades. They will all close eventually. This might take a while. I suggest revolution and an overthrow of your government.

Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed
Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.