0

I'm trying to calculate MACD and RSI formula in groovy. Regarding MACD, I've calculated up to MACD line but not able to calculate Signal line. Also does anyone have idea how to calculate RSI in groovy ? I know the RSI formula, RSI = 100 - 100/(1+RS) and RS = Avg Gain/ Avg Loss

But how to calculate Avg Gain and Avg Loss ? Can anyone explain with exact calculations ?

jdev1
  • 141
  • 2
  • 14

1 Answers1

1

This RSI calculation is based on 14 periods

The very first calculations for average gain and average loss are simple 14 period averages.

First Average Gain = Sum of Gains over the past 14 periods / 14.

First Average Loss = Sum of Losses over the past 14 periods / 14.

The second, and subsequent, calculations are based on the prior averages and the current gain loss:

Average Gain = [(previous Average Gain) x 13 + current Gain] / 14.

Average Loss = [(previous Average Loss) x 13 + current Loss] / 14.

If Average Loss equals 0, a "divide by zero" situation occurs for RS and RSI is set to 100 by definition. Similarly, RSI equals 0 when Average Gain equals zero.

GobyDot
  • 483
  • 3
  • 15
  • Yes I've seen these formulas.. But can you show me how to calculate "previous Average Gain" ? Or any excel calculations ? – jdev1 Mar 07 '14 at 09:49