## frechet (vars Data, int TimeFrame, var Scale, var* Pattern) : var

Compares the recent part of a price series with a predefined curve pattern, and returns the similarity between the two curves. This function is used for detecting cups, zigzags or similar triggers in the price curve.
### Parameters:

**Data** |
The series to be compared. |

**TimeFrame** |
The number of bars in the series to be compared, or **0** for using the length of the pattern. |

**Scale** |
The vertical size of the pattern for comparison (f.i. **10*PIP** for detecting a 10 pips tall pattern). Use a negative scale for inverting the pattern. |

**Pattern** |
The pattern to be detected in the series, given by an array of positive values that starts with the oldest value and ends with **0** as an end mark. |

### Returns

Similarity between **Data** and **Pattern** in percent, normally in the **20..80** range.
### Remarks:

- The algorithm is based on the
**Fréchet distance**, a measure of similarity between two curves, often used for handwriting recognition. For the algorithm, imagine a dog walking along one curve and the dog's owner walking along the other curve. They are connected by a leash and walk from the start point to the end point of the curve. Both may vary their speed and even stop anytime, however neither can backtrack. The Fréchet distance is the length of the shortest possible leash required for traversing the curves in this manner.
- The absolute values of the pattern array don't matter, as it is normalized to
**Scale** before comparison. The pattern is also aligned with the minimum of the **Data** series. For automatically adapting the pattern size to the data amplitude, set **Scale = MaxVal(Data,TimeFrame) - MinVal(Data,TimeFrame);**.
- Because series arrays have reverse time order, the pattern array is also reversed before comparison. This must be considered when comparing the pattern with a data array that is not a series.

### Example:

*//detect 10-pip 10-bar cup formations in the price curve
*function run()
{
vars Price = series(price());
static var cup[10] = { 6,3,2,1,1,1,2,3,6,0 };
plot("Cup Similarity",frechet(Price, 0, 10*PIP, cup),NEW,RED);
}

### See also:

predict, advise, polyfit
► latest
version online