Abstract In this paper a solution to the problem of tracking an unknown reference signal is proposed. Three-term and error driven mean square optimal controllers are defined. Self-tuning algorithms, providing adaptation to both the process dynamics and the reference signal form are derived from the optimal solution. Their global convergence is proved. Simulation results illustrate their main properties.