# TrendPersistenceRate

## Description

Trend Persistence Rate is a technical indicator designed by Richard Poster, PhD. As its name implies, this technical indicator attempts at measuring the strength of a trend. While many other indicators assess the trend strength based on price changes, Trend Persistence Rate does so by taking into account trend duration.

Trend Persistence Rate is calculated using the following algorithm:

1. The system calculates the slope of a moving average as one-bar momentum of that average divided by tick size times a preset multiplier.
2. The system then counts how many times the slope of a moving average has exceeded the specified threshold and how many times it has fallen below the negative of that threshold – over the trend lookup period.
3. The difference between these two numbers is then divided by the period length and multiplied by 100. The resulting percentage ratio is the Trend Persistence Rate.
4. The system also calculates a moving average of that ratio so you can estimate whether the current readings are above or below the mean.

In the study input parameters, you can customize the output of the indicator based on the trend direction. If the `trend direction` parameter is set to `no`, the output is an absolute value: for both uptrends and downtrends, strength rate is a positive number and higher readings indicate higher strength rates. If it is set to `yes`, uptrend strength rates are positive numbers and downtrend strength rates are negative.

## Input Parameters

Parameter Description
`average length` The length of the moving average to calculate the slope for.
`tpr length` The trend strength lookup period.
`tpr average length` The length of the moving average of Trend Persistence Rate.
`threshold` The threshold (in pips) to compare the moving-average slope with.
`multiplier` The tick size multiplier.
`trend direction` Defines the value output. If set to `no`, returns positive values regardless of trend direction. If set to `yes`, returns positive values for uptrend segments and negative for downtrend ones.
`average type`

The type of moving average to be used in calculations: simple, exponential, weighted, Wilder's, or Hull.

## Plots

Plot Description
`TPR` The Trend Persistence Rate plot.
`TPRAvg` The Trend Persistence Rate average plot.
`ZeroLine` The zero level. 