
This 67-minute course shows you how use the visual programming language Node-Red and the MachineTrader platform to build RSI, EMA, MACD, and zScore indicators. In the first lesson, successful Wall Street Quant and PhD in Physics, Jerzy Pawlowsky, explains the theory and practice behind these popullar technical indicators. Subsequent lessons show you how to build working calculators using Node-Red.
Prerequisites:
You will need a MachineTrader account to try these out your own. MachineTrader offers a free 30-day free trial of a Learner's Account which then renews at $24.95 (USD)/month which should provide you plenty of time to test the platform before deciding to continue. You will also need a free paper trading account from Alpaca Markets in order to access time series data streams.
This lesson explores popular technical indicators used in quantitative trading, focusing on moving averages, MACD, Z-score, and RSI. These indicators help identify trends, detect overbought or oversold conditions, and refine trading strategies.
1. Moving Averages
A Simple Moving Average (SMA) is calculated by averaging prices over a set period. The look-back window length affects the responsiveness of the SMA:
• Longer look-back windows create smoother trends but introduce lag.
• Shorter look-back windows follow price movements more closely but generate more noise.
An alternative is the Exponential Moving Average (EMA), which applies greater weight to recent prices:
• The decay factor (λ) determines how much past data influences the EMA.
• Higher λ values create smoother EMAs but introduce lag.
• Lower λ values make the EMA track prices more closely but increase volatility.
2. MACD (Moving Average Convergence Divergence)
The MACD indicator measures the relationship between two EMAs:
• Fast EMA - Slow EMA = MACD Series.
• When the fast EMA crosses above the slow EMA, it indicates an uptrend.
• When the fast EMA crosses below, it signals a downtrend.
A third EMA, called the MACD Signal, smooths the MACD Series:
• MACD Divergence (MACD – MACD Signal) helps identify buy and sell opportunities.
• Reducing λ values makes the indicator react faster but increases false signals.
3. Price Z-Score
The Z-score quantifies how far the current price deviates from its historical average, helping to determine rich (overpriced) or cheap (underpriced) conditions:
• Z = (Current Price - EMA Price) / Volatility
• A high Z-score indicates overvaluation; a low Z-score suggests undervaluation.
• Increasing λ creates smoother, less volatile Z-scores.
• Lower λ allows the Z-score to track prices more closely but increases false signals.
4. Relative Strength Index (RSI)
The RSI measures price momentum and indicates overbought or oversold conditions:
• RSI = 100 - [100 / (1 + Average Gain / Average Loss)]
• RSI above 70 suggests overbought conditions (sell signal).
• RSI below 30 suggests oversold conditions (buy signal).
By adjusting λ, traders can fine-tune the RSI:
• Higher λ smooths RSI movements but delays signals.
• Lower λ makes RSI more sensitive to price changes but increases noise.
5. Trading Strategy Simulation
A basic RSI-based strategy is tested:
• Buy when RSI falls below a threshold (θ).
• Sell when RSI exceeds 1 - θ.
• The strategy maintains a long or short position based on RSI trends.
The Sharpe ratio comparison shows that:
• SPY ETF has a Sharpe ratio of 0.6.
• The RSI strategy achieved 0.8, suggesting better risk-adjusted returns.
• However, the strategy underperformed post-2017, indicating potential overfitting.
Conclusion
Technical indicators like SMA, EMA, MACD, Z-score, and RSI are valuable tools but require careful parameter tuning. They can improve trade timing, but overfitting risks mean strategies must be tested on new data to ensure effectiveness.
This lesson provides a step-by-step guide on 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.
The lesson begins with accessing your MachineTrader 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 automatio
This course explores popular technical indicators used in quantitative trading, focusing on moving averages, MACD, Z-score, and RSI. These indicators help identify trends, detect overbought or oversold conditions, and refine trading strategies.
1. Moving Averages
A Simple Moving Average (SMA) is calculated by averaging prices over a set period. The look-back window length affects the responsiveness of the SMA:
• Longer look-back windows create smoother trends but introduce lag.
• Shorter look-back windows follow price movements more closely but generate more noise.
An alternative is the Exponential Moving Average (EMA), which applies greater weight to recent prices:
• The decay factor (λ) determines how much past data influences the EMA.
• Higher λ values create smoother EMAs but introduce lag.
• Lower λ values make the EMA track prices more closely but increase volatility.
2. MACD (Moving Average Convergence Divergence)
The MACD indicator measures the relationship between two EMAs:
• Fast EMA - Slow EMA = MACD Series.
• When the fast EMA crosses above the slow EMA, it indicates an uptrend.
• When the fast EMA crosses below, it signals a downtrend.
A third EMA, called the MACD Signal, smooths the MACD Series:
• MACD Divergence (MACD – MACD Signal) helps identify buy and sell opportunities.
• Reducing λ values makes the indicator react faster but increases false signals.
3. Price Z-Score
The Z-score quantifies how far the current price deviates from its historical average, helping to determine rich (overpriced) or cheap (underpriced) conditions:
• Z = (Current Price - EMA Price) / Volatility
• A high Z-score indicates overvaluation; a low Z-score suggests undervaluation.
• Increasing λ creates smoother, less volatile Z-scores.
• Lower λ allows the Z-score to track prices more closely but increases false signals.
4. Relative Strength Index (RSI)
The RSI measures price momentum and indicates overbought or oversold conditions:
• RSI = 100 - [100 / (1 + Average Gain / Average Loss)]
• RSI above 70 suggests overbought conditions (sell signal).
• RSI below 30 suggests oversold conditions (buy signal).
By adjusting λ, traders can fine-tune the RSI:
• Higher λ smooths RSI movements but delays signals.
• Lower λ makes RSI more sensitive to price changes but increases noise.
5. Trading Strategy Simulation
A basic RSI-based strategy is tested:
• Buy when RSI falls below a threshold (θ).
• Sell when RSI exceeds 1 - θ.
• The strategy maintains a long or short position based on RSI trends.
The Sharpe ratio comparison shows that:
• SPY ETF has a Sharpe ratio of 0.6.
• The RSI strategy achieved 0.8, suggesting better risk-adjusted returns.
• However, the strategy underperformed post-2017, indicating potential overfitting.
Conclusion
Technical indicators like SMA, EMA, MACD, Z-score, and RSI are valuable tools but require careful parameter tuning. They can improve trade timing, but overfitting risks mean strategies must be tested on new data to ensure effectiveness.