Pivot Point Moving Average (PPMA)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("PPMA", overlay = true)

ppma(left, right)=>
    signal = ta.change(ta.pivothigh(high, left, right)) or ta.change(ta.pivotlow(low, left, right))
    var int count = na
    var float sum = na
    if not signal
        count := nz(count[1]) + 1
        sum := nz(sum[1]) + close
    else
        count := na
        sum := na

    sum/count

left = input.int(50, "Pivot Left", 0)
right = input.int(0, "Pivot Right", 0)

plot(ppma(left, right))
