Attachments forums

List of attachments posted on this forum.


All files on forums: 135728

Pivot-Point Weighted Moving Average 1.0

ionone, Mon Jun 06, 2022 5:00 pm

Pivot-Point Weighted Moving Average 1.0

The Pivot-Point Weighted MA is very different from other weighted MAs, in the sense that the price weights can achieve negative values. For an example, if a length of 21 is used, the pivot point will be calculated as 13, meaning that the 13th prior candle will have 0 weight, and all prices before it will have a negative weight on the sum, so their impact is reversed rather than just unweighted.

The intent of this is to reduce lag by front-loading the prices. It works better in cyclic markets, and with a longer length, where the inflection point (the one with 0 weight) is aligned with the cyclic turn.

You can configure where the weight starts. If you leave it as 0, it will start with floor(length * 0.66) - 1.


Code: Select all

// 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)
All files in topic