Count number of Peak/Trough in a period

I have peaks and troughs based on Zig Zag function.
I want to count the number of Peak or Trough in a period, for example 250 bars...
Can experts help me plz

@zzDoanhzz,

See,