  Using the large-$N$ limit of the $t$-$J$ model and allowing also for phonons
and the electron-phonon interaction we study the isotope effect $\alpha$ for
coupling constants appropriate for YBCO. We find that $\alpha$ has a minimum at
optimal doping and increases strongly (slightly) towards the underdoped
(overdoped) region. Using values for the electron phonon interaction from the
local density approximation we get good agreement for $\alpha$ as a function of
$T_c$ and doping $\delta$ with recent experimental data in YBCO. Our results
strongly suggest that the large increase of $\alpha$ in the underdoped region
is (a) caused by the shift of electronic spectral density from low to high
energies associated with a competing phase (in our case a charge density wave)
and the formation of a gap, and (b) compatible with the small electron phonon
coupling constants obtained from the local density approximation. We propose a
similar explanation for the anomalous behavior of $\alpha$ in Sr doped
La$_2$CuO$_4$ near the doping 1/8.
