http://www.forexfactory.com/showthread.php?t=217486

From 7Bit:

Let f be a continuous function:

y=f(x); x,y ∈ ℝ; 0 ≤ x ≤ 100

whose function values, when plotted, would define the shape of a price pattern in such a way that f(0) would correspond to the close price of the current bar and f(100) to the beginning of the pattern in the past.

After having defined such a function I loop through a certain range of widths (say from 10 to 200 or even more) and for each such width I take this amount of recent bars, determine their highest high and lowest low and scale my pattern (x and f(x)) into this rectangle of market prices. For each such set of bars I calculate the error (the sum of all differences between each bar's close price and the ideal pattern value at this bar's position and finally divided by the area of the complete rectangle to make different sizes comparable) and if the best match has an error below a certain threshold I plot the pattern into the chart and open a trade.

In other words: On every bar open I test many differently sized rectangles of recent prices and try to fit the pattern into each of them until I find one that fits well enough.

This is how the error for a range of recent bars (determined by width) is calculated (negative width means pattern is mirrored at the x axis):

- Code: [Select all]
- Please Login or Register to see this content
- <

the function scalePatternY() that is called here determines optimal y_0 and y_scale values by simply looking at the price range and the co-domain of our pattern function and doing some simple math to find the needed scale and offset for our pattern.

Has anybody tried this approach before?

It is a bit cumbersome to create the pattern functions and the one in the example image is only a quick test to debug the basic functionality, a rough fantasy pattern out of the top of my head, but already quite promising.

If somebody here is willing to help me find and test better pattern shapes then he can find the complete source code attached to this posting.

This two files go into the experts folder:

patternmatcher.mq4

patterndesigner.mq4

This three files go into the experts/include folder:

patternmatcher.common.mqh

patternmatcher.definitions.mqh

common_functions.mqh

Patternmatcher is the EA used for trading, Patterndesigner is an EA only used during pattern development for visualizing (plotting) the pattern function into a chart.

The source is licensed under GNU GPL V3, this means: don't remove the license or any copyright notices, derivative works MUST ALWAYS include full source code and copyright notices along with the SAME license, selling closed source EAs derived from or containing (parts of) this code is not allowed. Commercial violations of other people's copyrights are considered a crime in most countries of this world!

To quickly get you started with pattern coding here is how my pattern functions look like. Basically i just split the x range into pieces (with if-constructs) and for each piece I calculate the y-value with a simple line equation. Of course you could also use all sorts of fancy math instead of the simple ab() line function to get other shapes.

The pattern function is defined in patternmatcher.definitions.mqh which will be used by both EAs. Whenever you change this file you must recompile the EAs, not the include files.

If you attach the Patterndesigner EA to an empty chart you can quickly view changes you made to the pattern function directly on the chart and drag the pattern around with the mouse to see how it looks compared to actual price. After you modified the function in patternmatcher.definitions.mqh just recompile patterndesigner.mq4 (don't compile the include files), move the lines around and see your changes directly in the chart.

The example from the above screenshot is defined by a function that looks like this:

- Code: [Select all]
- Please Login or Register to see this content
- <

A simple V-shape pattern may look like this:

- Code: [Select all]
- Please Login or Register to see this content
- <