Almost correct, only the if(NumOpenTotal) is unnecessary, as this is handled by the loop anyway. You can find several examples of open_trades loops in the manual.
Whether to handle trades in loop or in a TMF depends on if you need to run the task once per bar or at every price tick.