ta.sar
Trail a stop that flips sides when price reverses through it.
ta.sar(start, increment, maximum, bars)Parabolic stop and reverse, Wilder's method. Per bar, in this order: step the stop toward the extreme point by the acceleration factor. If the stop has been touched, reverse: the new stop is the extreme of this bar and the old extreme point, the new extreme point is this bar's other extreme, and the factor resets to start. Otherwise widen the factor by increment, capped at maximum, if and only if this bar set a new extreme. Finally clamp the stop outside the previous two bars' range so it never sits inside the bars it trails. The trend is seeded on the second bar from the direction of the close, with the stop at the first bar's low for an uptrend or its high for a downtrend. Bars are read from bars. There is no direction output. The stop is below price in an uptrend and above it in a downtrend, so close > ta.sar() is the test.
Parameters
A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.
| Name | Kind | Type | Unit | Default | Range | Description |
|---|---|---|---|---|---|---|
start | Constant | number | - | 0.02 | 0.000001 to 1 | The acceleration factor the trend starts at after every reversal. |
increment | Constant | number | - | 0.02 | 0 to 1 | How much the acceleration factor widens on each new extreme. |
maximum | Constant | number | - | 0.2 | 0.000001 to 1 | The ceiling the acceleration factor may widen to. |
bars | Constant | bars | bars | na | - | Which bars to read: a declared series, or na for the chart's own. |
Output
| Name | Type | Unit |
|---|---|---|
value | number | - |
Warm-up and missing values
- Warm-up
- 2 bars.
- Missing values
- na on the first bar (the trend is seeded from the first close-to-close direction, which needs two bars) and na while
barshas no bar available. A bar that cannot be read leaves the state where it was. The stop stands and the next usable bar carries on without re-seeding.
Example
ta.sar(0.02, 0.02, 0.2)plot(ta.sar(0.02, 0.02, 0.2), "Stop and reverse")