Technical Equations
Explore the mathematical foundations of trading indicators.
Simple Moving Average (SMA)
The Formula
The Simple Moving Average is calculated as:
Where \( P_i \) is the price at period \( i \), and \( n \) is the number of periods.
Example with Real Numbers
Let's calculate a 5-day SMA:
Stock prices over 5 days:
- Day 1: $10
- Day 2: $12
- Day 3: $11
- Day 4: $13
- Day 5: $14
Step 1: Add all the prices together
$10 + $12 + $11 + $13 + $14 = $60
Step 2: Divide by the number of days (5)
$60 ÷ 5 = $12
Answer: The 5-day SMA is $12
Relative Strength Index (RSI)
The Formula
The RSI is calculated as:
Where \( RS = \frac{\text{Average Gain}}{\text{Average Loss}} \) over \( n \) periods (typically 14).
Example with Real Numbers
Simplified 5-day RSI example:
Price changes over 5 days:
- Day 1: +$2 gain
- Day 2: +$3 gain
- Day 3: -$1 loss
- Day 4: +$1 gain
- Day 5: -$2 loss
Step 1: Calculate average gain
($2 + $3 + $1) ÷ 5 = $1.20
Step 2: Calculate average loss
($1 + $2) ÷ 5 = $0.60
Step 3: Calculate RS
$1.20 ÷ $0.60 = 2.0
Step 4: Calculate RSI
100 - (100 ÷ (1 + 2.0)) = 100 - 33.33 = 66.67
Answer: The RSI is 66.67 (above 50 suggests bullish momentum)
Average True Range (ATR)
The Formula
The ATR is calculated as:
Where \( TR_i = \max(H_i - L_i, |H_i - C_{i-1}|, |L_i - C_{i-1}|) \), with \( H_i \), \( L_i \), and \( C_{i-1} \) being the high, low, and previous close prices.
Example with Real Numbers
Calculate a 3-day ATR:
Day 1: High=$15, Low=$12, Previous Close=$13
Find the biggest of these three:
• High - Low = $15 - $12 = $3 ✓ Biggest!
• High - Prev Close = $15 - $13 = $2
• Prev Close - Low = $13 - $12 = $1
Day 1 True Range = $3
Day 2: High=$17, Low=$14, Previous Close=$15
True Range = $3
Day 3: High=$16, Low=$13, Previous Close=$16
True Range = $3
Final Step: Average the 3 True Ranges
($3 + $3 + $3) ÷ 3 = $3
Answer: The 3-day ATR is $3 (higher ATR = more volatility)