BTW, you are correct technically that if the expected return of the investment is positive, then you maximise the expected return by putting in everything now all at once. However, maybe you want to reduce the variance. Or you want to trade off return and risk. Or you want to minimise regret.
If you put all in at a certain price, and later the market moves down, you'll regret that you didn't buy cheaper, and think you timed it badly.
If, however, you commit to a strategy of putting in say 5% per month over the next months, then a) you just automate it, and don't think about it anymore, and b) you don't really have a reference price at which you bought (sure, you can determine your actual cost basis, but who does that...) and thus avoid regret when the market tanks. Plus you reduce variance (by reducing the variance of your cost basis).