Here’s how you can calculate EMA5 (5-period Exponential Moving Average) and RSI (Relative Strength Index) in Google Sheets, using stock data such as that from Google Finance.
🟢 1. Pull Stock Price Data (optional)
First, get historical data for a stock like Google (Alphabet Inc.):
=GOOGLEFINANCE("GOOG", "close", TODAY()-30, TODAY(), "DAILY")
This will give you dates and closing prices for the past 30 days.
Assume Column A has dates and Column B has closing prices.
🟡 2. EMA5 Formula in Google Sheets
To calculate a 5-period EMA, use this formula starting from row 6 in, say, Column C:
Initial SMA (used for first EMA value in Row 6):
=AVERAGE(B2:B6)
Put that in C6. Then use this formula from C7 downward:
=C6 + (2 / (5 + 1)) * (B7 - C6)
Explanation:
- 5 is the EMA period.
2 / (n + 1) is the multiplier.
Drag down to fill the rest of Column C.
🔵 3. RSI Formula (14-period is standard)
Let’s assume closing prices are in Column B starting at B2.
We’ll calculate RSI(14) in steps, assuming values from Row 2 onward.
Step 1: Price Change
In D3:
=B3 - B2
Then drag down.
Step 2: Separate Gains and Losses
In E3 (Gain):
=IF(D3>0,D3,0)
In F3 (Loss):
=IF(D3<0,ABS(D3),0)
Drag both down as well.
Step 3: Average Gain/Loss using EMA (Recommended)
In G15 (Average Gain, after 14 data points):
=AVERAGE(E2:E15)
In H15 (Average Loss):
=AVERAGE(F2:F15)
Then from row 16 down:
In G16:
=(G15*13 + E16)/14
In H16:
=(H15*13 + F16)/14
Step 4: RSI Calculation
In I16:
=IF(H16=0, 100, 100 - (100 / (1 + (G16 / H16))))
Drag this RSI formula down. Values will normalize after enough data points (~15+ rows).
✅ Optional: Label Your Columns
- A = Date
- B = Close Price
- C = EMA5
- D = Change
- E = Gain
- F = Loss
- G = Avg Gain
- H = Avg Loss
- I = RSI
Let me know if you want a template Google Sheet or prefer using ARRAYFORMULA for automation.