We propose a novel dynamic gate algorithm (DGA) for precise and accurate peak detection. The algorithm uses a threshold-determined detection window and center of gravity algorithm with bias compensation. We analyze the wavelength fit resolution of the DGA for different values of the signal-to-noise ratio and different peak shapes. Our simulations and experiments demonstrate that the DGA method is fast and robust with better stability and accuracy than conventional algorithms. This makes it very attractive for future implementation in sensing systems, especially based on multimode fiber Bragg gratings.