PivotPointBar
Background
A pivot is a local turning point, a high with lower bars on either side or a low with higher bars on either side. Sometimes you don't care about the price at a pivot, you care about when it happened, so you can measure how long ago a swing was or how far apart two swings are.
PivotPointBar counts pivots backwards from the most recent bar and returns
how many bars ago the Nth one occurred. It is the companion to
PivotPoint: same idea, but it gives you the bar offset
rather than the value. A return of 1 means the pivot is on the most recent bar, 10
means it happened ten bars ago.
Function
PivotPointBar(Source, TrendSize, PivotNo)
Parameters
| Parameter | Description |
|---|---|
| Source | The array pivots are found on. This can be the price or another indicator such as RSI. |
| TrendSize | How large the trend on each side of a point has to be for it to count as a pivot. Larger values find fewer, more significant pivots. Must be at least 1. |
| PivotNo | Which pivot you want, counting back from the most recent. 1 is the latest pivot, 2 is the one before it, and so on. |
Usage
// How many bars ago the last two swing highs were
barsAgo1 = PivotPointBar( High, 5, 1 );
barsAgo2 = PivotPointBar( High, 5, 2 );
distance = barsAgo2 - barsAgo1; // bars between the two swings
AddColumn( barsAgo1, "Last High Bars Ago" );
AddColumn( distance, "Swing Spacing" );
The exported function name is PivotPointBar. It returns a single value,
the number of bars ago, not an array. If the requested pivot doesn't exist or there
isn't enough clean data, it returns an empty value.