This is a pretty broad question, but the short answer is simply that the underlying realities of different equities may move similarly on a general basis.
The real value of a stock is that it provides you with a portion of all future cashflows from that company [dividends + perhaps a liquidating payment if the company is ever closed down]. The ability to pay those dividends is based on the company's net income, which you could simplistically say is based on the economy in general, the relevant industry more specifically, and also the direct specifics of that company.
For example, if the US economy worsens, then some people may lose jobs, and total consumer spending decreases - this could impact the value of all consumer product companies. Further, analysts might predict that fewer people will buy cars in the next 2 years; this means that all carmakers might take a particularly large impact. Finally, perhaps a particular automaker, let's say Ford, has just made a massive investment in a new plant, and perhaps that plant is feared to need to close down due to car shortages, so Ford takes the biggest hit of all. At the same time, maybe Tesla continues to attract new buyers, so Tesla might even improve in value over the same period of time.
The point is that some general indicators impact almost every company [if the interest rate decreases, more money is available to, in theory, invest, so more money is invested and stock prices might rise], some indicators impact a lot of companies [like the cruise industry under-performing due to media coverage of trapped tourists], and some indicators are company specific [like multiple executives at a fast food chain all being fired in the same month indicating performance issues].
One final word of caution: you plainly state "most stocks chart match peaks and valleys." Be careful that you are making broad assumptions about how things work and acting on that information. I think you will find that company performance is not as aligned as you believe.