Delivering good quality of power is the main agenda for distribution system to the loads. But maintain power quality is not so easy due to the load variations in the system. Sag and swell are the main factors that affect power quality. In this paper, multiple sag conditions and swell conditions were tested by producing the condition in different phases of the system. A simple algorithm called RMS algorithm was developed and tested for the said conditions. Sag and swell were generated on single phase and multiple phases for testing the algorithm. The algorithm and the results were obtained using Matlab