AutoPivots
Background
A pivot is a local turning point in the data: a high that has lower bars on both sides of it, or a low that has higher bars on both sides. Pivots are the skeleton of price action. Most of the pattern work in this toolbox, and a lot of support and resistance analysis in general, starts by finding the pivots and then looking at how they line up.
AutoPivots scans the array you give it and marks where the pivots are. It
returns an array that is 1 on a bar that is a pivot and 0 everywhere else, so you can
use it as a flag to plot markers, count turning points, or feed into your own logic.
What counts as a pivot depends on the Trend value: a bigger Trend means a bar has to
stand out over more neighbours on each side before it is called a pivot, which gives
you fewer but more significant turning points.
Included formula
The toolbox ships a ready-made Pivots indicator built on this function, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Pivots onto a price chart. It marks the pivot highs and lows with small circles, with the trend strength (how far a bar must stand out) and the colours set from its parameters.
The exported function
If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.
AutoPivots(Source, Trend)
Parameters
| Parameter | Description |
|---|---|
| Source | The array pivots are found on. This can be the price or another indicator such as RSI. |
| Trend | The number of bars that must be lower (for a high pivot) or higher (for a low pivot) on each side of the pivot. Larger values find fewer, more important turning points. Must be at least 1. |
Usage
pivots = AutoPivots( Close, 5 );
Plot( Close, "Price", colorDefault, styleCandle );
PlotShapes( pivots * shapeSmallCircle, colorOrange, 0, Close );
You need at least Trend * 2 + 1 bars of clean data for a pivot to be
possible, since a pivot needs that many neighbours around it. The Source array must
not contain empty, infinite or not-a-number values.