When you have a stock market that has become expensive on a price-to-earnings basis, technical momentum on weekly charts becomes the best tool as to when to invest and when to book profits.

When a stock continues to trade to new highs, weekly closes are above its key weekly moving average with rising weekly momentum readings that eventually risees into overbought territory. When these indicators start to deteriorate its time to reduce holdings regardless of P/E ratio and dividend yield.

This notion and analysis will be put to the test when defense contractors General Dynamics (GD) - Get Report , Lockheed Martin (LMT) - Get Report and Northrop Grumman (NOC) - Get Reportreport their second-quarter earnings over the next few weeks.

Defense stocks have a built-in friend: national governments that need more protection. TheStreet's Jim Cramer, whose Action Alerts PLUS portfolio holds Lockheed, recently wrote the company "sits in an industry benefiting from serious secular growth -- namely, increases in defense spending. As we've noted time and again, stability and income generation will win out in this uncertain market and LMT fits the bill."

Lockheed Martin is a holding in Jim Cramer'sAction Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells LMT? Learn more now.

Lockheed Martin has the strongest momentum and will be the first to report earnings before the opening bell on July 19. Analysts expect the company to earn $2.92 a share.

Northrop Grumman also has strong momentum and will be reporting second quarter results before the opening bell on July 27. Analysts expect the company to earn $2.49 a share.

General Dynamics does not have the upward momentum, but will given a weekly close on July 15 above its key weekly moving average. The company reports on August 3 and analysts expect earnings to be $2.30 a share.

These three stocks began the year on Jim Cramer's list of 38 'anointed' stocks for 2016. This makes them important allocations to consider in a diversified investment portfolio.

Let's take a look at the weekly charts for these defense stocks and the guidelines on how to trade them.

Here's the weekly chart for General Dynamics.

Image placeholder title

Courtesy of MetaStock Xenith

General Dynamics closed Thursday at $142.56, up 3.6% year to date and up 17.2% above its Jan. 20 low of $121.61. The stock is 7.3% below its all-time high of $153.76 set on Aug. 19, 2015.

The weekly chart shows a red line through the weekly price bars is the key weekly moving average (a 5-week modified moving average). The green line is the 200-week simple moving average considered the "reversion to the mean". The study in red along the bottom of the chart is weekly momentum (a 12x3x3 weekly slow stochastic), which scales between 00.00 and 100.00, where readings above 80.00 indicates overbought and readings below 20.00 indicates oversold. A negative weekly chart shows the stock below its key weekly moving average with weekly momentum declining below 80.00 in a trend towards 20.00.

The weekly chart for General Dynamics will end this week positive if the stock is above its key weekly moving average of $140.50 but well above the 200-week simple moving average of $113.10. The weekly momentum reading is projected to rise to 59.37 this week, up from 58.36 on July 8.

Investors looking to buy General Dynamics should do so on weakness to $128.33, which is a key level on technical charts until the end of July.

Investors looking to reduce holdings should consider selling strength to $156.18, which is a key level on technical charts until the end of September.

Here's the weekly chart for Lockheed Martin.

Image placeholder title

Courtesy of MetaStock Xenith

Lockheed Martin closed Thursday at $256, up 17.9% year to date and up 27.7% since setting its Jan. 26 low of $200.47. The stock set an all-time high of $257.93 on July 14.

The weekly chart for Lockheed Martin is positive but overbought with the stock above its key weekly moving average of $244.75 and well above the 200-week simple moving average of $165.86. The stock has been above its 200-week since the week of Jan. 20, 2012 when the average was $81.10. The weekly momentum reading is projected to rise to 88.37 this week up from 84.16 on July 6, becoming more overbought above the threshold of 80.00.

Investors looking to buy Lockheed Martin should consider doing so on weakness to $235.63, which is a key level on technical charts until the end of July.

Investors looking to reduce holdings should consider selling strength to $262.94 and $268,94, which are key levels on technical charts until the end of September, and 2016, respectively.

Here's the weekly chart for Northrop Grumman.

Image placeholder title

Courtesy of MetaStock Xenith

Northrop Grumman closed Thursday at $221.13, up 17.1% year to date and up 26.4% above its Jan. 28 low of $175.00. The stock set its all-time high of $223.79 on July 11.

The weekly chart for Northrop Grumman is positive but overbought with the stock above its key weekly moving average of $216.552 and well above the 200-week simple moving average of $132.99. The last test of the 200-week occurred during the week of Nov. 25, 2011, when the average was $54.18. The weekly momentum reading is projected to rise to 87.34 this week up from 84.93 on July 8, becoming more overbought above the threshold of 80.00.

Investors looking to buy Northrop Grumman should consider doing so on weakness to $215.33, which is a key level on technical charts until the end of July.

Investors looking to reduce holdings should consider selling strength to $230.43 and $235,03, which are key levels on technical charts until the end of 2016 and the end of September.

This article is commentary by an independent contributor. At the time of publication, the author held no positions in the stocks mentioned.