Calculating a Wilder's Smoothed Relative Strength Index (Wilder's RSI) by hand is a fairly daunting task. Even a 2-period version is going to require a significant number of bars to calculate a decent approximation.
The technique given in the help files is as follows.
RSI is calculated using the following formula:
RSI = 100 - (100 / (1+RS))
RS = n period average of up closes / n period average of down closes
This is pretty much the method as described by Wilder, but I probably wouldn't use it personally if I had to do it by hand. Instead I would probably use the following.
RSI = 100 * n period average of up net changes in the close / n period average of absolute net changes in the close
The same details about how the moving averages are calculated applies.
In RSI, RS uses a simple average of the up and down closes. In Wilder's RSI, RS uses Wilder's smoothing which is a different form of exponential averaging. Wilder's smoothing = Previous MA value + (1/n periods * (Close - Previous MA))
Note that when taking the n period average of the up net changes, that negative or 0 net changes are still averaged in. You just need to use zero for the value being used.
Now the non-Wilder's smooth 2-period case for this is a fairly short formula and simple to calculate.
100 * (ABS(C > C1) * (C - C1) + ABS(C1 > C2) * (C1 - C2)) / (ABS(C - C1 + ABS(C - C2))
The ABS(C > C1) and ABS(C1 > C2) multiply C - C1 and C1 - C2 by 1 if true and 0 if false to create the number described in the algorithm I would use to calculate this by hand. C is the current close, C1 is the previous close and C2 is the close of 2 bars ago. I didn't divide the numerator and denominator by 2 to convert the sum into an average because it would cancel out.
The above formula is for the non-Wilder's Smoothed version of RSI. As mentioned in the definition in the help files, the Wilder's smoothed version uses a type of exponential moving average for its calculation instead of simple moving averages.
On the chart, we would start calculating exponential moving averages at the oldest bar (the very first bar of data available when scrolling back) and then get a new value for the numerator and denominator at each bar. This means the Wilder's Smoothed version of RSI uses all of the data on the chart to calculate its value. The older data is less significant to the calculations than the newer data however, so the contribution of the older data to the calculations eventually becomes small enough to ignore.
I am instead going to calculate the formula from the newest data to the oldest data until I get to a point where I feel I can safely ignore the older data. I'm going to go out far enough to include the close of 14 bars ago in the calculations, but you might want to go further.
100 * (ABS(C > C1) * (C - C1) + .5 * (ABS(C1 > C2) * (C1 - C2) + .5 * (ABS(C2 > C3) * (C2 - C3) + .5 * (ABS(C3 > C4) * (C3 - C4) + .5 * (ABS(C4 > C5) * (C4 - C5) + .5 * (ABS(C5 > C6) * (C5 - C6) + .5 * (ABS(C6 > C7) * (C6 - C7) + .5 * (ABS(C7 > C8) * (C7 - C8) + .5 * (ABS(C8 > C9) * (C8 - C9) + .5 * (ABS(C9 > C10) * (C9 - C10) + .5 * (ABS(C10 > C11) * (C10 - C11) + .5 * (ABS(C11 > C12) * (C11 - C12) + .5 * (ABS(C12 > C13) * (C12 - C13) + .5 * (ABS(C13 > C14) * (C13 - C14))))))))))))))) / (ABS(C - C1) + .5 * (ABS(C1 - C2) + .5 * (ABS(C2 - C3) + .5 * (ABS(C3 - C4) + .5 * (ABS(C4 - C5) + .5 * (ABS(C5 - C6) + .5 * (ABS(C6 - C7) + .5 * (ABS(C7 - C8) + .5 * (ABS(C8 - C9) + .5 * (ABS(C9 - C10) + .5 * (ABS(C10 - C11) + .5 * (ABS(C11 - C12) + .5 * (ABS(C12 - C13) + .5 * (ABS(C13 - C14)))))))))))))))
The structure of the formula is the same, but each older factor is multiplied by .5 since it only makes half the contribution to the result as the newer factor.
There would be a factor applied at the beginning of the numerator and denominator to calculate the average, but it cancels out since it is the same in both cases. If I were actually writing a formula and not doing this by hand, I would probably re-arrange things a bit to make the formula shorter.
50 * (C - XAVGC3.1) / 2 / (.50003052 * (ABS(C - C1) + .5 * (ABS(C1 - C2) + .5 * (ABS(C2 - C3) + .5 * (ABS(C3 - C4) + .5 * (ABS(C4 - C5) + .5 * (ABS(C5 - C6) + .5 * (ABS(C6 - C7) + .5 * (ABS(C7 - C8) + .5 * (ABS(C8 - C9) + .5 * (ABS(C9 - C10) + .5 * (ABS(C10 - C11) + .5 * (ABS(C11 - C12) + .5 * (ABS(C12 - C13) + .5 * (ABS(C13 - C14)))))))))))))))) + 50
The only new syntax in this formula in the XAVGC3.1 section which stands for a 3-period exponential moving average of the close.
Personal Criteria Formula Syntax
-Bruce Personal Criteria Formulas TC2000 Support Articles
|