Methods and evidence
Relative strength ranking and moving-average rules
A relative strength strategy compares instruments with one another, then chooses among those eligible for its portfolio. In PyInvesting, a moving-average screen and the selected ranking signals answer separate questions: may this instrument be considered, and how does it rank against the other candidates?
This guide explains the relative strength builder with invented observations. It reports no backtest return or live performance. Sign in to review your settings before running an experiment.
Define the screen and the ranking separately
With a Simple or Exponential moving-average screen, the strategy requires the latest usable price to be strictly above that average. Equality does not pass. The ranking then uses the signals, directions and weights you selected. A strong return rank cannot override a failed screen.
No Screen removes this moving-average comparison. It still requires usable prices and eligible factor data, and at least one ranking signal. It does not supply missing history or bypass data-quality checks. A long return lookback still needs the earlier observations used to calculate that return.
For a clean exercise, explicitly choose Simple, 200 periods, only 6 Month Returns with direction Highest and weight 100, two holdings and monthly rebalancing. Leave Cash Allocation off and leverage at 1. These are example settings: a fresh builder starts with a 120-period Exponential screen and a mixture of return, growth and valuation signals; a saved definition can restore different inputs.
A hypothetical decision at one rebalance
Assume four invented instruments have complete data and no other restrictions. The return ranks below compare all four for explanation; the actual portfolio selection ranks the eligible candidates. Prices and averages use the same consistent price basis.
| Instrument | Six-month return / rank | Price / 200-period average | Already held? | Target decision |
|---|---|---|---|---|
| A | 30% / 1 | 95 / 100: fails | Yes | Remove from the target portfolio despite the strongest return. |
| B | 20% / 2 | 110 / 100: passes | No | Enter the target portfolio as the highest-ranked eligible candidate. |
| C | 10% / 3 | 105 / 100: passes | Yes | Remain in the target portfolio as the second eligible candidate. |
| D | 5% / 4 | 100 / 100: fails | No | No entry: equality fails the strict screen. |
B and C receive equal target weights in this example. With No Screen and the same return signal, A and B would instead occupy the two places. Neither decision establishes the price at which a simulated order fills. Consult the completed trade record and execution assumptions.
Holding a stock does not exempt it from the rule
The relative strength screen uses the same price test for new and existing holdings. An existing holding can leave because it fails the screen or because stronger eligible candidates take the available places. A candidate that passes the screen can still miss the holdings cutoff. Changes are evaluated on the configured rebalance schedule; this is not a promise of an immediate intraday exit when a price crosses an average.
Portfolio target selection, the rebalance band, execution availability and the optional Cash Allocation setting affect different stages. With Cash Allocation off, fewer qualifying candidates can concentrate the target weights among those available; an empty selection leaves no stock targets. Do not infer a fixed cash percentage solely from the requested number of holdings.
Two other meanings that can cause confusion
Relative strength is not RSI. The example makes a cross-sectional comparison: it ranks six-month returns across instruments. The Relative Strength Index is an oscillator calculated from an individual price series' gains and losses. Choosing a return ranking does not silently introduce an RSI entry or exit threshold.
Historical-universe entry and exit ranks are another layer. In the optional historical US universe, these ranks control monthly membership by historical market capitalization. They are not the return ranks in the table and do not guarantee a portfolio position. Read the historical universe methodology before combining those settings.
Continue with the no-code backtest walkthrough, learn how to review a completed result or inspect the research and correction policy.
Prepared with AI assistance. PyInvesting is responsible for this guide; see our editorial policy for sources, limitations and corrections.