Skip to content

ROC with Bands ​

Rate of Change (ROC) with Bands, created by Vitali Apirine, is a volatility banded variant of Rate of Change (ROC). [Discuss] 💬

csharp
// C# usage syntax
IReadOnlyList<RocWbResult> results =
  bars.ToRocWb(lookbackPeriods, emaPeriods, stdDevPeriods);

Parameters ​

paramtypedescription
lookbackPeriodsintNumber of periods (N) to go back. Must be greater than 0. Typical values range from 10-20.
emaPeriodsintNumber of periods for the ROC EMA line. Must be greater than 0. Standard is 3.
stdDevPeriodsintNumber of periods the standard deviation for upper/lower band lines. Must be greater than 0 and not more than lookbackPeriods. Standard is to use same value as lookbackPeriods.

Historical price bars requirements ​

You must have at least N+1 periods of bars to cover the warmup periods.

bars is a collection of generic TBar historical price bars. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

Response ​

csharp
IReadOnlyList<RocWbResult>

RocWbResult ​

propertytypedescription
TimestampDateTimeDate from evaluated TBar
RocdoubleRate of Change over N lookback periods (%, not decimal)
RocEmadoubleExponential moving average (EMA) of Roc
UpperBanddoubleUpper band of ROC (overbought indicator)
LowerBanddoubleLower band of ROC (oversold indicator)

Utilities ​

See Utilities and helpers for more information.

Streaming ​

Use the buffer-style List<T> when you need incremental calculations without a hub:

csharp
RocWbList rocWbList = new(lookbackPeriods, emaPeriods, stdDevPeriods);

foreach (IBar bar in bars)  // simulating stream
{
  rocWbList.Add(bar);
}

// based on `ICollection<RocWbResult>`
IReadOnlyList<RocWbResult> results = rocWbList;

Subscribe to a BarHub for advanced streaming scenarios:

csharp
BarHub barHub = new();
RocWbHub observer = barHub.ToRocWbHub(lookbackPeriods, emaPeriods, stdDevPeriods);

foreach (IBar bar in bars)  // simulating stream
{
  barHub.Add(bar);
}

IReadOnlyList<RocWbResult> results = observer.Results;

See Buffer lists and Stream hubs for full usage guides.

Chaining ​

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

csharp
// example
var results = bars
    .Use(CandlePart.HL2)
    .ToRocWb(..);

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

csharp
// example
var results = bars
    .ToRocWb(..)
    .ToEma(..);

See Chaining indicators for more.