Systemicbeta

Confirmed Peak / Trough

systemic:core-pivotIndicators

Inputs

NameTypeDescription
Confirmation BarsWhole numberThe number \(N\) of values that a peak or trough must stand against on each side, a constant whole number of at least 1.
SeriesNumber seriesThe numeric series whose turning points you want to study, for example a price, a daily high or low, or an indicator value.

Outputs

NameTypeDescription
Last PeakNumber seriesThe value of the most recent **confirmed** swing high, in the unit of the Series input.
Last TroughNumber seriesThe value of the most recent **confirmed** swing low, in the unit of the Series input.

Cost

12
credits per run
1,000
bars

0.212 + 0.0113·n credits for n bars, rounded up. The marks are each plan's limit of bars.

A price can look like a turning point today and be passed tomorrow. Confirmed Peak / Trough waits for a chosen number of later values before it calls a high or low a swing. It gives you two running reference levels: the last confirmed peak and the last confirmed trough. Connect closing prices to study turns in closes, or connect an oscillator to study turns in that oscillator.

The timing rule is simple: a level first appears when it is confirmed, never on the earlier bar where the turn happened. A strategy that uses this output never sees the future.

What qualifies as a swing?

Set Confirmation Bars to (N), a whole number of at least 1. Take a candidate value (X_i) among the non-empty values, in time order:

Peak at i  ⟺  Xi>max⁡(Xi−N,…,Xi−1)andXi≥max⁡(Xi+1,…,Xi+N),Trough at i  ⟺  Xi<min⁡(Xi−N,…,Xi−1)andXi≤min⁡(Xi+1,…,Xi+N).\begin{aligned} \text{Peak at }i &\iff X_i > \max(X_{i-N},\ldots,X_{i-1}) \quad\text{and}\quad X_i \geq \max(X_{i+1},\ldots,X_{i+N}),\\ \text{Trough at }i &\iff X_i < \min(X_{i-N},\ldots,X_{i-1}) \quad\text{and}\quad X_i \leq \min(X_{i+1},\ldots,X_{i+N}). \end{aligned}

In plain terms, a peak must be higher than each of the previous (N) values and at least as high as each of the next (N). A trough is the mirror image. The comparison is strict against the past and allows equality in the future. If several values in a row make a flat top or bottom, the first can qualify. A later equal value cannot qualify while an earlier equal value is among its previous (N).

The comparison uses only the input series. Closing prices give turns in closing prices; daily highs give turns in daily highs. Neither output predicts the next turn.

When does the level become available?

The candidate needs (N) earlier and (N) later non-empty values, so the earliest confirmation needs (2N+1) non-empty values. A confirmed level appears on the (N)th later non-empty value. Until another peak is confirmed, Last Peak keeps the previous peak value. Last Trough works the same way, independently. Each output is empty before its first confirmation.

Here is a small series of made-up numbers, not market prices. With (N=2), the trough of 1 at bar 3 becomes available at bar 5; the peak of 4 at bar 5 becomes available at bar 7.

Bar01234567
Series13212432
Last Peakemptyemptyemptyemptyemptyemptyempty4
Last Troughemptyemptyemptyemptyempty111
timeline
    title N = 2 - value at the turn versus value available
    Bar 3 : 1 is a possible trough
    Bar 4 : 2 is the first later value
    Bar 5 : 4 confirms trough 1
          : 4 is a possible peak
    Bar 6 : 3 is the first later value for the peak
    Bar 7 : 2 confirms peak 4

The high of 3 at bar 1 is not a confirmed peak: it has only one earlier value. A marker over bar 5 can show where the peak of 4 happened, but a rule could first use that level at bar 7. This matters when you test a strategy: using the level at its turning point would use information that had not arrived yet. TradingView's example of plotting past pivots shows why a clean historical chart can mislead.

Build with the confirmed levels

  • Breakout reference. Connect the closing-price series to Greater Than (>) → First Value and Last Peak to Second Value. A true result means the current close is above the latest confirmed high in closes. It can stay true for several bars, so it does not mark the first crossing by itself. Check the age of the level and the market context: a break alone does not prove a lasting trend.
  • Risk boundary. Use Last Trough as a reference level for the exit signal of a long position, or Last Peak for a short position. The level is a historical reference, not a guaranteed support or resistance line. StockCharts' support and resistance guide explains why traders examine prior reaction highs and lows.
  • Compare swings. Chart the two outputs next to a price or indicator series. Rising confirmed troughs show that pullbacks stop at higher levels. This module keeps only the latest level on each side, so it does not compare two past troughs by itself.

A smaller (N) finds shorter swings sooner and can confirm more levels. A larger (N) compares more neighbors and takes longer to confirm; it does not set a minimum move size. Neither setting removes false signals. The outputs may hold an old level while price moves far away, and a newly confirmed peak or trough is not a trading signal by itself.

Gaps, zero, and aligned data

An empty (null) value is a bar with no usable number. The module skips empty values when it counts the (N) values on each side of a candidate. The outputs are empty on a bar where the input is empty, even if a level was confirmed earlier; the held level returns on the next non-empty bar. Zero is a valid number: it takes part in comparisons and can itself be a confirmed trough or peak.

If a slower series is repeated to align with faster bars, each repeated value counts as a value here. That can delay or change which swings qualify. Choose the data source and period with this in mind: (N) counts non-empty values, not a fixed amount of time.

Adding later bars never moves a confirmed level back to its turning point. Levels depend on the bars included in the run: with a later start date, a held level may be missing until another swing is confirmed.

Rendering diagrams...
© 2026 WanoLabs. All rights reservedBeta v0.1.5