Particle Swarm Optimization (PSO) is popular for solving complex optimization problems. However, it easily traps in local minima. Authors modify the traditional PSO algorithm by adding an extra step called PSO-Shock. The PSO-Shock algorithm initiates similar to the PSO algorithm. Once it traps in a local minimum, it is detected by counting stall generations. When stall generation accumulates to a prespecified value, particles are perturbed. This helps particles to find better solutions than the current local minimum they found. The behavior of PSO-Shock algorithm is studied using a known: Schwefel's function. With promising performance on the Schwefel's function, PSO-Shock algorithm is utilized to optimize the weights and bias of Artificial Neural Networks (ANNs). The trained ANNs then forecast electricity consumption in Thailand. The proposed algorithm reduces the forecasting error compared to the traditional training algorithms. The percentage reduction of error is 23.81% compared to the Backpropagation algorithm and 16.50% compared to the traditional PSO algorithm.