The unevenness of the electricity consumption schedule at enterprises leads to a peak power increase, which leads to an increase in the cost of electricity supply. Energy storage devices can optimize the energy schedule by compensating the planned schedule deviations, as well as reducing consumption from the external network when participating in a demand response. However, during the day, there may be several peaks in consumption, which lead to a complete discharge of the battery to one of the peaks; as a result, total peak power consumption does not decrease. To optimize the operation of storage devices, a day-ahead forecast is often used, which allows to determine the total number of peaks. However, the power of the storage system may not be sufficient for optimal peak compensation. In this study, a long-term forecast of power consumption based on the use of exogenous parameters in the decision tree model is used. Based on the forecast, a novel algorithm for determining the optimal storage capacity for a specific consumer is developed, which optimizes the costs of leveling the load schedule.