This paper presents a hierarchical clustering algorithm approach to the optimal coordination of directional overcurrent relays (OCRs) in microgrids. To improve the reliability and sensitivity of multi-level relay protection in distribution networks with distributed power sources, this study designs an adaptive setting strategy optimization method.