Dollar cost averaging every month is the only way around this. Otherwise with lump sum investing, especially in individual companies, you're gonna need a huge amount of luck to pick the right timing to invest, even with a a mixture of good judgement, knowledge from 'experts' and a sizeable dollop of picking your timing out of thin air. Although if you have a long enough time horizon it doesnt matter when you invest. If you have 30 years or more, then the chances are that you're gonna come out ahead, even if you initially bought at a peak, just before a huge and prolonged crash. Of course with DCA, as long as you keep paying in through thick and thin, especially through the thin, then in time, things should work out great. They always have done previously.
Obviously this mainly applies to index funds and ETFs. Individual stocks still remain far too risky imo, at least for me with my current level of knowledge. I know my limits, both of my knowledge and understanding, and of the time and effort required, which I just don't have the time, energy, motivation, or interest, to learn enough about individual companies, it's just is not there, and I am therefore sticking to index funds and ETFs, which I understand very well.. Even if and when they go through bad times, they never collapse completely and always recover in time. Historically speaking. The same cannot be said for stocks in individual companies, which can easily loose huge amounts on their share prices, or entirely collapse to nothing, and basically never recover.
The vast majority of actively managed funds do far worse than passive index funds, showing that even people working full time in this occupation, cannot reliably beat the average market returns, by trying to be clever, and by trying to beat the market. This barely ever works, at least never on a consistent basis.