Of course! Here are the formulas for calculating a 5-period Exponential Moving Average (EMA5) and the Relative Strength Index (RSI) in Google Sheets, presented from a simple copy-paste solution to a detailed step-by-step guide.
Quick Copy-Paste Formulas
This assumes your data is set up as follows:
- Column A: Date
- Column B: Closing Price (with data starting in
B2)
EMA5 Formula (in Column C)
- In cell C6, enter this formula for the initial value (which is a Simple Moving Average):
=AVERAGE(B2:B6)
- In cell C7, enter the true EMA formula:
=(B7 * (2/(5+1))) + (C6 * (1-(2/(5+1))))
- Click on cell C7 and drag the little blue square (fill handle) down to the rest of your column.
RSI (14-period) Formula (in Column J)
The RSI calculation is more complex and is best done using several "helper" columns for clarity. We'll use the standard 14-period RSI.
-
Change (Column D): In cell D3, calculate the price change.
=IF(ISBLANK(B3),, B3-B2)
-
Gain (Column E): In cell E3, isolate the gains.
=IF(D3>0, D3, 0)
-
Loss (Column F): In cell F3, isolate the losses (as positive numbers).
=IF(D3<0, -D3, 0)
-
Avg Gain (Column G): The first value is a simple average, the rest are smoothed.
- In cell G16 (for a 14-period RSI, the first calculation is on the 14th change value):
=AVERAGE(E3:E16)
- In cell G17:
=((G16*13)+E17)/14
-
Avg Loss (Column H): Same logic as Avg Gain.
- In cell H16:
=AVERAGE(F3:F16)
- In cell H17:
=((H16*13)+F17)/14
-
RSI (Column I): Now calculate the final RSI.
- In cell I16:
=100-(100/(1+(G16/H16)))
-
Drag It All Down: Select cells D3:I3 and drag down to the end of your data. Then select cells G17:I17 (skipping the first simple average rows) and drag them down.
Detailed Step-by-Step Guide
This guide explains the logic and provides tips for a robust setup.
Setup Your Sheet
- Open your Google Sheet.
- Ensure you have at least two columns: Date (Column A) and Close (Column B).
- Enter your headers in row 1. Your price data should start from cell
B2.
Part 1: Calculating EMA5 (5-Period EMA)
The first EMA value requires a starting point, which is typically the Simple Moving Average (SMA) of the first 5 periods. After that, the exponential formula kicks in.
-
Add a Header: In cell C1, type EMA5.
-
Calculate the Initial SMA: The first 5 closing prices are in B2:B6. Therefore, the first EMA5 value will be in cell C6.
- In cell C6, enter the formula:
=AVERAGE(B2:B6)
-
Calculate the Subsequent EMA: Now, in the cell directly below (C7), we'll use the standard EMA formula which references the previous day's EMA (C6) and the current day's price (B7).
-
Fill Down the Formula:
- Click on cell C7.
- Move your cursor to the small blue square at the bottom-right corner of the cell (the fill handle).
- Click and drag it down to the end of your data. Google Sheets will automatically adjust the cell references for each row.
Part 2: Calculating RSI (14-Period RSI)
RSI is more involved. Using helper columns makes it transparent and easy to debug. We will calculate the standard 14-period RSI.
-
Add Headers: In cells D1, E1, F1, G1, H1, I1, type Change, Gain, Loss, Avg Gain, Avg Loss, and RSI respectively.
-
Column D: Price Change
- In cell D3, enter:
=IF(ISBLANK(B3),, B3-B2)
- Drag this formula down. This calculates the difference from the previous day's close.
-
Column E: Gain
- In cell E3, enter:
=IF(D3>0, D3, 0)
- Drag this formula down. This shows the change only if it was positive.
-
Column F: Loss
- In cell F3, enter:
=IF(D3<0, -D3, 0)
- Drag this formula down. This shows the absolute value of the change only if it was negative.
-
Columns G & H: Average Gain and Loss
This is a two-step process, just like the EMA. The first value is a simple average, and subsequent values are smoothed (using Wilder's Smoothing Method).
- Initial Average: We need 14 periods of gains/losses. Since our
Gain data starts at E3, our first 14 values are in the range E3:E16.
- In cell G16, enter:
=AVERAGE(E3:E16)
- In cell H16, enter:
=AVERAGE(F3:F16)
- Smoothed Average: For all subsequent rows, we use a smoothing formula.
- In cell G17, enter:
=((G16*13)+E17)/14
- In cell H17, enter:
=((H16*13)+F17)/14
- Select both G17 and H17 and drag them down.
-
Column I: RSI
Your final sheet will look something like this: