## valley(vars Data) : bool

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

### Parameters:

 Data Data series.

### Returns:

true if the series had a peak or valley at the previous bar, false otherwise.

### Modifies

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

### Algorithm:

```bool peak(var* Data) { return (Data[2] < Data[1]) && (Data[1] > Data[0]); }
bool valley(var* Data) { return (Data[2] > Data[1]) && (Data[1] < Data[0]); } 			 ```

### Remarks:

• The Data series must have a minimum length of 3.
• A 'flat line' of the Data series for several bars will not produce a peak or valley signal.
• For a fuzzy logic version that also detects 'almost peaks' and 'almost valleys', use peakF / valleyF.
• For detecting only 'strong peaks' or 'strong valleys', compare rMomentum with a percent threshold.
• For checking if a peak occurred n bars before, use peak(Data+n).
• For predicting an upcoming peak or valley, use the predict function.

### Example:

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