Stocks edged higher on Friday afternoon as crude oil continued to race toward the $40 level.

The S&P 500 was up 0.4%, the Dow Jones Industrial Average added 0.3%, and the Nasdaq rose 0.11%. 

Crude oil added to highs on Friday afternoon after the number of active crude oil drilling rigs in the U.S. fell by 8 to 354, according to Baker Hughes data. The number of active drilling rigs has tumbled 78% since hitting its peak in October 2014. 

Oil was already higher as commodity traders pinned hopes on next week's meeting among Organization of Petroleum Exporting Countries members which will hopefully result in a production freeze. West Texas Intermediate crude oil was up 5.5% to $39.30 a barrel.

"Sentiment is ... swinging back to a more bullish view of the upcoming April 17 producer freeze talks in Doha," said Timothy Evans, energy futures analyst at Citi. "We continue to see any deal without Iran as doing little more than confirming a status quo, since the majority of producers in attendance weren't planning or able to raise output anyhow."

The energy sector was the best performer Friday. Major oilers including Exxon Mobil (XOM - Get Report) , Chevron (CVX - Get Report) , PetroChina (PTR - Get Report) and Royal Dutch Shell (RDS.A - Get Report) were higher, while the Energy Select Sector SPDR ETF (XLE - Get Report) added 2.1%.

Consumer stocks were the weakest performers on Friday, led by a selloff in Gap (GPS - Get Report) shares. Gap plummeted 14% after reporting a 6% slump in same-store sales in March. The retailer had reported a 2% increase over the same period a year earlier. Banana Republic was the worst performer, tumbling 14% compared to a 3% decrease in March last year.

Other retailers in the red on Friday included Nike (NKE - Get Report) , Target (TGT - Get Report) , VF Corp (VFC - Get Report) , Dollar General (DG - Get Report) , L Brands (LB - Get Report) and Ross Stores (ROST - Get Report) . The SPDR S&P Retail ETF (XRT - Get Report) fell 0.5%. 

Target is a holding in Jim Cramer's Action Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells TGT? Learn more now.

Stocks have had a rocky week, rallying on Wednesday on signs of a dovish Federal Reserve and selling off on Thursday alongside crude oil. Investors have shown weariness ahead of the kickoff to first-quarter earnings season next week. The Dow suffered its worst loss in six weeks on Thursday, plummeting 174 points or 1%.

Fed Chair Janet Yellen and former Fed chiefs Alan Greenspan, Ben Bernanke and Paul Volcker inspired good vibes on Wall Street after assuring that the U.S. economy wasn't heading back into recession despite presidential frontrunner Donald Trump's claims that we are in a bubble.

The "economy has made tremendous progress in recovering from the damage from the financial crisis," Yellen said at a panel discussion at the International House of New York on Thursday night. "Slowly but surely, the labor market is healing. For well over a year, we've averaged about 225,000 jobs a month, the unemployment rate now stands at 5%, and we're coming close to our assigned congressional goal of maximum employment."

The Fed's policy-tightening will be a gradual process given risks to the U.S. economy remain, New York Fed President William Dudley said Friday morning. The dovish voting member said he expects the U.S. economy to grow around 2% in 2016.

"Although the downside risks have diminished since earlier in the year, I still judge the balance of risks to my inflation and growth outlooks to be tilted slightly to the downside," Dudley said in prepared remarks.

The first-quarter earnings season will kick off in earnest on Monday afternoon when unofficial bell-ringer Alcoa (AA - Get Report) reports. Uncertainty over how major companies fared over the quarter kept bulls on the sidelines and pushed bears to sell.

"As we start to kick in to earnings season there's going to be anxiety," Matt Kaufler, portfolio manager at Federated Investors, told TheStreet. "There's a general skepticism that [earnings] are perhaps steady but they'll be unenthusiastic. Steady but uninspiring."

The early prognosis on companies' quarterly performances doesn't look good. S&P 500 earnings are expected to fall 7.9% in the first quarter, their third straight quarter in decline and their losing streak worst since mid-2009. Excluding the energy sector, earnings are forecast to fall 3.6%.

Twitter (TWTR - Get Report) was 2.5% lower after naming PepsiCo Chief Financial Officer Hugh Johnston and founder Martha Lane Fox to its board. The two new board members will begin work immediately.

Twitter is a holding in Jim Cramer's Action Alerts PLUS Charitable Trust Portfolio

"We like the change, specifically the addition of PepsiCo Vice Chairman and CFO Hugh Johnston," said Jack Mohr, research director and co-portfolio manager for Action Alerts PLUS.

"PEP is one of our core holdings in the AAP portfolio, and Mr. Johnston has been instrumental in driving cost discipline in an efficient, yet productive manner (the company is on track to deliver $1 billion of annual productivity savings through 2019)," he added. "He has demonstrated an uncanny ability to manage the pace and magnitude of operational efficiencies without compromising top-line growth, and has proven adept at transforming the PepsiCo brand amidst a challenging backdrop for consumer packaged goods. While we do not place too much weight on individual board seats, there is no doubt that Mr. Hughes' vision, experience and wisdom is highly relevant in context of Twitter's challenges (as it struggles to drive both growth and cost efficiencies amidst a deceleration in its active audience)."

Anavex Life Sciences (AVXL) jumped more than 9% after announcing its Alzheimer treatment had received orphan drug designation from the Food and Drug Administration. The designation provides the drugmaker with development and commercial incentives, including seven years of market exclusivity in the U.S. and certain exemptions from or reductions in regulatory fees.

DepoMed (DEPO) added 12.5% after activist investor Starboard Value disclosed a 9.8% stake. The firm, now the pharmaceutical company's third-largest shareholder, said it intends to nominate board members and also questioned DepMed's "serious corporate governance deficiencies [and] questionable capital allocation decisions."

Marriott (MAR - Get Report) and Starwood Hotels (HOT) were slightly higher after shareholders approved their proposed merger. A near-unanimous 97% of Marriott shareholders approved of the acquisition, while 95% of Starwood voters were in agreement.