Percent Change (PCTCHANGE)

StratForge indicator page for change relative to a prior bar.

Route: /indicators/pctchange/

What It Does

stratforge::PctChange compares the current input with the value period bars earlier. Its output is a decimal ratio, not a number already multiplied by 100. Multiply by 100 only when displaying a percentage.

Formula and worked example

PctChange(t) = Price(t) / Price(t - period) - 1

For period = 2, input closes [100, 105, 120] produce (120 / 100) - 1 = 0.20, displayed as 20%. The first two bars have no value because the earlier comparison bar is unavailable. With the default period = 30, the first value needs 31 bars.

If the comparison price is zero, the implementation performs division without a special zero-denominator rule; the result can be non-finite. Check input data before using the value in a signal. A zero period compares the bar with itself and yields zero for nonzero prices.

Parameters

  • period — lookback offset in bars; default 30.

C++23 API

#include <stratforge/indicators/percentchange.hpp>
auto pctChange = std::make_unique<stratforge::PctChange>(data().close(), 30);

The example assumes a StratForge strategy with data() available and <memory> included. Checked implementation (revision d25404d, 2026-08-28).

Common Usage

  • Compare changes across assets with different price scales after checking for zero and missing inputs.
  • Pair the reading with trend or volatility context; the reading alone does not establish a trading edge.