The Electron Cyclotron Resonance (ECR) ion source is an irreplaceable apparatus for producing high-intensity, highly charged heavy ion beams, representing a critical component for heavy ion accelerators. The operation of the ECR ion source is inherently influenced by various factors, leading to fluctuations in beam intensity. Such instability not only diminishes the efficacy of accelerator operations but also introduces distortions in terminal experimental data. Addressing these challenges, this study proposes the application of a Temporal Convolutional Network (TCN) based on a Dynamic Time Warping (DTW) loss function (TCN-DTW) for predicting the stability of the ion beams. Prior to constructing the prediction network, raw data undergoes preprocessing through an Interquartile Range (IQR) anomaly detection mechanism and the Savitzky-Golay (SG) filtering algorithm with an adaptive window. Experimental results demonstrate a substantial enhancement in prediction performance when employing the TCN network with the DTW loss function compared to traditional alternatives. This approach facilitates effective forecasting of the ion source beam current trend, offering a basis for the control and correction of long-term stability. Consequently, it provides valuable insights for optimizing the ECR ion source and enhancing overall accelerator operational performance.