There are some economic signs as there are in all economic and business cycles, such as interest rates rising. However, a more effective way is to actually look at price action itself.
The definition of an uptrend is higher highs followed by higher lows. The definition of a downtrend is lower lows followed by lower highs.
So if you are looking to invest for the long term you can look at the weekly or even the monthly chart of the market say over the past 10, 15 or 20 years. Using these definitions on say the S&P500 if the price continues to make higher highs and higher lows then stay in the market.
If the price makes a lower high than the previous high, then this is a warning sign that the trend may be about to end. The trend has not broken yet but it is a warning sign that it could be ending soon. If the price makes a higher low next followed by a higher high, then the trend continues and you just need to keep an eye on things.
If, however, the price makes a lower low after the lower high this is a signal that the uptrend is over and you should get out of the market.
If the price makes a lower low directly after a higher high, then be cautious and wait for confirmation that the uptrend is over. If you then get a lower high this is confirmation that the uptrend is over, you would then sell if prices drop below the previous low.
If you invest in individual shares then you should keep an eye on the charts for the index and individual shares as well. The index chart will give you an indication if the uptrend is over for the whole market, then you can be more cautious in regards to the individual shares. You can then plan exit points on each individual share if their trends are broken too. If you have stop losses employed and the trend reverses on the index, this would be a good time to tighten your stop losses on individual shares.
You can then buy back into the market when you determine that the downtrend is broken and prices start to show higher highs and higher lows again.
Will there be occasions when the uptrend reverses and then after a short period starts trending up again, yes there might be, but the worse that will happen is that you pay a bit of extra brokerage to get out and then back into the market, and you might have to pay some capital gains tax on any profits made. But remember no one ever went broke making a profit.
The most important thing to remember when investing is to conserve and protect your capital. I would rather pay some extra brokerage and some capital gains tax than see my portfolio drop by 50% or more, then take 5 years or more to recover. And remember, paying tax is a good thing, it means you made money. If you don't want to pay any tax it means you will never make any profits, because if you make profits you will have to pay tax one day.