Code:

```
declare upper;
#===================================================
# INPUTS & GLOBAL VARIABLES
#===================================================
input Hide_Gap_Down = no;
input Pivot_Forward = 1;
Input Pivot_Backward = 10;
input _Forward = 1;
input _Backward = 10;
input Hide_Extreme_Deviations = yes;
#input Show__Pivot = yes;
#input Show_Price_Pivot = yes;
#input Show_Pivot_Connector = no;
#input show_price_trendline = yes;
#input trend_price = close;
#input trend_deviations = 2.0;
#input trend_fullRange = Yes;
#input trend_length = 21;
def _BN = BarNumber();
def _nan = Double.NaN;
def _L = low;
def _H = high;
def _O = open;
def _C = close;
def _V = volume;
Script PivotPoints{
input dat = high; #the data or study being evaluated
input HL = 0; #high or low pivot designation, 0 is low, 1 is high
input PF = 5; #pivot forward period
input PB = 10; #pivot backward period
def _BN = BarNumber(); #the current barnumber
def _VStop; #confirms that the lookforward period continues the pivot trend
def _V; #the Value at the actual pivot point
def _VBar; #the bar number at the pivot point
def _PV; #the previous pivot Value
def _PVBar; #the previous pivot bar number
def _VDiff; #the difference in values between last two pivot points
def _VDist; #the diffence in barnumbers between last two pivot points
def _VSlope; #the Slope calculated using value and distance changes
def _VPivot; #used for the pivot point connector line
def _nan = double.nan;
_VStop =
fold a = 1 to PF + 1
with b = 1 while b
do dat > GetValue(dat, -a);
_V =
if _BN > PB
and dat == Highest(dat, PB)
and _VStop
then dat else _NaN;
_VBar = if !IsNaN(_V) then _BN else _VBar[1];
_PV = if !IsNaN(_V) then GetValue(dat, _BN - _VBar[1]) else _PV[1];
_PVBar =
if _VBar != _VBar[1]
then _PVBar[1] else
_VBar;
_VDiff = AbsValue(_V) - AbsValue(_PV);
_VDist = _BN - _PVBar;
_VSlope = if _V > _PV
then 1 else
if _V < _PV
then -1 else 0;
_VPivot = _bn >= lowestAll(_PVBar);
plot V = _V;
#plot Vstop = _Vstop;
#plot VBar = _Vbar;
#plot PV = _PV;
#plot PVBar = _PVBar;
#plot Vdiff = _Vdiff;
#plot Vdist = _Vdist;
#plot VSlope = _Vslope;
#plot VPivot = _Vpivot;
#end script
};
def PP_V = PivotPoints( #call the to script above and sending 4 inputs
dat = _H,
HL = 1,
PF = Pivot_Forward,
PH = Pivot_Backward);
plot close = _C;
```