Dear all, I would be grateful for some help. I am trying to implement a condition check for part of my strategy. I want to know how close is current price to the most recent price pivot point. I define a pivot point as a recent High of a bar that is higher than 10 bars ( for example) to its left and also 10 bars to its right.

I hoped the following would get me part way there but my array called pivots never gets populated.

```
pivotSize=10;
pivots = IIf(H>Ref(HHV(H,pivotSize),1) AND H>Ref(HHV(H,pivotSize),pivotSize*-1),H,NULL);
```

I would then need to find a way to know which of these pivots is providing the closest support for the current bar.

Grateful for any help...

regards, Tim.

You can start with this code

```
PP = pivot_period = 10;
CH = HHV(H,pp+1);
FH = Ref(CH,pp);
C1 = CH == High AND FH == High;
PP = pivot_point = ValueWhen(C1,High);
Percentage_Diff = Close/PP;
Vertical_Diff = Close-PP;
Plot(Close,"Close",colorDefault,styleBar);
Plot(PP,"Pivot Point",colorWhite,styleLine|styleNoRescale);
Plot(Vertical_Diff,"Vertical Difference",colorGold,styleOwnScale);
Plot(Percentage_Diff,"Percentage Difference",colorAqua,styleOwnScale);
```

4 Likes

I'm using a Look ahead approach as coded below

```
//// https://forum.amibroker.com/t/coding-for-pivot-points/9079
//// By: @travick
pbars = 10; // Bars to Look Around
bi = BarIndex();
bPrev = HHV( H, pbars); // H of Past Bars
bFut = Ref( bPrev, pbars -1); // H of Future bars
// Pivots Array
pvs = (bPrev == bFut) AND // Bars when both condtions coincide
H == bPrev AND // the Bar that becomes the pivot
bi < BarCount - pbars -1; // make sure enough Future bars exist
rpp = LastValue( ValueWhen(pvs, H, 1)); // Price or H of Last Pivot
PlotShapes( pvs*shapeHollowSmallCircle, colorWhite, 0, H, 10);
```

**rpp** is the variable or High price of the Last Pivot.

You can you the Last price to compute the difference in $ or % as you need.

Hope it works.

Ignore the dashed lines.

4 Likes

Sebastian, thank you so much for this. I think I follow what you've done. Array processing is very powerful (and quite tricky to think in arrays!), regards, Tim.

Hi Travick, thank you for taking the time to help me with this. Your solution and Sebastian's take a similar approach. It's a great help and provides a great insight into how I must think when processing arrays. thank you. regards Tim.

I didn't realize, we both posted in a span of 3min