Natural chemical gradients to which cells respond chemotactically are often dynamic, with both spatial and temporal components. A primary example is the social amoeba Dictyostelium, which migrates to the source of traveling waves of chemoattractant as part of a self-organized aggregation process. Despite its physiological importance, little is known about how cells migrate directionally in response to traveling waves. The classic back-of-the-wave problem is how cells chemotax toward the wave source, even though the spatial gradient reverses direction in the back of the wave. Here, we address this problem by using microfluidics to expose cells to traveling waves of chemoattractant with varying periods. We find that cells exhibit memory and maintain directed motion toward the wave source in the back of the wave for the natural period of 6 min, but increasingly reverse direction for longer wave periods. Further insights into cellular memory are provided by experiments quantifying cell motion and localization of a directional-sensing marker after rapid gradient switches. The results can be explained by a model that couples adaptive directional sensing to bistable cellular memory. Our study shows how spatiotemporal cues can guide cell migration over large distances.