This paper introduces a novel metaheuristic named the stochastic shaking algorithm (SSA), which is rooted in swarm intelligence principles. The innovation lies in its unique utilization of iteration for selecting references during guided searches through a stochastic approach. The optimization process involves two sequential steps: the primary reference in the first step is the finest swarm member, while in the second step, it is the mean of all finer swarm members plus the finest one. This primary reference is then combined with a randomly chosen solution within the space, serving as the secondary reference. SSA undergoes evaluation in two contexts. The first involves assessing its performance using a set of 23 classic functions as a theoretical use case. The second involves tackling the economic load dispatch problem (ELD), a practical use case featuring a system with 13 generators of various energy resources. The study compares SSA against five other metaheuristics-One to One Based Optimization (OOBO), Kookaburra Optimization Algorithm (KOA), Language Education Optimization (LEO), Total Interaction Algorithm (TIA), and Walrus Optimization Algorithm (WaOA). Results indicate SSA's superiority over OOBO, KOA, LEO, TIA, and WaOA in 21, 13, 11, 16, and 14 functions out of 23 functions, respectively. Additionally, the evaluation of the economic load dispatch problem reveals intense competition among the six metaheuristics.