pivothighbarvs and pivotlowbarvs returns the number of bars ago that the pivothigh and pivotlow occurred. The value of -1 or 1 are only returned if a pivot did not occur within the length you specified. The barvs with the lowest count of bars ago will be the last one plotted. There are several ways you can do this. Here is one: Variable
ivothighcount(0), pivothighlast(false),Pivotlowcount(0),pivotlowlast(false);
pivothighcount=PivotHighVSBar(Instance, Price, LeftStrength, RightStrength, Length);
pivotlowcount=PivotLowVSBar(Instance, Price, LeftStrength, RightStrength, Length);
If pivothighbars<pivotlowbars then pivothighlast=true else pivothighlast=false;
If pivotlowbarsvs<pivothighbarsvs then pivotlowlast=true else pivotlowlast=false;
Then depending on what you want to do with this:
If pivothighlast=true then begin......
If pivotlowlast=true then begin.....
Just make sure you have a Length that will be more than necessary to include the last several pivots.