spike triggered average

Does anyone know how to do spike triggered average in Igor. I have a wave with multiple events and I wish to align all the events within the wave which pass a certain threshold.
Something like this (untested)?

Function STA(voltage,threshold,length)
   wave voltage
   variable threshold,length

   FindLevels/Q/DEST=spiketimes voltage,threshold  // this is crude, and should be made more appropriate for your application
   if(V_flag==2)
     DoAlert 0,"No spikes found"
     return -1
   endif

      // I'll make an averaged wave centered on spikes with total length "length" and the same scaling as the original signal
   variable dt=DimDelta(voltage,0)
   Make/O/D/N=(length/dt) spikeTriggeredAverage=0
   SetScale/P x,(-length/2),dt,spikeTriggeredAverage
   variable ii
   for(ii=0;ii<numpnts(spiketimes);ii+=1)
     spikeTriggeredAverage+=voltage(spiketimes[ii]+x)
   endfor
End