XGBoost is a highly effective and widely used machine learning model and its hyperparameters take an important role on the performance of the model. This paper presents a new grid search (GS) algorithm for obtaining optimal hyperparameters of the XGBoost model based on the median values of their error loss. A benchmark method used to evaluate the proposed and original GS algorithms is introduced. Datasets with measured daily electricity demand load values of Ho Chi Minh City, Vietnam and Tasmania state, Australia are analyzed for the performance of both algorithms. The error metrics, mean squared errors (MSEs), of the proposed algorithm are found to be 2,282 MW and 501 MW that are smaller than those of original algorithms, which are 2,424 MW and 537 MW in case of Ho Chi Minh City and Tasmania state, respectively. These results then verify the accuracy of the proposed algorithm.