It's a fair bit longer than yours, and includes the ops/voices (which you already say you have working).

This has been tested on a network running UnrealIRCd. I don't know if that's going to make a difference or not. I don't think it will.
Code:
 on *:rawmode:*:{
  var %mode = $1
  tokenize 32 $2-
  if $left(%mode,1) == + {
    if $pos(%mode,q,0) {
      var %a = 1, %b = $pos(%mode,q,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %founders
          echo $chan %founders founders 
        }
        inc %a
      }
    }
    if $pos(%mode,a,0) {
      var %a = 1, %b = $pos(%mode,a,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %protects
          echo $chan %protects protects
        }
        inc %a
      }
    }
    if $pos(%mode,o,0) {
      var %a = 1, %b = $pos(%mode,o,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %ops
          echo $chan %ops ops
        }
        inc %a
      }
    }
    if $pos(%mode,h,0) {
      var %a = 1, %b = $pos(%mode,h,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %hops
          echo $chan %hops half-ops
        }
        inc %a
      }
    }
    if $pos(%mode,v,0) {
      var %a = 1, %b = $pos(%mode,v,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %voices
          echo $chan %voices voices
        }
        inc %a
      }
    }
  }
  else {
    if $pos(%mode,q,0) {
      var %a = 1, %b = $pos(%mode,q,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %defounders
          echo $chan %defounders de-founders
        }
        inc %a
      }
    }
    if $pos(%mode,a,0) {
      var %a = 1, %b = $pos(%mode,a,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %deprotects
          echo $chan %deprotects de-protects
        }
        inc %a
      }
    }
    if $pos(%mode,o,0) {
      var %a = 1, %b = $pos(%mode,o,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %deops
          echo $chan %deops de-ops
        }
        inc %a
      }
    }
    if $pos(%mode,h,0) {
      var %a = 1, %b = $pos(%mode,h,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %dehops
          echo $chan %dehops de-half-ops
        }
        inc %a
      }
    }
    if $pos(%mode,v,0) {
      var %a = 1, %b = $pos(%mode,v,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %devoices
          echo $chan %devoices de-voices
        }
        inc %a
      }
    }
  }
}
 


Noting the level of complexity in your code, you should be able to work out how my code works, however, if you have problems, post here and I or someone else will be happy to explain.