Mathematically, how do you ride a stock up while taking profits along the way? Like say I have 1000 shares. Would you sell 10% every 10% and buy if it drops 20% from the 10% gain? Or even sell half at 20% buy again if it drops 10% from the 20% gain. Or should I sell x amount at 5%? What is the best plan based on average stock price movements?
The mathematically "best" way to take profits is very subjective and depends on how much potential return you want to trade away in exchange for less risk. It also depends on the nature of the risk.
For an extreme example, suppose you sell half your position whenever the price doubles. After the first double, you've recouped your initial investment and have guaranteed that you won't lose any money regardless of what happens in the future. If your investment doubles again, you sell half of what's left - 1/4 of your original investment at 4x the price, so you have basically at least doubled your money no matter what the future price movement does. But as the price continues to double, you only earn one additional unit (an arithmetic progression) while the price increases geometrically. In other words, with a 2x you have locked in 1x (your original investment), with a 4x gain you have locked in 2x, with an 8x gain you have locked in 3x, with a 16x gain you have locked in 4x, etc. This is a very expensive strategy. For instance, if you used it on a stock like Apple which went up hundreds of times, you might have something like an 8x gain when you could have had 256x. This strategy might be good for something like cryptocurrency where the chance of a crash is very high, but you still need to tweak it based on the highest chance of hitting a sell point before a price reversal.
You can run the numbers yourself based on your own situation. For instance, if you sell 10% every time the price increases 10%, you can calculate how much you have locked in if the price rises 10%, 20%, etc. Run the calculation with various percentages and see how much you would lock in if the price reaches each level, versus how much it would be worth at that point if you hadn't sold any. Make your best guess as to the likelihood at each step that the price will reach the next level. Now you can find an expected value for each percentage and determine which strategy has the highest total expected value for that likelihood.
Any strategy that has you selling some percentage of your holdings as the price goes up is going to cost you more in lost opportunity the more the price ultimately goes up. As such, I wouldn't recommend it for any investment which you expect to hold long term. For such an investment you want something like a market index or fund that you expect will keep going up in the long term. Such an investment you would only sell if you needed the money for something (such as retirement) or if your thesis on the investment changed (e.g. you felt it was no longer a good long term investment). If you want to gamble on things that might lose all or a lot of their value and never recover it, this strategy makes sense.
Mathematically, how do you ride a stock up while taking profits along the way?
Not sure about mathematically but you could put in a rolling stop loss order that will sell your stock when it drops by, say, 5% from the highest price since you made the order. Be careful, though, as the smaller you make the stop gap, the more chance that a down blip will trigger your order and you'll miss out of future gains. If you want cash for your position but still want to profit if the stock rises, then you could sell the stock and buy a call option.
You could also keep the stock and buy put options, but the premium you have to pay will lower your break-even point. If you want to reduce that break-even drop you could sell a call option above the current price to reduce the overall cost by giving up some upside. (This is called a "collar" in the option world)
For a hypothetical example, if the stock is currently at $100, you could buy a put at $97 for, say, $4 and sell a call at $110 for, say, $2. Your net cost for the options would be $2 and your break-even point (the net price at which you've locked in profits) would be $97 - $2 = $95.
What you're trying to do (it seems) is to lock in what you've gained so far (remove any downside risk) and keep all future profits (keep upside risk). There's no instrument that I'm aware of that will do that without some cost.
I can give you the perfect algorithm for taking profits along the way. It will be 100% accurate. All you have to do is provide me with your stock's future price movement. Since you can't then there is no such 'best plan'.
There is also no such thing as "average stock price movements." Stocks can move linearly, erratically or trade in a box for awhile. The daily H/L range can be large or tight.
Your fundamental decision is your outlook for the stock. If you're an investor and bullish, you hold. If you're a trader and/or you're looking to safeguard profits, you can use trailing stops, scale out of the position, or incorporate one of a number of option hedging strategies if the stock has options.
For the downside, I would implement the option approach, hedging profits. I do everything to avoid a nice gain turning into a loss. Since I don't know if you're familiar with them then my KISS suggestion would be to decide today how much of your profit you are willing to give up and then place a trailing stop, hoping that there's no gap.
If not using options, then to the upside, I'd begin scaling out when keeping that profit becomes more important to me than making more. A bird in the hand... etc.