In this paper, a new sliding window-based joint sparse representation (SWJSR) anomaly detector for hyperspectral data is proposed. The main contribution of this paper is to improve the judgments about the probability of anomaly presence in signals using the integration of information gathered during transition of sliding window for each pixel. In this method, each pixel experiences different spatial positions with respect to the spatial neighbors through the transition of this sliding window. In each position, an optimized local background dictionary is formed using a K-Singular Value Decomposition (K-SVD) algorithm and the recovery error of sparse estimation for each pixel is calculated using a simultaneous orthogonal matching pursuit algorithm (SOMP). Thus, the votes of each signal in terms of the anomaly presence in each spatial neighborhood are calculated and the variance of these recovery errors is considered as the detection criterion. The experimental results of the proposed SWJSR method on both synthetic and real datasets proved its higher performance compared to the Global RX (GRX), Local RX (LRX), Collaborative Representation Detector (CRD), Background Joint Sparse Representation (BJSR), Causal RX Detector (CR-RXD, CK-RXD), and Sliding Local RX(SLRX) detectors with an average efficiency improvement of about 7.5%, 14.25%,