This paper proposes an algorithm to generate the reference trajectory based on recurrent neural networks for an excavator arm working in a dynamic environment. Firstly, the dynamic of the plant which includes the tracking controller, the arm, and the pile is appropriated by a recurrent neural network. Next, the recurrent neural network combined with a Model Reference Adaptive Controller (MRAC) is used to calculate the reference trajectory for the system. In this paper, the generated trajectory is changed depending on the variation of the pile to maximize the dug weight. This algorithm is simple but effective because it only needs information about the weight at each duty cycle of the excavator. The efficiency of the overall system is verified through simulations. The results show that the proposed scheme gives a good performance, i.e. the dug weight always remains at the desired value (nominal load) as the pile changes its shape during working time.