I'm starting to think that sometimes the market can ONLY do the irrational thing.
E.g. 1: Say for some reason a crisis occurs that will cut corporate earnings in half and lead to a large number of defaults and bankruptcies. Most investors will see this as a bearish sign and try to sell their stocks at prices higher than the forecast would warrant. After the last bear has sold, the next day the only people trading are bulls. Therefore, the market can only go up because the bulls don't want to sell, they want to buy, and they're the only people still trading in the market.
E.g. 2: Say for some reason the market zooms up in an unsustainable expansion of PE ratios and any other valuation metric. Anyone who is analyzing their investments in a rational way, with spreadsheets showing cashflow projections and expected ROI, will sell. After the last person who cares about fundamentals has sold, the next day the only people trading are the momentum traders and technical analysts. Therefore, the market can only go up because fundamentals don't matter to the only people still trading in the market.
E.g. 3: Say a crash occurs and the landscape is cleared and ready for several years of growth. Weak companies are going bankrupt, defaults are at their peak because new debts are not being taken on, consumers are reducing their debts, unemployment is a few months from its peak, and there is a lot of deferred spending waiting to happen because people are holding off on business investments, cars, homes, appliances, etc. Overall, it's a great time to invest! By this time, the bulls have lost their asses and tied up everything they own in stocks. The bears are still scared, perhaps at their peak of being scared. Therefore, even though investing conditions are ideal right at this instant, the only thing that can happen is a very slow recovery as the bulls slowly invest their earnings from work/business. The bulls have no cash on the sidelines and the bears are too scared to go all in (being bears and all). This is why the market crashes quickly, but takes years to recover, even though rationally it has the best prospects at the bottom.
IDK how to operationalize this because reliable real-time investor polling is not a thing. Also, it seems like example 1 would lead to a dead-cat bounce that you would NOT want to buy into, and example 2 would lead to a market peak that you would NOT want to buy into. Maybe both of those are shorting opportunities, or opportunities to exit long positions. Example 3 is the most problematic. How far down is the bottom? At what point do you know the bulls ran out of money?
Perhaps the algorithm is as follows:
Pattern 1 or 2 detected: Switch from long exposure to a hedged limited-downside position such as a protected put or long call before the bulls and pattern traders run out of money.
Pattern 3 detected: Now that you saved some money by limited your downside, plow that cash into long stock positions before the bulls run up the price.