I am trying to use the stock minigame to make cookies. However, I am having trouble making a profit, because I don't know what patterns to look for in the prices. What should I look for when buying stocks?
Buy Low, Sell High
Just like in the real stock market, you make the most profit when there is a great value difference between when you buy and when you sell. Each individual stock has a range of values that it can hit, but for the most part, stocks won't go much lower than $10-$20 per unit, so definitely buy any stocks you see below that.
The upper threshold is a little bit harder to judge as that varies wildly based on what type of stock you're buying and what state the market is in. Typically, most stocks will be having slow trajectories up or down and will change their behavior after 30-50 minutes or so. If you see a stock shooting up high, watch it for a bit. Once it starts to turn downward for more than a couple ticks, the rise is over and it's a good time to sell.
The typical top and bottom values is lower for the low-level stocks (such as the ones based on cursors and grandmas) and higher for high-level stocks (such as the ones based on idleverses). Cereals usually don't go much higher than $30-$40 (though I have seen them go as high as $180), but recipes can often go over $180 (my historical high is $288).
The simple way of handling this is: every hour, buy the lowest 3-4 stocks at the bottom of the graph, then sell the top 2-3. You can change these numbers to whatever makes sense based on the graph you see at the time. The downside of this method is that it will take a while to have the stocks that you want to sell, but once you start selling, it will always produce a profit.
You will make less profit per transaction using the cheaper stocks, but you'll be able to buy more of them when you do. The most important thing to do is diversify your portfolio, and make sure to always have the cookies in your bank to buy a big chunk of stocks when the opportunity arises. If something goes low enough to where you want to buy it, you should always buy as many as your warehouses will fit.
It may seem expensive at first to pay 20 minutes of unbuffed CPS ($1200) for such a small change in the exchange fee, but this is definitely worth it in the long run. There are achievements for making or spending $86,400 in a single purchase, which is not uncommon after doing several days of trading. With no brokers, either of these will come with a fee of $17,280! That's more than 14 brokers worth.
Buying ~60 brokers will reduce the fee to less than 1%. You'll never reduce it completely to 0, but the more brokers you can afford, the more profits you will make in the long run. If you plan to be on a run for more than a few days, I would suggest always maxing out your brokers as soon as possible.
Upgrade Your Office
Having more room for stocks means more profits. I wouldn't suggest stretching too far to get the necessary number of cursors to buy the next upgrade though. If you are spending several hours or days worth of cookies just to buy a resource that you will sacrifice for a few more stocks, it probably would be a better investment to spend those cookies on other buildings or the stocks themselves.
If you can buy an office upgrade without losing all of your cursors, and you already have enough cookies to buy them back, do so and you'll be able to make more profits.
Don't Use the Loans
The loans all have terrible downsides in addition to costing a huge chunk of your bank. Most of the time, the negatives far outweigh the positives. If you just bought something and have very few cookies stocked up, and you plan on being hyper active for the exact duration of the loan and then will be offline, the first two loans have the possibility of being a slight net positive. Otherwise just ignore them.
A few additions and corrections to Chase Sandmann's answer:
You only pay fees when buying stock, not when selling. So, if you mainly buy stuff in the single digit price range, you can probably get away without buying brokers.
The third loan buffs for 2 days and then nerfs for 5 days, so if you ascend within two days, you completely forgo that period. This should probably get activated as soon as possible to minimize the downpay.