Sell a stock and buy a new one
You have to wait for three (business) days. That's the time it takes for the settlement to complete and for the money to get to your account. If you don't wait - brokers will still allow you to buy a new stock, but may limit your ability to sell it until the previous sale is settled. Here's a FAQ from Schwab on the issue. It depends on the broker. The one I use (Fidelity) will allow me to buy then sell or sell then buy within 3 days even though the cash isn't settled from the first transaction. But they won't let me buy then sell then buy again with unsettled cash. Of course not waiting for cash to settle makes you vulnerable to a good faith violation.
"This probably won't be a popular answer due to the many number of disadvantaged market participants out there but: Yes, it is possible to distort the markets for securities this way. But it is more useful to understand how this works for any market (since it is illegal in securities markets where company shares are involves).  Since you asked about the company Apple, you should be aware this is a form of market manipulation and is illegal... when dealing with securities. In any supply and demand market this is possible especially during periods when other market participants are not prevalent. Now the way to do this usually involves having multiple accounts you control, where you are acting as multiple market participants with different brokers etc. The most crafty ways to do with involve shell companies w/ brokerage accounts but this is usually to mask illegal behavior In the securities markets where there are consequences for manipulating the shares of securities. In other markets this is not necessary because there is no authority prohibiting this kind of trading behavior. Account B buys from Account A, account A buys from Account B, etc. The biggest issue is getting all of the accounts capitalized initially. The third issue is then actually being able to make a profit from doing this at all. Because eventually one of your accounts will have all of the shares or whatever, and there would still be no way to sell them because there are no other market participants to sell to, since you were the only one moving the price. Therefore this kind of market manipulation is coupled with ""promotions"" to attract liquidity to a financial product. (NOTE the mere fact of a promotion does not mean that illegal trading behavior is occurring, but it does usually mean that someone else is selling into the liquidity) Another way to make this kind of trading behavior profitable is via the derivatives market. Options contracts are priced solely by the trading price of the underlying asset, so even if your multiple account trading could only at best break even when you sell your final holdings (basically resetting the price to where it was because you started distorting it), this is fine because your real trade is in the options market. Lets say Apple was trading at $200 , the options contract at the $200 strike is a call trading at $1 with no intrinsic value. You can buy to open several thousand of the $200 strike without distorting the shares market at all,  then in the shares market you bid up Apple to $210, now your options contract is trading at $11 with $10 of intrinsic value, so you just made 1000% gain and are able to sell to close those call options. Then you unwind the rest of your trade and sell your $210 apple shares, probably for $200 or $198 or less (because there are few market participants that actually valued the shares for that high, the real bidders are at $200 and lower). This is hardly a discreet thing to do, so like I mentioned before, this is illegal in markets where actual company shares are involved and should not be attempted in stock markets but other markets won't have the same prohibitions, this is a general inefficiency in capital markets in general and certain derivatives pricing formulas. It is important to understand these things if you plan to participate in markets that claim to be fair. There is nothing novel about this sort of thing, and it is just a problem of allocating enough capital to do so." "Take the case where a stock has just two owners, A and B, both at $10. One of them sells his shares to C, at $11.  Now B has made $1 in profit but is no longer an owner of the stock. A hasn't sold anything but his shares are worth 10% more due to the last traded price printed. C has bought shares at $11 and the price is $11, so technically he hasn't lost any money. In a larger market, there are winners and losers every day on a single stock, but they may not remain owners of a stock. There could be days in which those that remain owners are all winners - say when a stock goes up to an all time high and all those that are currently owners have an average buy price lower than the last traded price. And the reverse applies too.  It is of course more complicated. Say you own a stock and let someone else ""borrow"" it for a short-selling opportunity (he sells it in the market). For each uptick in price, you win, the short seller loses, and the guy he sold it to also wins. A person that has a covered call on a stock is not a winner beyond a point. And so on." "For the first and last questions, I can do this multiple ways.  For the middle question, I'll just make up values.  If you want different ones, you will have to redo the math.   I am going to assume that you participate in the merger exchange, swapping your share for their offer.   If you own one share, it depends how they handle fractional shares.  Your original one share of ABC can be worth either one share of XYZ or 1.05 shares of XYZ.  If you get one share, you typically get an additional $.80 cash to make up for the fractional share.   You might ask why you don't just get $20 cash and one share of XYZ.  Consider the case where you own twenty shares of ABC.  Then you'd own twenty-one shares of XYZ and $384.  No need for fractional shares.   Beyond all this though, the share value of XYZ is not set autocratically.  The shares might be worth $16, $40, or $2 after the merger.  If both stocks are perfectly valued and the market is aware of that value, then it will depend partially on the number of shares of each.   For example, if we assume there are 10,000 shares of ABC and 50,000 shares of XYZ (including the shares paid for ABC), then their initial market values are $320,000 for ABC and $800,000 for XYZ.  XYZ is paying $360,000, so its value drops to $440,000.  But it is gaining ABC, which is worth $320,000.  Net value now is $760,000 or $15.20 per share.   This has assumed that the shares transferred from XYZ to the shareholders of ABC were already included in the market value.  This may mean that the stock price was previously $20 or so with almost 40,000 shares in circulation.  Then they issued new shares, diluting the value down to $16.  We could start at 50,000 shares at $16 and end up with 60,000 to 60,050 shares at $13.332 to $13.333 per share.  Then XYZ is really only paying $326,658.31 for ABC.  That's a premium of only $6,658.31 for ABC and gives a final stock value of $13.222 per share.   The problem though is that in reality, there is no equivalent of perfect value.  So I say again that the market value might be $15.20 (the theoretic answer that best fits the question given the example quantities of shares), $13, $20, or something else.  It will depend on how the market perceives the deal.  Is the combined company worth more or less than the sum of its parts?   And beyond this, you will have $19.20 to $20 in cash in addition to your XYZ share (or 1.05 shares).  Assuming 1.05 shares, that would be $15.96 plus the $19.20--that's $35.16 total in theory or anything from $19.20 up in practice.  With the givens, the only thing of which you can be sure is the $19.20 cash.  The value of the stock is up in the air.   If XYZ is only privately traded, this is still true.  The stock is worth the price that someone will pay for it.  The ""someone"" is just more limited with privately traded stocks." "I can see two possibilities. Either a deal is struck that someone (the company itself, or a large owner) buys out the remaining shares. This is the scenario @mbhunter is talking about, so I won't go too deeply into it, but it simply means that you get money in your bank account for the shares in question the same as if you were to sell them for that price (in turn possibly triggering tax effects, etc.). I imagine that this is by far the most common approach. The other possibility is that the stock is simply de-listed from a public stock exchange, and not re-listed elsewhere. In this case, you will still have the stock, and it will represent the same thing (a portion of the company), but you will lose out on most of the ""market"" part of ""stock market"". That is, the shares will still represent a monetary value, you will have the same right to a portion of the company's profits as you do now, etc., but you will not have the benefit of the market setting a price per share so current valuation will be harder. Should you wish to buy or sell stock, you will have to find someone yourself who is interested in striking a deal with you at a price point that you feel comfortable with." You need to use one of each, so a single order wouldn't cover this:  The stop-loss order could be placed to handle triggering a sell market order if the stock trades at $95 or lower.  If you want, you could use a stop-limit order if you have an exit price in mind should the stock price drop to $95 though that requires setting a price for the stop to execute and then another price for the sell order to execute. The limit sell order could be placed to handle triggering a sell if the stock rises above $105. On the bright side, once either is done the other could be canceled as it isn't applicable anymore. The way the wash sale works is your loss is added to your cost basis of the buy.  So suppose your original cost basis is $10,000.  You then sell the stock for $9,000 which accounts for your $1,000 loss.  You then buy the stock again, say for $8,500,  and sell it for $9,000.  Since your loss of $1,000 is added to your cost basis, you actually still have a net loss of $500. You then buy the stock again for say $10,500,  then sell it for $9,500.  Your $500 loss is added to your cost basis,  and you have a net loss of $1,500. Since you never had a net gain, you will not owe any tax for these transactions. "The two dimensions are to open the trade (creating a position) and to buy or sell (becoming long or short the option). If you already own an option, you bought it to open and then you would sell it to close. If you don't own an option, you can either buy it to open, or sell it (short it) to open. If you are already short an option, you can buy it back to close. If you sell to open covered, the point is you're creating a ""covered call"" which means you own the stock, and then sell a call. Since you own the stock, the covered call has a lot of the risk of loss removed, though it also subtracts much of the reward possible from your stock." The same as when you are buying a car. If a dealer quotes 10k and you quote 8k. 8k is the buy price and 10k is the sell price.  Somebody might quote 8.5k and another dealer might quote 9.5k. The the new price that you see on your screen is 8.5k(Best buy price) and 9.5k(Best sell price). When the buyer and seller agree to an amount, the car(In your case stock) is traded. "There some specific circumstances when you would have a long-term gain. Option 1:  If you meet all of these conditions: Then you've got a long-term gain on the stock.  The premium on the option gets rolled into the capital gain on the stock and is not taxed separately.  From the IRS: If a call you write is exercised and you sell the underlying stock, increase your amount realized on the sale of the stock by the amount you received for the call when figuring your gain or loss. The gain or loss is long term or short term depending on your holding period of the stock. https://www.irs.gov/publications/p550/ch04.html#en_US_2015_publink100010630 Option 2: If you didn't hold the underlying and the exercise of the call that you wrote resulted in a short position, you might also be able to get to a long-term gain by buying the underlying while keeping your short position open and then ""crossing"" them to close both positions after one year. (In other words, don't ""buy to cover"" just ""buy"" so that your account shows both a long and a short position in the same security.  Your broker probably allows this, but if not you, could buy in a different account than the one with the short position.)  That would get you to this rule: As a general rule, you determine whether you have short-term or long-term capital gain or loss on a short sale by the amount of time you actually hold the property eventually delivered to the lender to close the short sale. https://www.irs.gov/publications/p550/ch04.html#en_US_2015_publink100010586 Option 1 is probably reasonably common.  Option 2, I would guess, is uncommon and likely not worthwhile. I do not think that the wash sale rules can help string along options from expiration to expiration though.  Option 1 has some elements of what you wrote in italics (I find that paragraph a bit confusing), but the wash sale does not help you out." "They are not selling stocks. They are selling OJ futures contracts. Selling a futures contract at 142 gives the buyer the right to buy a fixed number of pounds of orange juice concentrate (""OJ"") on a future date at 142 cents per pound. The seller has an obligation to suppy that fixed number of pounds of OJ to the buyer on the future date for 142 cents per pound. When the seller turns around and buys future contracts at 29, the seller gets the right to buy OJ on a future date at 29. This ""zeros his position"" -- meaning he's guaranteed himself the ability to deliver the pounds of OJ he was obligated to supply when he sold futures contracts at 142. And since he'll only have to pay 29 cents per pound, and he'll be selling the OJ for 142 per pound, he'll walk away with 113 cents of profit for every pound sold. You can read a blow-by-blow account of what Winthorpe and Valentine did at the end of ""Trading Places"" here and here. Note that what they did would not be legal today under the ""Eddie Murphy rule"", which prohibits trades based on illicitly obtained government information." "Generally if you are using FIFO (first in, first out) accounting, you will need to match the transactions based on the number of shares. In your example, at the beginning of day 6, you had two lots of shares, 100 @ 50 and 10 @ 52.  On that day you sold 50 shares, and using FIFO, you sold 50 shares of the first lot.  This leaves you with 50 @ 50 and 10 @ 52, and a taxable capital gain on the 50 shares you sold. Note that commissions incurred buying the shares increase your basis, and commissions incurred selling the shares decrease your proceeds.  So if you spent $10 per trade, your basis on the 100 @ 50 lot was $5010, and the proceeds on your 50 @ 60 sale were $2990.  In this example you sold half of the lot, so your basis for the sale was half of $5010 or $2505, so your capital gain is $2990 - 2505 = $485. The sales you describe are also ""wash sales"", in that you sold stock and bought back an equivalent stock within 30 days.  Generally this is only relevant if one of the sales was at a loss but you will need to account for this in your code.  You can look up the definition of wash sale, it starts to get complex. If you are writing code to handle this in any generic situation you will also have to handle stock splits, spin-offs, mergers, etc. which change the number of shares you own and their cost basis.  I have implemented this myself and I have written about 25-30 custom routines, one for each kind of transaction that I've encountered.  The structure of these deals is limited only by the imagination of investment bankers so I think it is impossible to write a single generic algorithm that handles them all, instead I have a framework that I update each quarter as new transactions occur." "In a perfect world of random stock returns (with a drift) there is no reason to ""take profit"" by exiting a position because there is no reason to think price appreciation will be followed by decline.   In our imperfect world, there are many rules of thumb that occasionally work but if any one of them works consistently over a long period of time, everyone starts to practice that rule and then it stops working.  Therefore, there are no such rules of thumb that work reliably and consistently over long periods of time and are expected to continue doing so.  Finding such a rule is and always has been a moving target. The rational, consistently sensible reasons to sell a stock are: These rules are very different from my interpretation of the ""walk with your chips"" behavior mentioned in your question." It depends to some extent on how you interpret the situation, so I think this is the general idea. Say you purchase one share at $50, and soon after, the price moves up, say, to $55. You now have an unrealized profit of $5. Now, you can either sell and realize that profit, or hold on to the position, expecting a further price appreciation. In either case, you will consider the price change from this traded price, which is $55, and not the price you actually bought at. Hence, if the price fell to $52 in the next trade, you have a loss of $3 on your previous profit of $5. This (even though your net P&L is calculated from the initial purchase price of $50), allows you to think in terms of your positions at the latest known prices. This is similar to a Markov process, in the sense that it doesn't matter which route the stock price (and your position's P&L) took to get to the current point; your decision should be based on the current/latest price level. "Scenario 1 - When you sell the shares in a margin account, you will see your buying power go up, but your ""amount available to withdraw"" stays the same until settlement. Yes, you can reallocate the same day, no need to wait until settlement. There is no margin interest for this scenario.  Scenario 2 -  If that stock is marginable to 50%, and all you have is $10,000 in that stock, you can buy another $10,000. Once done, you are at 50% margin, exactly." "The only general rule is ""If you would buy the stock at its current price, hold and possibly buy. If you wouldn't, sell and buy something you believe in more strongly."" Note that this rule applies no matter what the stock is doing. And that it leaves out the hard work of evaluating the stock and making those decisions. If you don't know how to do that evaluation to your own satisfaction, you probably shouldn't be buying individual stocks. Which is why I stick with index funds."