In this paper we consider the detection of compact sources in maps of the cosmic microwave background radiation following the philosophy behind the Mexican hat wavelet family (MHWn) of linear filters. We present a new analytical filter, the biparametric adaptive filter (BAF), that is able to adapt itself to the statistical properties of the background as well as to the profile of the compact sources, maximizing the amplification and improving the detection process. We have tested the performance of this filter using realistic simulations of the microwave sky between 30 and 857 GHz as observed by the Planck satellite, where complex backgrounds can be found. We demonstrate that doing a local analysis on flat patches allows one to find a combination of the optimal scale of the filter R and the index of the filter g that will produce a global maximum in the amplification, enhancing the signal-to-noise ratio (SNR) of the detected sources in the filtered map and improving the total number of detections above a threshold. We conclude that the new filter is able to improve the overall performance of the MHW2, increasing the SNR of the detections and, therefore, the number of detections above a 5σ threshold. The improvement of the new filter in terms of SNR is particularly important in the vicinity of the Galactic plane and in the presence of strong Galactic emission. Finally, we compare the sources detected by each method and find that the new filter is able to detect more new sources than the MHW2 at all frequencies and in clean regions of the sky. The BAF is also less affected by spurious detections, associated with compact structures in the vicinity of the Galactic plane.