The video below provides a step-by-step guide to creating a flow that calculates the Relative Strength Index (RSI), a widely used indicator in day trading. The process is designed for integration with algorithmic trading setups, specifically utilizing Alpaca’s API and Node-RED for workflow automation.
Getting Started
The lesson begins with accessing the learner’s account and downloading three essential files: Market Open, Calculate RSI, and Web Links for Downloads. These files are then uploaded into the instance where the flow will be constructed.
Setting Up the Flow
The RSI flow starts with an inject node, which initializes the process. A function node is used to check whether the market is open by referencing global variables. If the market is open, a symbol (e.g., Nvidia) is selected for trading. The next step involves retrieving the latest trade data using Alpaca’s last trade node, connected to a paper trading account.
To track price changes, a display prices node is introduced. It extracts price data from Alpaca’s payload and stores two key values:
1. Current Price – retrieved from the last trade data.
2. Previous Price – stored and updated after each cycle.
The system updates the previous price dynamically, ensuring the next iteration has historical data for RSI calculations. This cycle is designed to run every 10 seconds, though the interval can be adjusted based on trading needs.
Calculating RSI
The RSI calculation node contains detailed documentation and follows the standard 14-period look-back window. The RSI formula measures the ratio of average gains to average losses over the specified time frame.
Key steps in the RSI calculation:
1. Extract Price Differences – Compute the difference between the current and previous price.
2. Determine Gains and Losses – Separate positive (gains) and negative (losses) price changes.
3. Calculate Moving Averages – Smooth the gains and losses over 14 periods.
4. Compute RSI – Using the formula:
RSI = 100 - \frac{100}{1 + ( \frac{Avg\ Gain}{Avg\ Loss})}
5. Store Results – The RSI values are stored in a database for further analysis.
The RSI results are displayed and updated in real time, allowing traders to monitor trends and adjust their strategy accordingly.
Visualizing the Data
The lesson concludes with instructions on downloading and analyzing RSI data:
• The stored RSI values are retrieved from the system’s database.
• Data is exported as a table with timestamps.
• A price vs. RSI chart is created, showing correlations between stock movements and RSI signals.
Key insights from the chart:
• RSI above 70 typically signals an overbought condition (potential sell opportunity).
• RSI below 30 indicates an oversold condition (potential buy opportunity).
• The effectiveness of RSI is not absolute, requiring testing and adjustments to optimize trading strategies.
Conclusion
This lesson provides a practical approach to implementing RSI in algorithmic trading. While RSI is a widely used indicator, it is not foolproof and requires careful tuning. Users are encouraged to experiment with parameters and analyze results to enhance trading accuracy.
Additionally, the lesson touches briefly on related topics like artificial intelligence (AI), machine learning (ML), and deep learning, highlighting their roles in financial modeling and trading automation.