Deal or no deal for Greece? Wall Street was feeling more optimistic Wednesday, sending stocks back up.
Stocks rallied after the Greek government made a big reversal, saying it is now ready to agree to the bailout package it had previously dissed. The Dow popped as much as 182 points on the news.
Markets then backed off those highs after Greece's prime minister Alexis Tsipras gave a confusing speech: He urged the Greek people to vote against the bailout package that he had just thrown his support behind.
Despite the mixed messages, the Dow closed up 138 points (nearly 0.8%), the S&P 500 gained 0.7% and the Nasdaq picked up just over 0.5%.
What the world is trying to figure out is whether Greece will stay in the eurozone. The more Greece signals it wants to do a deal, the more investors (and everyone else) believes that Greece is likely to stay with the euro.
Related: Catch up on the Greek crisis in 2 minutes
"It's certainly a sigh of relief after three days of uncertainty and panic," said Ankur Patel, chief investment officer at R-Squared Macro Management. "It's not that the news out of Greece is very good. It's not just the worst-case scenario."
Fears of a Greek exit were at the heart of Monday's market plunge, which sent the Dow plummeting 350 points -- its biggest dive of 2015.
Deal or no deal? Those fears seemed to be coming true on Tuesday evening when Greece became the first developed economy to default on loans to the International Monetary Fund. The failure to pay its debt cuts Greece off from IMF funding.
Global markets rose sharply Wednesday morning when Greek Prime Minister Alexis Tsipras wrote a letter to creditors accepting most of the conditions attached to releasing more bailout cash.
However, it's important to note that key differences remain, including over the level of sales tax on Greek islands and pension reform. European officials are still assessing the dramatic reversal and Greek citizens can still vote down the deal in a referendum on Sunday.
Tsipras then confused the markets by telling Greeks in a televised speech they should vote "no" to strengthen his hand in future negotiations on a new rescue. But European leaders have said voting "no" would signal that voters want to leave the eurozone.
Related: Global markets leap on Greek U-turn
History says ride out the storm: Greece represents less than 2% of the European Union's economy. The latest developments support the idea that investors shouldn't dump all their stocks just because of a crisis in a country as small as Greece.
"It's about riding out the storm," said Patel, who is telling clients who have cash on the sidelines to be patient while uncertainty remains.
A look back at history shows that investors who pull their cash from the market following big market shocks often regret it.
An S&P Capital IQ analysis of the last 70 years of market shocks shows that the U.S. stock market tends to weather most storms that come its way. The median S&P 500 decline the day after a shock to the system was 2.4%. It then took the market a median of just eight days to bottom out after a shock and then only two weeks to recover all of that lost ground.
"As history has shown, prior market shocks have usually proven to be better opportunities to buy than bail," Sam Stovall, chief investment officer at S&P Capital IQ, wrote in a note to clients.
Related: Who owns Puerto Rico's debt?
Related: China didn't get the rally memo. Stocks plunged 5% in a single hour
CNNMoney's Mark Thompson and Ivana Kottasova contributed to this report.