on *:DISCONNECT: unset %md*

This brings me to an important point. If you are setting %md#channel and are in the same channel on multiple connections (even different networks), you need to use $cid as part of the variable name or you'll unset the wrong connection's variables.

Suppose that I happen to be connected to DALnet on my first connection, EFnet on my second connection and undernet on my third connection (as I currently happen to be). DALnet's $cid is 1, EFnet's is 2 and undernet's is 3. By building my variables using the $cid, I can get disconnected from any of them and still unset the correct connection's variable set.

DALnet
[color:00007F]%md1#mIRC
%md1#HelpDesk[/color]

EFnet
[color:00007F]%md2#mIRC
%md2#Help[/color]

undernet
[color:00007F]%md3#mIRC[/color]

To build your variables this way works exactly the same (with little added code) way you're building them already: the % to indicate a variable, md, followed by $cid and finally the $chan.

To create the variable:
[color:840017]$+(%, md, $cid, $chan)[/color]

To get the value of that variable:
[color:00007F]$eval([color:840017]$+(%, md, $cid, $chan)[/color], 2)[/color]

NOTE: This will change the event I posted first, but only slightly. The ON START is added in case you lose power rather than quitting normally where mIRC has a chance to clean up before exiting cleanly.
[color:840017]
on *:START: unset %md*
on *:DISCONNECT: unset $+(%, md, $cid, *)[/color]