Search code examples
javascriptdesign-patternsstocktrading

Stock chart pattern finder with Javascript (Node)


I am building a little stock trader program, that try's to find patterns in (many) forex charts.

There is a lot of information on the web, about the most used patterns.

1: http://www.stocktradingtogo.com/2009/05/18/best-stock-chart-patterns-investing-technical-analysis/

2:http://www.morpheustrading.com/blog/best-stock-breakouts/

As I get along, its getting better and better, but its hard!

The patterns I am mainly interested in, are the 'waves' that seem to occur on almost every chart. They sometimes break, but lots of them have at least 2-3 or more 'consistent' waves, before the break.

A stock broker will return a large array with values, sorted on date.

So:

[
{
    time: 12345678,
    high: 2,
    low: 1
},

{
    time: 12345680,
    high: 3,
    low: 2
},

{
    time: 12345682,
    high: 2,
    low: 2
}
]

I have found a way to find certain 'wave' patterns in this array of information. Think of it like an ocean, where waves are mostly consistent and predictable, but sometimes there is a big wave, sometimes there are no waves.

Its a bit like the good old sound files (wave files), where you see bars like waves, each wave presenting a 'beat'.

There are probably tons of theories and examples, that show even more possibilities, but it's hard to transform such theories to dry code.

Does anyone have some advice/ideas about this problem? Could be a website with algorithms or an example in another language, or even an e-book.

Thanks in advance!!


Solution

  • What you are referring to sounds very close to the Elliott Wave Principle by Ralph Nelson Elliott.

    Elliott wave example

    According to Elliott, the markets are influenced by human emotions and these human emotions often follow predictable cycles (also called 'waves').

    In order to extend your knowledge on the Elliott wave principle, I suggest you read (at least) the following three links:

    Now to program the Elliott wave, you can simply follow the Elliott wave rules. A good starting point for these rules is again the Wikipedia page about the Elliott wave principle. Specifically, read the following 3 sections:

    • Pattern recognition and fractals
    • Elliott wave rules and guidelines
    • Fibonacci relationships

    As you can see from the information provided there, many researchers combine Elliott's theory with the Fibonacci numbers. They use the 'golden ratio' to determine (/forecast) the length of the various waves (or stages) within the complete Elliott cycle (see image below):

    Elliott wave image

    If you want more concrete material regarding this, you might want to consider reading:

    Profitability of Elliott Waves and Fibonacci Retracement Levels in the Foreign Exchange Market

    Especially useful about the paper is the Appendix (pages 56-61) which shows their Elliott wave pattern recognition algorithm in the programming language Matlab. They also define certain rules for the algorithm in the paper itself. You could take a look at their code and rewrite it in another language (Matlab is quite easy to pick up/ read).

    You could, of course, also search under "Elliott wave algorithm" or "Elliott wave pattern recognition" on Google.

    Good luck!