Account-Protector
                                
                                
                                
                                    Account-Protector copied to clipboard
                            
                            
                            
                        how are open orders closed?
Hi, how is the order of closed trades in Account Protector?
for martingale systems (example: MG EA) the trade are open in this order: 0.01 0.02 0.04 0.08
If account protector close from first opened trade would be OK because the MG EA will not continue to open other trades.
If account protector close the trade from latest trade (example: 0.08), the MG EA will directly open an new trade with 0.08 if this trade is "no longer opened".
Hi!
For 'floating profit/loss' conditions, the AP closes trades from the most profitable/losing trades to the least profitable/losing ones. In all other cases, it closes trades in no particular order to attain maximum execution speed.
is possible to change the order from the oldest order by date to the most recent?
function to close orders is on line 4403 of Account Protector.mqh file?
You could change this line inside the void CAccountProtector::Close_All_Positions() function:
for (int i = total - 1; i >= 0; i--)
to:
for (int i = 0; i <= total - 1; i++)
But this won't guarantee any specific order of closing.
just that was my idea. what do you mean it does not guarantee closing in order or open trades?
because delays between mt4 and close on broker side?
No, because positions selected from history are selected in no specific order. MT4 doesn't guarantee that order. It may coincide with actual open time order, or it may not.
I see that it check if orders have been closed or not. I will test next days and if i will face problem I will let you know.
Thanks very much.
You could change this line inside the void CAccountProtector::Close_All_Positions() function:
for (int i = total - 1; i >= 0; i--)to:for (int i = 0; i <= total - 1; i++)But this won't guarantee any specific order of closing.
I got this when is trying to close the trades: 2022.03.16 20:43:27.125 Account Protector EURUSD,M5: array out of range in 'Account Protector.mqh' (4277,45)
is on this array: if(!OrderSelect((int)PositionsByProfit[i][1], SELECT_BY_TICKET))
I tested it in normal way too with approx 100 trades for (int i = total - 1; i >= 0; i--)  but it is not reliable, because my ea start to reopen trades and account protector does not close them.
i have to see if put a loop to try 2-3 times to call CAccountProtector::Close_All_Positions()
what can you suggest to me?
You need to comment out both instances of ArrayResize(PositionsByProfit, i); in the CAccountProtector::Close_All_Positions() function. This will eliminate the error.
Also, if you are using profit/loss conditions, you need to comment out these lines there:
    if ((TriggeredCondition == Floating_loss_rises_to_perecentage) || (TriggeredCondition == Floating_loss_rises_to_currency_units) || (TriggeredCondition == Floating_loss_rises_to_points)) ArraySort(PositionsByProfit, WHOLE_ARRAY, 0, MODE_DESCEND);
    else if ((TriggeredCondition == Floating_profit_rises_to_perecentage) || (TriggeredCondition == Floating_profit_rises_to_currency_units) || (TriggeredCondition == Floating_profit_rises_to_points)) ArraySort(PositionsByProfit, WHOLE_ARRAY, 0, MODE_ASCEND);
                                    
                                    
                                    
                                
You need to comment out both instances of
ArrayResize(PositionsByProfit, i);in theCAccountProtector::Close_All_Positions()function. This will eliminate the error.Also, if you are using profit/loss conditions, you need to comment out these lines there:
if ((TriggeredCondition == Floating_loss_rises_to_perecentage) || (TriggeredCondition == Floating_loss_rises_to_currency_units) || (TriggeredCondition == Floating_loss_rises_to_points)) ArraySort(PositionsByProfit, WHOLE_ARRAY, 0, MODE_DESCEND); else if ((TriggeredCondition == Floating_profit_rises_to_perecentage) || (TriggeredCondition == Floating_profit_rises_to_currency_units) || (TriggeredCondition == Floating_profit_rises_to_points)) ArraySort(PositionsByProfit, WHOLE_ARRAY, 0, MODE_ASCEND);
commented the suggested values and added 3 times Close_All_Positions();
if(IsANeedToContinueClosingOrders) { Close_All_Positions(); //we try 4 times to close the trades Close_All_Positions(); Close_All_Positions(); Close_All_Positions(); }
will test next days and if i will face problem I will let you know.
Thanks again