That confused me initially too. I know that post. But in my code I did not compare the Stop value to the MAE but I calculated the max loss of any trade and it was a lot greater than stop value set.
Just look at how vMinTradeResult is calculated. vMinTradeResult is -300pips while I think it should not be less than -100pips as there is a stop set at 100pips.
The TakeProfit seems to work as there is no trade result with a profit of more than 100pips.
You can remove all the MAE specific code and then it is probably clearer:
#include <profile.c>
function run()
{
// Output:
//
// 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;
for (all_trades)
{
vMinTradeResult = min(vMinTradeResult, toPIP(TradeResult));
vMaxTradeResult = max(vMaxTradeResult, toPIP(TradeResult));
}
printf("\nMinTradeResult: %f", vMinTradeResult);
printf("\nMaxTradeResult: %f", vMaxTradeResult);
printf("\n");
}
}