Inserted Code
void LockInProfit() { double Balance = AccountBalance(); double Equity = AccountEquity(); if ((Equity) > (Balance*1.01)) { CloseAll(); } return; } void CloseAll() { // for (int i=OrdersTotal()-1;i>=0; i--) for (int i = 0; i < OrdersTotal(); i++) // FIFO rule { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { RefreshRates(); if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,clrNONE)) Print("Error closing (CloseAll) #",IntegerToString(OrderTicket())," Error code ",GetLastError()); } } }
I have multiple opened positions in multiple currencies. When LockInProfit() is triggered, it does not close everything.
Is the problem with LockInProfit() or/and CloseAll()?
I suspect that
1) The functions only close the currency pair that the EA is attached to and not all the other currency pairs.
2) At some point, it stop closing when (Equity) is no longer > (Balance*1.01).
How do I close everything? (All opened positions in multiple currencies )
How to close everything without attaching the EA to multiple charts of different pairs.
How do I close everything (including currencies of different pairs) when attaching the EA to only one chart?