Distance relays are used to protect EHV and HV Transmission lines. Over the past decades many algorithms have emerged for digital distance relays. These are based on the calculation of the transmission line impedance from the relaying to fault points. In this paper a novel method for digital distance relaying is proposed. In the method the tracking procedure is implemented. The method uses the calculus of variations for optimization of functionals. The method tracks the fundamental component of the waveforms and at the same time calculates the fault loop impedance. This eliminates the need for a pre-algorithm filtering which in turn improves the speed of the relay. Comparison with other algorithms has shown that the proposed method has a faster response and improved accuracy, in particular when a long line is considered.