RSI calculator for stocks workflow

Im trying to create a workflow that will generate the RSI for a set of market data.
I had a few questions that were answered in another thread.

Im a bit stuck on the second part of the operation. Im confident that it can be done using column expressions node but the conditions are eluding me. the requirement is this transformation.

  • First Average UM= sum of upward movement over the past 14 periods / 14.

  • First Average DM= Sum of downward movement over the past 14 periods / 14

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

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

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

The idea is to just have 1 row with the average of the first 14 values, and then use a lag node for the remaining averages. (not sure if this is the way to go).

TEST RSI.knwf (12.4 KB)

I have uploaded my workflow. (finding seemingly simple transformations challenging :cry: will try researching and using brain more :smile:)

thanks in advance!

Hi,

Please find a solution in the workflow attached.

I couldn’t use your workflow because the data was not available, but I used the workflow prepared by Gabriel here Need help (very new to this field) with some more realistic price data. I also added a counter to the data to show the day number using the Counter Generation node.

I first changed the upward and downward movements to percentages in the expressions inside the Math Formula nodes. Then I calculated the moving average over a period of 14 days using the Moving Average node.

Then I lagged these gains by one row using the Lag Column node.

Finally I calculated the first, second, etc. RSIs using the Column Expressions node with the following code inside:

day = column("Counter")
RSI = null

if (day = 15)
    RSI = 100 - (100/(1+(column("MA(Upward movement)")/14)/(column("MA(Downward Movement)")/14)))

if (day > 15)
    RSI = 100 - (100/(1+(column("MA(Upward movement)(-1)")*13+column("Upward movement"))/(column("MA(Downward Movement)(-1)")*13+column("Downward Movement"))))

RSI Calculation.knwf (18.2 KB)

Please check if the formulas are correct! Especially the division by 14 in the first RSI. I took the formula from here: https://www.investopedia.com/terms/r/rsi.asp

I hope this helps!

Maarit

2 Likes