I experimented with the MAE Graph and set up some trades with fixed Stop and TakeProfit values and noticed in the graph some outlier trades.

Some trade was closed beyound its set stop loss value which seemed odd. I verified this by iterating over all trades and calculating the max loss in pips. It was -300pips while the Stop was set to 100pips.

The following code reproduces this:

Code:
#include <profile.c>

function run()
{
	// Output:
	// 
	// MaxMAE: 456.152495
	// MaxMFE: 296.190463
	// MinTradeResult: -303.420043
	// MaxTradeResult: 99.170744
	//   Step: 10
	// Monte Carlo Analysis... Median AR 24%
	// Profit 52$  MI 2$  DD 94$  Capital 121$
	// Trades 176  Win 52.8%  Avg +3.4p  Bars 2
	// AR 20%  PF 1.07  SR 0.34  UI 40%  R2 0.16
	
	set(LOGFILE);
	
	BarPeriod = 1440;
	LookBack = 1000;
	StartDate = 2010;
	EndDate = 2015;
	
	asset("EUR/USD");

	Stop = TakeProfit = 100 * PIP;

	if (NumOpenTotal == 0)
	{
		if (Bar % 2 == 1)
			enterLong();
		else
			enterShort();
	}
	
	if (is(EXITRUN))
	{
		var vMinTradeResult = 0.0;
		var vMaxTradeResult = 0.0;
		
		var vMaxMAE = 0.0;
		for (all_trades)
			vMaxMAE = max(vMaxMAE, TradeMAE/PIP);
			
		var vMaxMFE = 0.0;
		for (all_trades)
			vMaxMFE = max(vMaxMFE, TradeMFE/PIP);
			
		for (all_trades)
		{
			vMinTradeResult = min(vMinTradeResult, toPIP(TradeResult)); 	
			vMaxTradeResult = max(vMaxTradeResult, toPIP(TradeResult));
		}
			
		printf("\nMaxMAE: %f", vMaxMAE);
		printf("\nMaxMFE: %f", vMaxMFE);
		printf("\nMinTradeResult: %f", vMinTradeResult);
		printf("\nMaxTradeResult: %f", vMaxTradeResult);
		printf("\n");
	}
	
	plotMAEGraph(0);
}



I first suspected it might have been a weekend gap but the code closes all trades before the weekend. I also tried with the TICKS flag. That did not seem to help either.

Setting BarPeriod to 60 and TimeFrame to 24 resulted in a change but the trade was also stopped way past its set stop value.

Why does this happen?