Selecting the portfolio of huge stocks is the main issue for investors to reduce a risk investment. This problem could be solved by employing a clustering as a data mining task. The technique groups together the stocks with less distance. A method to measure those dissimilarities is crucial to produce a good clustering quality. This paper is to confirm the improved distance method, dynamic time warping (DTW), stated as powerful compared to the classical way, Euclidean. Then, hierarchical clustering (HC) was used to examine the sequences from two sources of the dataset. It includes 25 stocks indexed by Indonesia Sharia Stock Index (ISSI) and 30 stocks indexed by the Jakarta Islamic Index (JII) during the year 2000-2020. The effectiveness of the distance method in clustering was evaluated by calculating the Silhouette index and running time. According to the value of the average Silhouette index, DTW-based HC gave a higher output which was not significantly different from Euclidean-based HC. In the other hand, the type of dataset contributes significantly. The Silhouette Index for JII dataset (homogeneous) is better than that for ISSI (heterogeneous). Therefore, it prefers to use similarity method with faster processing time to cluster the data if its quality is merely similar to any similarity methods.