Elon Musk and President Donald Trump may not agree on everything. But the willingness of Musk to continue meeting with and advising Trump, even as many other tech leaders face criticism for doing so, might actually be a smart business decision.

Shares of Musk's electric car company Tesla (TSLA) are up more than 25% so far in 2017. The stock is not far from the all-time high level it last hit in September 2014 either.

And that's despite the fact that many investors are still worried about whether or not Tesla will be too late to market with its more affordable Model 3 car. GM (GM) has beaten Tesla to the punch with its new Bolt. There's also the Leaf from Nissan (NSANF).

What's more, some investors are nervous about Tesla's plan to buy SolarCity -- a move that would make it a bigger player in alternative energy but is a lot different from making and selling cars.

It doesn't help that SolarCity is run by two of Musk's cousins. Musk is also chairman. So it's understandable why critics would be concerned about nepotism and self-dealing.

So why has the stock done so well? Musk can thank Trump.

Related: Musk says he's 'doing good' on Trump's advisory panel

If the new president's policies actually boost the economy (and weaken the dollar, which also boosts oil) then there also should be stronger demand for electric cars.

For many average consumers, i.e. the ones not wealthy enough to buy a Model S or Model X but could afford a Model 3, the decision to spurn gas guzzlers in favor of a plug-in car will depend on oil prices.

If filling up the tank becomes too costly, then an electric vehicle is the smarter economic choice.

So with that in mind, Musk's willingness to engage with Trump seems to make more sense. It also helps that Musk can tout to Trump that he has created lots of American jobs with the company's new gigafactory in Nevada.

Tesla's main manufacturing factory is also in Fremont, California. Not Mexico, China, Japan or other places outside of the U.S. that Trump has been threatening with tariffs and other tough trade talk.

So in many respects, Tesla could be considered by Trump (and Wall Street) as a more all-American car company than Detroit's Big Three.

Trump has already had Twitter feuds with GM and Ford (F) over cars made in Mexico. And Fiat Chrysler (FCAU) is technically a European company now.

Related: Elon Musk's surprising secret weapon: Trump?

Of course, Musk doesn't see eye-to-eye with Trump on a lot of things.

Both Tesla and Musk-backed SpaceX joined more than 100 other tech companies that signed a legal brief opposing Trump's executive order that banned immigrants from seven mostly Muslim nations.

Musk also disagrees with some of Trump's assertions that climate change may not be a real thing.

But Musk has defended his decision to keep meeting with the president, arguing that the only way he can possibly change Trump's mind is to actually have a dialogue with him.

In other words, it looks like Musk wants to be -- to quote Trump's least favorite musical "Hamilton" -- in the room where it happens. And investors seem pretty pleased that Musk is there too.