Calculating a pattern-match score on a ten-element array
This whole approach is completely bogus and not worth your time.

A "pattern" is simply an array of percentage changes. For simplicity let's use a pattern size of 5. So a pattern might look like:

pat1 = [ 1%, 3%, -2%, 1.6%, 2.1% ]


meaning that the price difference (from the price at time 0) at time 1 was 1%, at time 2 was 3%, at time 3 was -2%, etc.

Given another pattern we want to compute how "similar" they are. This is done componentwise using a similarity function for percentages whose definition is:

sim(p,q) = 100 - abs (percentageChange(p,q))


where percentageChange is the percent change between p and q with an absolute value in the denominator:

percentChange(p,q) = 100 * (p-q)/abs(q)


So in python, sim is:

def sim(p,q):
  """Compute the similarity between two percentage changes."""
  pc = 100 * (p-q) / abs(q)
  return 100 - abs(pc)


Note since we are multiplying everything by 100 that the 1% value in pat1 is just the value 1, not the conventional 0.01.

Given two patterns, pat1 and pat2, we say they are close if

sim( pat1[i], pat2[i] ) &gt;= 70   for each i in 0..4


The big idea

The idea behind these patterns and similarity measures is that given historical data we compute a pattern and a future price change with the idea that the pattern implies the future price change.

Then given current data we compute the current pattern and search for a similar pattern in our database from which we can deduce the corresponding price change.

The main problem is that the sim function is not symmetrical in its arguments, i.e. sim(p,q) and sim(q,p) may have wildly different values.
Consider these examples:

sim(1.200, 2.000)   = 60.000000
sim(2.000, 1.200)   = 33.333333

sim(-1.000, 2.000)  = -50.000000
sim(2.000, -1.000)  = -200.000000

sim(-1.000, -2.000) = 50.000000
sim(-2.000, -1.000) = 0.000000

sim(-1.000, 1.000)  = -100.000000  # guess these are actually the same!
sim(1.000, -1.000)  = -100.000000

sim(-1.000, -0.100) = -800.000000
sim(-0.100, -1.000) = 10.000000

sim(-1.000, 0.100) = -1000.000000
sim(0.100, -1.000) = -10.000000


A better definition for sim(p,q) would simply be:

sim(p,q) = abs(p-q)


and then to define two patterns to be close if 

sum of sim(pat1[i], pat2[i]) for i in 0..4
  is LESS THAN a certain number


The prediction algorithm then boils down to a nearest neighbor search in a high number of dimensions (e.g. the length of the pattern array.)