Here is a working example you perhaps can learn from, or even use for yourself (no worries, you can 'rip' it as the term may be) See if this helps you:

Code:
on *:CONNECT: {
  if (!$timer(lag $+ $network)) .timerlag [ $+ [ $network ] ] 0 120 /lag
}

on *:DISCONNECT: {
  if ($timer(lag $+ $network)) .timerlag [ $+ [ $network ] ] off
}

alias lag {
  .ctcp $me lag $ticks
}

ctcp *:lag: {
  if ($nick == $me) {
    var %ticks = $2, %lag = $calc(($ticks - %ticks) / 1000)
    /echo -s Lag Time: $round(%lag, 2) $+ sec
  }
  /halt
}


-KingTomato