Skip to content

Price Relative Strength (PRS) ​

Price Relative Strength (PRS), also called Comparative Relative Strength, shows the ratio of two bar histories, based on price. It is often used to compare against a market index or sector ETF. When using the optional lookbackPeriods, this also returns relative percent change over the specified periods. This is not the same as the more prevalent Relative Strength Index (RSI). [Discuss] 💬

Indicator style

csharp
// C# usage syntax
IReadOnlyList<PrsResult> results =
  barsEval.ToPrs(barsBase);

Create a buffer list. Add each series separately as its values arrive; either one may run ahead, and a result is added once both hold the same timestamp:

csharp
PrsList prsList = new(lookbackPeriods);

// call from each series' message handler
void OnEvalReceived(IReusable value) => prsList.AddSource(value);
void OnBaseReceived(IReusable value) => prsList.AddOther(value);

// the list itself holds the results; fills as the handlers run
IReadOnlyList<PrsResult> results = prsList;

A timestamp that only one series holds produces no result, where the Series method throws. Each series must arrive in strictly increasing order: an older or equal timestamp on a side throws an InvalidOperationException. Each side stages at most MaxListSize values, so a side that falls further behind than that loses the pairs the leading side has dropped.

See Buffer lists for the full usage guide.

Subscribe to a BarHub for each series and add bars as they arrive:

csharp
BarHub evalHub = new();
BarHub baseHub = new();
PrsHub observer = evalHub.ToPrsHub(baseHub, lookbackPeriods);

// call from each series' message handler
void OnEvalReceived(IBar bar) => evalHub.Add(bar);
void OnBaseReceived(IBar bar) => baseHub.Add(bar);

// results fill as the handlers run
IReadOnlyList<PrsResult> results = observer.Results;

A result is added once both providers hold the same timestamp. A value that arrives late, or is revised or removed, on either side is handled by the usual rebuild. Timestamps match exactly, and PrsPercent looks back N matched timestamps. Drive both providers from one thread at a time.

Omit lookbackPeriods (new PrsList() or .ToPrsHub(baseHub)) to skip PrsPercent, as the Series method does.

See Stream hubs for the full usage guide.

Parameters ​

paramdescription
sourceEval
IReadOnlyList<IReusable>
Historical price bars used as the evaluation subject. You must have the same number of periods as sourceBase.
sourceBase
IReadOnlyList<IReusable>
Historical price bars used as the benchmark basis for comparison. This is usually market index data. You must have the same number of periods as sourceEval.
lookbackPeriods
int
Optional. Number of periods (N) to lookback to compute % ROC difference. Must be greater than 0 if specified; omit it for no lookback.

Historical price bars requirements ​

You must have at least N+1 periods of price bars to calculate PrsPercent if lookbackPeriods is specified; otherwise, you must specify at least 2 periods. More than the minimum is typically specified.

sourceEval and sourceBase must have consistent frequency (day, hour, minute, etc). Mismatch histories will throw InvalidBarsException. See the Guide for more information.

Response ​

csharp
IReadOnlyList<PrsResult>
  • This method returns a time series of all available indicator values for the bars provided.
  • It always returns the same number of elements as there are in the historical price bars.
  • It does not return a single incremental indicator value.
  • The N periods will have null values for PrsPercent since there's not enough data to calculate.
csharp
PrsList : IReadOnlyList<PrsResult>
  • The list itself holds the results, one for each timestamp both series hold, in timestamp order.
  • It keeps up to 100,000 results by default and drops the oldest beyond that; set MaxListSize to keep fewer.
  • The N periods will have null values for PrsPercent since there's not enough data to calculate.
csharp
IReadOnlyList<PrsResult> results = observer.Results;
  • observer.Results holds the results, one for each timestamp both providers hold, in timestamp order.
  • Results update as bars arrive, including bars that arrive late or are revised.
  • The cache keeps up to 100,000 results by default; set maxCacheSize on the BarHub to keep fewer.
  • The N periods will have null values for PrsPercent since there's not enough data to calculate.

PrsResult ​

propertydescription
Timestamp
DateTime
Date from evaluated TBar
Prs
double?
Price Relative Strength is the ratio of Eval / Base price values
PrsPercent
double?
Percent change difference between Eval and Base over N periods

Example

At period i, Prs is Eval[i] / Base[i] and PrsPercent is the difference in Eval percent change and Base percent change over the prior N periods. Example: if Eval gains 10% and Base gains 3%, PrsPercent depicts +7% relative outperformance.

Chaining ​

This indicator may be generated from any chain-enabled indicator or method.

csharp
// example
var results = barsEval
    .Use(CandlePart.HL2)
    .ToPrs(barsBase, ..);

🚩 Matching inputs required

Both sourceEval and sourceBase arguments must contain the same number of elements and be the results of a chainable indicator or .Use() method.

Results can be further processed on Prs with additional chain-enabled indicators.

csharp
// example
var results = barsEval
    .ToPrs(barsBase, ..)
    .ToSlope(..);

See Chaining indicators for more.

Add each series from the results of other chain-enabled buffer lists with AddSource and AddOther. When a new result appears in this list, add it to the next chain-enabled buffer list yourself.

See Chaining buffer lists for more.

Subscribe other chain-enabled hubs to it to process Prs further.

csharp
// example
SlopeHub observer = evalHub
    .ToPrsHub(baseHub, ..)
    .ToSlopeHub(..);

See Chaining stream hubs for more.

Utilities ​

Call these on the list itself, as in prsList.Find(lookupDate). .Condense() returns a new list and leaves prsList unchanged.

Warmup removal is left out. Once the list is full it drops its oldest results, so trimming by position would remove valid values.

Call these on observer.Results, as in observer.Results.Find(lookupDate). .Condense() returns a new list and leaves the hub's results unchanged.

Warmup removal is left out. Once the cache is full the hub drops its oldest results, so trimming by position would remove valid values.

See Utilities and helpers for more information.