With the "Actions on Close" button in the song's edit window, you can define arbitrary MIDI commands that are sent when the song stops.
In the MIDI settings under "MIDI" -> "MIDI Macros" -> "Macros for Song Operations," you can select a predefined MIDI macro that will be sent when closing every song. Below that, you can also specify whether it should be sent even if the song already has its own "Actions on Close."