Ok, try this: get the latest version 1.74.8 and use for(closed_trades). It is undocumented, but is supposed to enumerate closed trades in backwards order. For aborting the loop, as you probably don't want to go through all trades, use break_trades; instead of break;.