stocks are valued on the basis of earnings going forward
at the basis of any valuation is a forecast
ie prediction, hypothesis
that hypothesis is usually based on a combination of four things 1. a trend in finances that you think will continue on
2.what you know of the actual business and what things in business produce earnings eg the product, competition, the business model
3. the stage in cycle and where it is headed
4. market forces such as trends on charts, director buying etc
but in the end business is complex and the future hasn't happened yet
you can narrow things down though choose companies with a history of earnings and not too much debt get into the stockmarket near the bottom of the cycle buy a company with a good business model, good management (avoid shady characters) buy a company whose chart is in an uptrend etc
but you still never know what is going to happen in the future when it comes to businesses so it is all gambling
just you might not be gambling as much as somebody who is just rely on charts alone