ta.sar() - Pine Script Function
ta.sar()
Section titled “ta.sar()”Overview
Section titled “Overview”Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find potential reversals in the market price direction of traded goods.
Syntax
Section titled “Syntax”ta.sar(start, inc, max) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| start | simple int/float | Start. |
Returns
Section titled “Returns”Parabolic SAR.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("ta.sar")plot(ta.sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)// The same on Pine Script®pine_sar(start, inc, max) =>var float result = navar float maxMin = navar float acceleration = navar bool isBelow = false bool isFirstTrendBar = falseif bar_index == 1if close > close[1]isBelow := true maxMin := high result := low[1]else isBelow := false maxMin := low result := high[1]isFirstTrendBar := true acceleration := start result := result + acceleration * (maxMin - result)if isBelowif result > low isFirstTrendBar := true isBelow := false result :=math.max(high, maxMin)maxMin := low acceleration := startelseif result < high isFirstTrendBar := true isBelow := true result :=math.min(low, maxMin)maxMin := high acceleration := startif not isFirstTrendBarif isBelowif high > maxMin maxMin := high acceleration :=math.min(acceleration + inc, max)elseif low < maxMin maxMin := low acceleration :=math.min(acceleration + inc, max)if isBelow result :=math.min(result, low[1])if bar_index > 1 result :=math.min(result, low[2])else result := math.max(result, high[1])if bar_index > 1 result :=math.max(result, high[2])resultplot(pine_sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)