hello community ! i took as example another indicator and here is the indicator with pivots for williams indicator
# WIILLIAMS%R Divergence
# HECTOROAG
# V1.02_08_2023
input n = 2;
input length = 14;
def h = high;
def l = low;
def bar = BarNumber();
def williams = williamsPercentR(length);
def CurrWilliamsH = if williams > -50
then fold i = 1 to n + 1
with p = 1
while p
do williams > GetValue(williams, -i)
else 0;
def CurrWilliamsPivotH = if (bar > n and
williams == Highest(williams, n) and
CurrWilliamsH)
then h
else Double.NaN;
def CurrWilliamsL = if williams < -50
then fold j = 1 to n + 1
with q = 1
while q
do williams < GetValue(williams, -j)
else 0;
def CurrWilliamsPivotL = if (bar > n and
williams == Lowest(williams, n) and
CurrWilliamsL)
then l
else Double.NaN;
def CurrPWBar = if !IsNaN(CurrWilliamsPivotH)
then bar
else CurrPWBar[1];
def CurrPLBar = if !IsNaN(CurrWilliamsPivotL)
then bar
else CurrPLBar[1];
def PWpoint = if !IsNaN(CurrWilliamsPivotH)
then CurrWilliamsPivotH
else PWpoint[1];
def priorPWBar = if PWpoint != PWpoint[1]
then CurrPWBar[1]
else priorPWBar[1];
def PLpoint = if !IsNaN(CurrWilliamsPivotL)
then CurrWilliamsPivotL
else PLpoint[1];
def priorPLBar = if PLpoint != PLpoint[1]
then CurrPLBar[1]
else priorPLBar[1];
def HighPivots = bar >= HighestAll(priorPWBar);
def LowPivots = bar >= HighestAll(priorPLBar);
def pivotHigh = if HighPivots
then CurrWilliamsPivotH
else Double.NaN;
plot PlotHline = pivotHigh;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(GetColor(7));
PlotHline.SetStyle(Curve.SHORT_DASH);
plot pivotLow = if LowPivots
then CurrWilliamsPivotL
else Double.NaN;
pivotLow.EnableApproximation();
pivotLow.SetDefaultColor(GetColor(7));
pivotLow.SetStyle(Curve.SHORT_DASH);
plot PivotDot = if !IsNaN(pivotHigh)
then pivotHigh
else if !IsNaN(pivotLow)
then pivotLow
else Double.NaN;
PivotDot.SetDefaultColor(GetColor(7));
PivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);