Determining whether the Relative Strength (RS) of a stock or asset is bullish or bearish relative to a base ticker (such as SPY) involves analyzing the trend, momentum, and price action of the RS line. Here are the key methods to assess RS:
1. Trend Analysis of the RS Line
Bullish RS: The RS line is trending upward, indicating the stock is outperforming SPY.
Bearish RS: The RS line is trending downward, indicating the stock is underperforming SPY.
2. Price vs. RS Divergence
Bullish Divergence: If the stock price makes a higher low while the RS line also makes a higher low, it suggests strengthening relative performance.
Bearish Divergence: If the stock price makes a lower high while the RS line makes a lower high, it suggests weakening relative performance.
3. Moving Averages of RS
Bullish RS: The RS line is above its moving average (e.g., 20-day, 50-day).
Bearish RS: The RS line is below its moving average.
4. RS Line vs. Zero Line
Bullish RS: The RS line is above zero, meaning the stock is outperforming SPY.
Bearish RS: The RS line is below zero, meaning the stock is underperforming SPY.
5. Breakouts & Breakdowns
Bullish Breakout: The RS line breaks above a resistance level, signaling improving relative strength.
Bearish Breakdown: The RS line breaks below a support level, signaling weakening relative strength.
If the stock’s RS is stronger than its sector’s RS, it suggests bullish relative strength.
If the stock’s RS is weaker than its sector’s RS, it suggests bearish relative strength.
8. Volume Confirmation
Bullish RS: Rising RS with increasing volume in the stock.
Bearish RS: Falling RS with decreasing volume in the stock.
Example Interpretation
If AAPL/SPY RS is rising while SPY is flat or falling, AAPL is bullish relative to SPY.
If TSLA/SPY RS is falling while SPY is rising, TSLA is bearish relative to SPY.
Conclusion
To determine if RS is bullish or bearish:
✅ Check the trend (up = bullish, down = bearish).
✅ Compare with moving averages (above = bullish, below = bearish).
✅ Look for divergences (higher lows = bullish, lower highs = bearish).
✅ Use RSI on RS (above 50 = bullish, below 50 = bearish).
Would you like a specific example with a stock?
User
yes show example with calculation or visual
Assistant
Here’s a step-by-step example with calculations and a visual representation of Relative Strength (RS) analysis for NVIDIA (NVDA) vs. SPY to determine if it's bullish or bearish.
Step 1: Calculate Relative Strength (RS)
The RS line is simply the ratio of the stock price to the benchmark (SPY):
Jan 4-5: RS recovers to 1.273 (Potential bullish continuation).
User
show tradingview example
Assistant
Here’s a TradingView-style example of Relative Strength (RS) analysis for NVIDIA (NVDA) vs. SPY, including a visual chart and key indicators to determine if the RS is bullish or bearish.
TradingView Chart Example
(Hypothetical but realistic setup)
1. Price Chart Setup
Top Panel: NVDA (blue) vs. SPY (red, overlay).
Bottom Panel: RS Line (NVDA/SPY) with key indicators.
[image: TradingView RS Example] open(Example link, not real)
(Since I can't embed live charts, I'll describe the key elements visually.)
Key Components of the Chart
1. RS Line Calculation
Formula: RS = NVDA / SPY
Plotted as a line chart in the bottom panel.
2. Moving Averages on RS Line
20-day MA (orange line) – Smooths the RS trend.
50-day MA (purple line) – Longer-term trend filter.
3. RSI of RS Line (Momentum)
RSI(14) applied to RS (not price).
>50 = Bullish momentum.
<50 = Bearish momentum.
4. Zero Line (Baseline)
RS > 1.0 → NVDA outperforming SPY.
RS < 1.0 → NVDA underperforming SPY.
Example Scenario (Bullish vs. Bearish RS)
Bullish RS Setup
RS Line: Rising above 20 & 50 MA.
RSI of RS: >50 (e.g., 60).
Price Action: NVDA making higher highs while SPY is flat or falling.
Visual Cues:
User
in amibroker, is the time series forecast function tsf(close, x), the same as LinearReg(Close, x )+LinRegSlope(Close, x)?
Assistant
In AmiBroker, the Time Series Forecast (TSF) function and the combination of Linear Regression (LinearReg) with its slope (LinRegSlope) are related but not exactly the same. Here’s a detailed breakdown:
1. TSF(Close, x)
Purpose: The TSF function performs a time series forecast using an autoregressive moving average (ARMA) model (or similar statistical method) to predict future values based on past data.
Behavior:
It smooths the data and extrapolates future values.
The x parameter determines the lookback period (how many bars are used for forecasting).
It is not purely linear—it accounts for more complex patterns than a simple linear regression.
2. LinearReg(Close, x) + LinRegSlope(Close, x)
Purpose: This combination calculates:
LinearReg(Close, x): The linear regression line (best-fit line) over x bars.
LinRegSlope(Close, x): The slope of that regression line (rate of change).
Behavior:
The sum LinearReg + LinRegSlope gives a linear extrapolation of the trend.
It assumes a strict linear relationship (no curvature or higher-order trends).
It is simpler than TSF and does not account for autoregressive components.
Key Differences
Feature
TSF(Close, x)
LinearReg(Close, x) + LinRegSlope(Close, x)
Model
ARMA-like (statistical forecasting)
Pure linear regression
Complexity
More sophisticated (can capture trends + mean reversion)
TSF will often appear smoother and may deviate from the linear combination.
The linear version (LinearReg + Slope) will follow a straight-line projection.
When to Use Which?
Use TSF if you want a forecast with smoothing (e.g., for predictive indicators).
Use LinearReg + Slope if you need a pure linear trend (e.g., for trend-following strategies).
Would you like a real-world comparison with a stock chart? I can simulate how these functions behave differently in practice. 📊
User
show afl code that equivalent to the builtin function tsf()
Assistant
In AmiBroker, the built-in TSF() function is a time series forecast that uses an autoregressive moving average (ARMA) model (or similar statistical method) to predict future values. While AmiBroker does not provide the exact internal implementation of TSF(), we can approximate it using linear regression with autoregressive components or exponential smoothing.
Below is an AFL (AmiBroker Formula Language) approximation of TSF() using a weighted moving average (WMA) combined with linear regression, which mimics the smoothing and forecasting behavior of TSF().
AFL Code: Approximation of TSF()
amibroker
// AFL Approximation of TSF(Close, x)
// Uses a combination of Linear Regression and Exponential Smoothing
function CustomTSF( array, period )
{
// Step 1: Linear Regression (Trend Component)
linReg = LinearReg( array, period );
// Step 2: Exponential Smoothing (Smoothing Component)
alpha = 2 / ( period + 1 ); // Smoothing factor
expSmooth = EMA( array, period );
// Step 3: Combine Trend + Smoothing (Approximates TSF)
tsfApprox = linReg + ( expSmooth - linReg ) * alpha;
return tsfApprox;
}
// Example Usage
period = 20; // Same as TSF(Close, 20)
Plot( TSF( Close, period ), "Built-in TSF", colorBlue, styleLine );
Plot( CustomTSF( Close, period ), "Custom TSF Approximation", colorRed, styleLine );
How This Works
Linear Regression (LinearReg)
Captures the trend (like LinRegSlope).
Exponential Smoothing (EMA)
Adds smoothing to reduce noise (similar to ARMA in TSF).
User
cannot use variable name if a function has the same name
Assistant
You're absolutely right! In AmiBroker AFL, you cannot use a variable name that conflicts with a built-in function name (like TSF). To fix this, we should rename the custom function to avoid naming conflicts.
Here’s the corrected AFL code that approximates TSF() without naming conflicts:
Corrected AFL Code (No Naming Conflicts)
amibroker
// AFL Approximation of TSF() - Avoids naming conflicts
function ApproximateTSF( array, period )
{
// Step 1: Linear Regression (Trend Component)
linReg = LinearReg( array, period );
// Step 2: Exponential Smoothing (Smoothing Component)
alpha = 2 / ( period + 1 ); // Smoothing factor
expSmooth = EMA( array, period );
// Step 3: Combine Trend + Smoothing (Approximates TSF)
tsfApprox = linReg + ( expSmooth - linReg ) * alpha;
return tsfApprox;
}
// Example Usage
period = 20; // Same as TSF(Close, 20)
Plot( TSF( Close, period ), "Built-in TSF", colorBlue, styleLine );
Plot( ApproximateTSF( Close, period ), "Custom TSF Approximation", colorRed, styleLine );
Key Fixes
Renamed the function from CustomTSF to ApproximateTSF to avoid conflict with TSF().
Kept the logic the same (Linear Regression + EMA blending).
Plotted both for comparison.
Alternative: Using HoltWinters() for Better Forecasting
If you want a more accurate forecast, you can use Holt-Winters Exponential Smoothing (no naming conflict):
amibroker
// Using Holt-Winters (built-in, no naming conflict)
Plot( HoltWinters( Close, 20 ), "Holt-Winters Forecast", colorGreen, styleLine );
Final Notes
✅ Avoid using built-in function names (e.g., TSF, EMA, LinearReg) as variable/function names.
✅ Use descriptive names like ApproximateTSF or MyCustomForecast.
✅ For best results, compare TSF() with HoltWinters() or the custom approximation.
Would you like a backtest comparison between these methods? 📊
Dataset releases
Not yet included in a published release.
Step 3: Determine Bullish or Bearish RS
1. Trend of RS Line
Bullish: RS is rising (Jan 1-3).
Bearish: RS is falling (Jan 3-4).
2. Moving Average (MA) of RS
If we apply a 3-day MA to RS:
Jan 3 MA: ( (1.25 + 1.268 + 1.309) / 3 = 1.276 )
Jan 4 MA: ( (1.268 + 1.309 + 1.256) / 3 = 1.278 )
Jan 5 MA: ( (1.309 + 1.256 + 1.273) / 3 = 1.279 )
RS vs. MA:
Jan 3: RS (1.309) > MA (1.276) → Bullish
Jan 4: RS (1.256) < MA (1.278) → Bearish
Jan 5: RS (1.273) < MA (1.279) → Still Bearish
3. RSI of RS Line (Momentum Check)
Calculate RSI(3) for the RS line:
Jan 3: RSI = 70 (Overbought, but bullish).
Jan 4: RSI = 30 (Oversold, bearish).
Jan 5: RSI = 55 (Neutral, but recovering).
4. Price vs. RS Divergence
If NVDA makes a higher high but RS makes a lower high, it’s bearish divergence (weakening relative strength).
If NVDA makes a lower low but RS makes a higher low, it’s bullish divergence (strengthening relative strength).