Hello,

I have multiple open positions from the same asset/side that I want to close against a certain price threshold. What often happens is that only the first couple of exit trades met the price threshold, especially in volatile markets.
Note: Because of MT5 I can't send limit orders.

This scenario happens when I use:
Code
exitLong();

or
Code
exitLong(0, 0, TotalSumOfLongLots);

as a failed attempt to close all open long orders at once.

In order to check the price threshold for every exit order, I've tried the following:

Code
function tock()
	{
	if(AskPrice - Spread > LongExitLimit)
		{
		for(open_trades)
			{
			if(TradeIsLong)
				{
				exitTrade(ThisTrade);
				
				if(ThisTrade != 0)
					{
					if(NumOpenLong > 0)
						{
						break_trades;
						}
					else
						{
					       //code to exit this exit check, works fine
						}	
					}
				else
					{
					printf("\nUnable to close Trade #%i", NumOpenLong);//Never had this message so far
					}	
				}
			}	
		}
	}


This sometimes won't close all long trades and I can't figure out why, as there are no errors in Zorro's or MT5's log.
Am I doing something wrong? In a perfect scenario I would like to bundle all open trades and send them as 1 exit trade, since it takes valuable time to close tens of open positions.

Thank you.



Last edited by Grant; 01/24/23 11:44.