Pivot-Point Weighted Moving Average
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EduardoMattje

//@version=5
indicator("Pivot-Point Weighted Moving Average", "PPWMA", overlay=true)

var startingWeight = input.int(0, "Starting weight")
var length = input.int(21, "Length")
price = input.source(close, "Price source")

pivotPointAverage = 0.0
weight = startingWeight

if weight == 0
    weight := math.floor(length * 2/3) - 1
    
sum = 0.0
sumWeight = 0.0

for ix = 1 to length
    sum := sum + weight * price[ix - 1]
    sumWeight := sumWeight + weight
    weight := weight - 1
    
if sumWeight != 0
	pivotPointAverage := sum / sumWeight
else
	pivotPointAverage := 0.0
	
plot(pivotPointAverage)
