Right before exiting, store the exit code in a global variable, and let the TMF copy that variable into a TradeVar.