PART VI · Chapter 44 · 257 / 660

Lesson 257. Moving averages and ATR as rule components

Chapter 44. Combining Indicators into Repeatable Rule Components

Say you wrote this in your rule notes: buy only when the close is above the 50-day line, and put the stop-loss level two times the average true range (ATR) below the entry price. It is a rule that uses the two indicators of Lessons 248 and 253 as they are. But what changes if you switch 50 to 20, or two times to three times?

More than you might think. The days and prices you buy change, and so do the stop-loss level and the quantity. This lesson reads a moving average as three numbers, slope, lag and distance, and decides whether to use it as a filter or a signal.

It then updates the ATR with the Wilder method and converts it to a ratio of price to compare stocks. Finally, it calculates how far the stop-loss level and quantity move when you change lengths and multiples, and connects that to the quantity limits of Lesson 276.

1. The slope of a moving average is set by the price n trading days ago

In Lesson 248, the 5-day average changed as one new close came in and the oldest close dropped out. Written as a formula, the daily change of an n-day simple moving average is as follows.

Daily change = (today's close − close n trading days ago) ÷ n

So whether the average line rises is not decided by today's price alone. If today's close is above the close n trading days ago, it rises; if below, it falls. Saying the 50-day line is rising is the same as saying today's close is above the close of 50 trading days ago.

Check this with a hypothetical stock. Over 50 trading days it falls $1 a day from $140 to $90, then rises $1 a day from the day after the bottom. The close on trading day 15 after the bottom is $105.

On this day the daily change of the 20-day line is (105 − 95) ÷ 20 = $0.50, so it rises. The 50-day line is (105 − 125) ÷ 50 = −$0.40, so it is still falling. That is because the close of $125 from 50 trading days ago drops out and $105 comes in. The 50-day line stops falling only on trading day 25, at $115, when today's close equals the close of 50 trading days ago.

2. Read lag and distance together with slope

When the price rises steadily, an n-day simple moving average trails the price by (n − 1) ÷ 2 trading days. That is because the middle of the n prices in the average lies that far in the past.

Average length Lag Gap to the close when rising $1 a day
10-day (10 − 1) ÷ 2 = 4.5 trading days $4.50
20-day (20 − 1) ÷ 2 = 9.5 trading days $9.50
50-day (50 − 1) ÷ 2 = 24.5 trading days $24.50

The example of section 1 shows this too. On trading day 15 after the bottom, the 10-day line is the average of the closes of trading days 6 to 15, $100.50, which is $4.50 below the close of $105.

This gives a way to read distance. Distance is usually measured as (close − average) ÷ average × 100. But in a steady trend, the distance is almost fully set by the daily rise times the lag. If days rising $1 each continue for more than 50 trading days, the close stays always $24.50 above the 50-day line. So do not call a stock overheated just because it is far from its average; look at whether the distance suddenly widened while the slope stayed the same.

To compare distances across stocks, ATR units are handier than percentages. Converting to (close − average) ÷ ATR tells you how many days of usual movement away it is. Section 6 uses this value as a chase limit.

3. Use a slow average as a filter and a fast average's cross as a signal

Moving averages in a rule do two jobs. A filter judges whether this stock is now in a state where you may take buy signals. A signal tells you that an event to place an order on has occurred today, and it has a date.

Start with signals, using the prices of section 1. If you define the signal as the day the close crosses the n-day line from below, the date depends on the average's length. The 10-day line is crossed on trading day 3 after the bottom. That day the 10-day line is the average of the closes 96, 95, 94, 93, 92, 91, 90, 91, 92 and 93, which is $92.70, and the close is $93.

Condition First day met Close that day
Signal: close crosses above the 10-day line Trading day 3 after the bottom $93
Signal: close crosses above the 20-day line Trading day 6 after the bottom $96
Signal: close crosses above the 50-day line Trading day 15 after the bottom $105
Filter: close above the 50-day line and 50-day line not lower than the day before Trading day 25 after the bottom $115

The 50-day signal comes 12 trading days later than the 10-day signal, at $105, about 12.9% above $93.

Price line of a hypothetical stock that falls $1 a day for 50 trading days from $140 to $90 and then rises $1 a day. The close first crosses the 10-day line on trading day 3 after the bottom at $93, the 20-day line on trading day 6 at $96, and the 50-day line on trading day 15 at $105. The filter, close above the 50-day line and 50-day line not lower than the day before, opens only on trading day 25 at $115. The longer the average, the later the signal and the higher the entry price.

That does not make a fast signal always better. Say the rebound stops on trading day 8 at $98 and the price falls $1 a day again. The 10-day and 20-day signals already fired at $93 and $96, and both fail. On the same day, the 50-day line is $107.94, $9.94 above the close, so the filter does not open.

The filter screens out the rebound that would fail, but at a real bottom it makes you wait until $115. So it is better not to mix the roles. Use a slow average's cross as a signal and entries come late; use a fast average as a filter and the state changes too often. For example, you might split the 50-day line's position and slope into the filter and the 20-day breakout into the signal. Real prices are not this straight, so in sideways stretches, signals from a fast average appear and vanish many times.

4. Update the ATR with the Wilder method; the length sets the speed of response

The true range (TR) seen in Lesson 253 is the largest of the high minus the low, the difference between the high and the prior close, and the difference between the low and the prior close. All differences are measured as positive numbers. The Wilder method ATR updates this TR as follows.

New ATR = (prior ATR × (n − 1) + today's TR) ÷ n

Say a hypothetical stock closed at $104.00 the day before, then gapped down and traded with a high of $101.20 and a low of $99.68. The high minus the low is $1.52, the difference between the high and the prior close is $2.80, and the difference between the low and the prior close is $4.32. The TR is $4.32, about 2.8 times the value from the day's range alone.

With the commonly used 14 periods, (2.50 × 13 + 4.32) ÷ 14 = $2.63, up 5.2% from the prior day's $2.50. If the same stock's 5-period ATR was $2.42 the day before, (2.42 × 4 + 4.32) ÷ 5 = $2.80, up about 15.7%. The short ATR responds to the same gap about three times as strongly.

The speed of fading differs too. In a 14-period ATR, the effect left by one day's TR shrinks by 13 ÷ 14 each day. Even if only TRs of usual size follow, after 14 trading days (13 ÷ 14) to the 14th power of the initial rise, about 35% remains. This is why a stop-loss distance measured in ATR stays wide for several weeks after an earnings gap.

Whether the first ATR starts as the simple average of the first 14 TRs or uses another averaging method can differ between charts. Write the calculation method in the rule along with the length.

5. Convert the ATR to a ratio of price to compare stocks

The ATR is a dollar amount, so you cannot compare it directly between stocks with different prices. As in Lesson 462, convert it to ATR ÷ close × 100, the ATR ratio. Say hypothetical Garam has an ATR of $1.60 at $40, and Nuri an ATR of $5.00 at $250.

Garam 1.60 ÷ 40 × 100 = 4.0%, Nuri 5.00 ÷ 250 × 100 = 2.0%

In dollars, Nuri's ATR is more than three times larger, but relative to its own price, Garam moves twice as much.

This exposes the problem with treating two times the ATR as the right stop-loss distance for every stock. Using 2 times as is puts the level $3.20 below for Garam, 8.0% of the price, and $10.00 below for Nuri, 4.0%. This distance only means two days of usual movement; it is not grounds for saying your judgment was wrong at that price. The ATR is an average, so it does not include event losses such as the earnings gaps seen in Lesson 276 either.

So reverse the order. Set the stop-loss level first from the chart structure: a price that, if touched, means your judgment was wrong, such as just below the prior confirmed low. Use the ATR as the ruler that measures that distance. For example, if (entry price − stop-loss level) ÷ ATR is below 1.5, ordinary swings can easily touch it, so postpone the entry; if it is above 4, the quantity gets too small, so skip it. Lesson 283 compares fixed-percentage, structural, ATR and time stops again.

6. Calculate the sensitivity to length and multiple and feed it into the Lesson 276 quantity limits

Go back to the hypothetical stock of Lesson 276. The planned entry price is $100, the usual planned loss budget $500, round-trip commission $0.20 per share, and a position weight limit of 100 shares. Assume no earnings release during the holding period, so the event limit is left out; as in Lesson 276, the cash and dollar volume limits do not bind. If this stock's ATR is $3.20 over 5 periods, $2.50 over 14 periods and $2.10 over 50 periods, setting the stop-loss level by ATR multiple alone gives these quantities.

Setting Stop-loss level Planned loss per share Quantity under the loss limit Final quantity
14 periods × 1.5 100 − 3.75 = $96.25 $3.95 floor(500 ÷ 3.95) = 126 shares 100 shares
14 periods × 2 100 − 5.00 = $95.00 $5.20 floor(500 ÷ 5.20) = 96 shares 96 shares
14 periods × 3 100 − 7.50 = $92.50 $7.70 floor(500 ÷ 7.70) = 64 shares 64 shares
5 periods × 2 100 − 6.40 = $93.60 $6.60 floor(500 ÷ 6.60) = 75 shares 75 shares
50 periods × 2 100 − 4.20 = $95.80 $4.40 floor(500 ÷ 4.40) = 113 shares 100 shares

The final quantity is the smaller of the quantity under the loss limit and the weight limit of 100 shares. With the same $500 budget, the quantity moves from 64 to 100 shares. Changing the multiple from 2 to 3 takes 96 shares to 64 shares, a cut of one third, and changing the ATR length from 14 to 5 gives 75 shares, about 22% fewer. The 1.5 times and 50-period settings hit the weight limit and cannot use the whole loss budget.

Now, in the order of section 5, use the structural level first. If the Lesson 276 stop-loss level of $94 is just below the prior confirmed low, the distance is (100 − 94) ÷ 2.50 = 2.4 ATR. That is within the range of 1.5 to 4, so keep the level and, as in Lesson 276, compare floor(500 ÷ 6.20) = 80 shares with the other limits. The ATR does not set the stop-loss level; it screens out trades where the level is too close or too far.

Attach the distance of section 2 as a chase limit. If the 20-day line on the signal day is $95.60, the distance is (100 − 95.60) ÷ 2.50 = 1.76 ATR. For example, you might set in advance that above 3 ATR you do not place the order even with a signal. Written on one card, the assembled rule looks like this. All lengths and multiples on the card are examples; readers set and write their own values from their own records.

Filter: close above the 50-day line, 50-day line not lower than the day before. Signal: close crosses above the 20-day line. Chase limit: distance from the 20-day line at most 3 ATR. Stop-loss: below the prior confirmed low, distance 1.5 to 4 ATR (14 periods, Wilder method). Quantity: the smallest of the five Lesson 276 limits.

The record for this lesson is this rule card with the sensitivity table attached below it. Each time you change the average length, the ATR length or the multiple, recompute the signal date, the stop-loss level and the quantity and keep them with the date. If you changed a number after seeing results, write it as a new version.

Try it yourself

  1. For a hypothetical stock with a 14-period ATR of $1.40, three days produced the following prices. Day one: prior close $50.00, high $51.20, low $49.52. Day two: prior close $50.80, high $53.90, low $52.70. Day three: prior close $53.60, high $52.10, low $51.22. Find the TR and ATR for each day.
  2. Hypothetical Dasom is at $18 with an ATR of $0.72, and Raon at $420 with an ATR of $9.24. Find the ATR ratios of the two stocks, and how many percent below the price a 2 ATR stop-loss level sits. Using the section 6 budget of $500, round-trip costs of $0.20 per share and a position weight limit of $10,000, what are the quantities?
  3. For the stock of section 6, if you set the stop-loss level at 2.5 times the 14-period ATR, what are the level and the quantity?
  4. For the stock of section 1, the close on trading day 20 after the bottom is $110. Find the daily changes of the 20-day and 50-day lines that day, and write whether each rises or falls.

Answers

First, on day one the high minus the low, $1.68, is the largest, so the TR is $1.68. Day two is a gap up, so the TR is the high's difference of $3.10 from the prior close; day three is a gap down, so the TR is the low's difference of $2.38 from the prior close. The ATRs are (1.40 × 13 + 1.68) ÷ 14 = $1.42, (1.42 × 13 + 3.10) ÷ 14 = $1.54 and (1.54 × 13 + 2.38) ÷ 14 = $1.60. Day two's TR was more than twice the ATR, but the ATR rises only $0.12.

Second, the ATR ratios are Dasom 0.72 ÷ 18 × 100 = 4.0% and Raon 9.24 ÷ 420 × 100 = 2.2%. 2 ATR is $1.44 for Dasom, 8.0% of the price, and $18.48 for Raon, 4.4% below. Dasom is floor(500 ÷ 1.64) = 304 shares, and 304 × 18 = $5,472, within the weight limit. Raon is floor(500 ÷ 18.68) = 26 shares, but 26 × 420 = $10,920 exceeds the limit, so floor(10,000 ÷ 420) = 23 shares. For a stock with a low ATR ratio, the weight limit tends to bind before the loss limit.

Third, 2.50 × 2.5 = $6.25, so the stop-loss level is $93.75. The planned loss per share is $6.45, and floor(500 ÷ 6.45) = 77 shares. That is 19 shares fewer than the 96 shares at 2 times.

Fourth, the 20-day line rises (110 − 90) ÷ 20 = $1.00. The 50-day line is (110 − 120) ÷ 50 = −$0.20, so it is still falling. Even when the price has been rising for 20 trading days, the 50-day line falls if the price of 50 trading days ago was higher.

Related lessons