peak(vars Data) : bool

valley(vars Data) : bool

Determines if the Data series had a maximum (peak) or minimum (valley) at the previous bar.

peak(vars Data, int TimePeriod) : int

valley(vars Data, int TimePeriod) : int

Returns the bar offset of the last maximum (peak) or minimum (valley) of the Data series, or 0 when the series had no peak or valley within the TimePeriod.

Parameters:

Data Time series
TimePeriod Number of series elements to test

Returns:

true or bar offset at the peak or valley, false or 0 if no peak and valley was found.

Modifies

rMomentum - Data movement in percent per time frame; indicates the 'sharpness' of the peak or valley.

Algorithm:

bool peak(var* Data) { 
  rMomentum = min(Data[1]-Data[2],Data[1]-Data[0])/Data[0]*100.;
  return (Data[2] <= Data[1]) && (Data[1] > Data[0]); 
}
bool valley(var* Data) {
  rMomentum = min(Data[2]-Data[1],Data[0]-Data[1])/a[0]*100.;
  return (Data[2] >= Data[1]) && (Data[1] < Data[0]); 
}  

Remarks:

Example:

function run()
{
  vars Trends = series(LowPass(series(price()),1000),3);
  if(valley(Trends))
    enterLong();
  if(peak(Trends))
    enterShort();
}

See also:

crossOver, crossUnder, rising, falling, peakF, valleyF, predict

► latest version online