John,
If in fact Peak is supposed to retain the value of the 
  previous Peak when not a new Peak (as opposed to zero shown in my previous 
  post) and similarly for Valley, then my earlier post would need to be modified 
  to the following (also corrected to no longer use the AmiBroker keyword Peak 
  as a variable name)
BP1 = Ref( BP, -1 );
BP2 = Ref( BP, -2 
  );
NewPeak = ( BP1 > BP AND BP1 > BP2 );
Peaks = IIF( NewPeak, 
  BP1, ValueWhen( NewPeak, BP1 ) );
NewValley = ( BP1 < BP AND BP1 < 
  BP2 );
Valleys = IIF( NewValley, BP1, ValueWhen( NewValley, BP1 ) 
  );
AvgPeak = MA( Peaks, 50 );
FracAvgPeak = Fraction * 
  AvgPeak;
AvgValley = MA( Valleys, 50 );
FracAvgValley = Fraction * 
  AvgValley;
Mike
--- In amibroker@xxxxxxxxxps.com, 
  "bbands" <BBands@xxx> wrote:
>
> --- In amibroker@xxxxxxxxxps.com, 
  "Ton Sieverding" <ton.sieverding@> wrote:
> >
> > 
  Hi John. It's not that I cannot translate lines 29 thru 36 in AFL. My problem 
  is that I do not understand the code :
> > 
> > 29. if BP[1] 
  > BP and BP[1] > BP[2] then 
> > 30. Peak = BP[1]
> > 
  31. else if BP[1] < BP and BP[1] < BP[2] then 
> > 32. Valley = 
  BP[1] ;
> > 
> > What's the difference between Peak and 
  Valley in the above code ? For me they always have the same value because 
  whatever happens this value is BP[1] ...
> > 
> > BTW BP is 
  an array and AFL handles this with the double if.( Iff( BP<Ref(BP,-1) etc. 
  ) ...
> Ton,
> 
> First, I think the John Ehlers' work in 
  the article is quite elegant and very interesting. 
> 
> As I grok 
  it: 
> 
> Peaks: If the last period is greater than the current 
  period and the prior period then peak = last period else peak equals the prior 
  value of peak.
> 
> c
> c c
> 
> Valleys: If the 
  last period is less than the current period and the prior period then valley = 
  last period else valley equals the prior value of valley.
> 
> c 
  c
> c
> 
> So peak and valley always contains the value to 
  the most recent high point and low point, where a high point is a point 
  surrounded by lower points and a low point is a point surrounded by higher 
  points.
> 
> I have done a lot of work on these ideas, which I 
  call hips and lops and Wheeler called circled highs and lows. The big 
  difference here being that closes are used instead of highs and lows.
> 
  
> You can see hips and lops in action on our forex site, 
  www.BBForex.com.
> 
> So this neatly combines several area of 
  interest for me, hips and lops and bands.
> 
> Thanks for having a 
  look at it,
> 
> John Bollinger
>