The algorithm of the ensemble pulsar time scale (PTens) based on the optimal Wiener filtration method has been proposed. This algorithm allows the separation of the contributions to the post-fit pulsar timing residuals of the atomic clock and pulsar itself. Filters were designed with the use of the cross-spectra of the timing residuals. The method has been applied to the timing data of six millisecond pulsars. Direct comparison with the classical method of the weighted average showed that use of the optimal Wiener filters before averaging allows noticeably to improve the fractional instability of the ensemble time scale. Application of the proposed method to the most stable millisecond pulsars with the fractional instability σz <10-15 may improve the fractional instability of PTens up to the level ~ 10-16 .