Price action works. But why?

jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Price action works. But why?

Post by jcl »

For any trading system there should be some rational reason why it works (or not). I had always assumed that price action trading with candlestick patterns can not work because price relations of adjacent candles are more or less random. So price action is just trading the noise. But that was wrong as I learned - there are patterns in historic price data that have indeed some predictive value:

Image

That's an out of sample test with EUR/USD and trading with computer generated patterns. The equity is the blue curve. This clearly proves that patterns can predict price movements. But only when the pattern consists of 3 daily candles. Patterns with 4 candles or candles with smaller time frames have no significance.

I'm now wondering if there is any idea or explanation for what reason a price movement is more often than by chance preceded by a certain pattern of 3 daily candles? Is there a trading behavior that would explain that phenomenon?
magft
Trader
Posts: 195
Joined: Tue Nov 15, 2011 9:59 pm
Location: East Midlands, UK

Re: Price action works. But why?

Post by magft »

jcl

I was looking at this over the weekend after installing Zorro 1.10. From you statement you have obviously tried different number of candle inputs and different timeframes. The plot you show is from workshop 7 but with Friday trading removed i think, is that correct?

The results are quite impressive Annual Return 223% 3699pips as shown below. I'm interested in this as i started looking at the 7bit pattern matching EA in the other thread. Have you tried any other inputs to the advise function other than those in the workshop? Also do you have more information on how the advise function works in terms of using the inputs to find the patterns, ie like in neural networks you have weights and biases? I see that it assigns a hex string for each profitable pattern, is this a hash of the pattern index or the like?

The reason i'm asking is a few years ago Steve H wrote an EA called Reversi that tried to use statistics from previous candles to predict reversals. Based on inputs of candle length it would calculate the probability of a reversal. I was just wondering if we could do a combination of the two maybe to find potential patterns for trade entry.

I hope you can get some discussion going as i think this is very interesting way to potentially make money.

Regards

Mike

Code: Select all

Walk-Forward Test Workshop7_1 EUR/USD - performance report

Simulation period   04.04.2002-23.04.2013
Test period         25.09.2008-23.04.2013
WFO test cycles     4 x 356 bars (73 weeks)
Training cycles     5 x 2017 bars (417 weeks)
Lookback time       80 bars (16 weeks)
Assumed spread      2.6 pips (roll -0.06/0.03)
Assumed slippage    10.0 sec
Contracts per lot   800

Gross win/loss      2987$ / -1633$ (+16924p)
Average profit      296$/year, 25$/month, 1.14$/day
Max drawdown        -164$ 12% (MAE -181$ 13%)
Total down time     72% (TAE 85%)
Max down time       24 weeks from May 2010
Largest margin      30$
Trade volume        383038$ (83725$/year)
Transaction costs   -74$ spr, -4.06$ slp, -2.60$ rol
Capital required    163$

Number of trades    356 (77/year)
Percent winning     58%
Max win/loss        79$ / -40$
Avg trade profit    3.80$ 47.5p (+14$ / -11$)
Avg trade bars      6 (+6 / -6)
Max trade bars      12 (17 days)
Time in market      174%
Max open trades     6
Max loss streak     7 (uncorrelated 7)

Annual return       223%
Profit factor       1.83 (PRR 1.57)
Sharpe ratio        1.43
Kelly criterion     1.13
OptimalF            .063
Ulcer index         4%
Prediction error    30%

Portfolio analysis  OptF  ProF  Win/Loss  Cycles

EUR/USD:L           .070  2.06  105/65    ////
EUR/USD:S           .055  1.63  101/85    ///\
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Price action works. But why?

Post by jcl »

Yes, I've tried different input variants, but the 3-candle pattern worked best. I got the idea from Daniel Fernandez who posted a similar result on his blog. The Zorro pattern finder uses no neural network, but just a brute force approach with a binary tree algorithm for identifying all profitable patterns in the training data.

The performance of this simple strategy is quite good, only question is - can you trust that result? I would prefer if I had some rational explanations why candle patterns work at all.
magft
Trader
Posts: 195
Joined: Tue Nov 15, 2011 9:59 pm
Location: East Midlands, UK

Re: Price action works. But why?

Post by magft »

jcl wrote:Yes, I've tried different input variants, but the 3-candle pattern worked best. I got the idea from Daniel Fernandez who posted a similar result on his blog. The Zorro pattern finder uses no neural network, but just a brute force approach with a binary tree algorithm for identifying all profitable patterns in the training data.

The performance of this simple strategy is quite good, only question is - can you trust that result? I would prefer if I had some rational explanations why candle patterns work at all.
I thought it was a brute force method i guess i'm trying to understand how it defines the patterns from the inputs. You say it only stores the profitable patterns (as hex number), number of occurrences, mean and SD int the rul file. Based on the example of inputs PATTERN+2,HLC[2],HLC[1],HLC[1],HLC[0] how does it define the pattern from the inputs and if it is profitable or not? Do you have a diagram to highlight the method as this could possibly help with answering why as it will help me and others understand how it is working.

Regards

Mike
garyfritz

Re: Price action works. But why?

Post by garyfritz »

Interesting finding, jcl! I gather you select all the 3-candle patterns that show good patterns in the training period, and trade those OOS? I wonder how it would work to "score" each pattern, weighting them more or less based on how well they performed in the training period?

Can you list some of the successful patterns? Might be easier to determine why they work, if we know what they are...
User avatar
mobthehop
Trader
Posts: 362
Joined: Wed Nov 16, 2011 12:16 am

Re: Price action works. But why?

Post by mobthehop »

Hi magft.... just a quick correction -Reversi looks at the sequential number of up / down candles not the candle length.... Still love this concept....

Cheers
Kruspe
Trader
Posts: 121
Joined: Sat May 19, 2012 3:34 pm
Location: Prague, Czech Republic

Re: Price action works. But why?

Post by Kruspe »

In case you want to find the sequence of up/ down candles, check VM´s I ching thread. It´s all about 6 candles patterns. Maybe it could be interesting to "connect" these threads and help each other.
Once you "see", you can not unsee. CJ
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Re: Price action works. But why?

Post by jcl »

I explain the method. I guess it's the very opposite of I Ching. Here's a file with the machine generated algorithm that contains all profitable patterns in EUR/USD data from 2005 on:
Workshop7_EURUSD.c
It's a normal C function, so you can theoretically paste it in a Empty4 EA and trade it, after some small modifications. The function begins like this:

Code: Select all

int EURUSD_L(float* sig)
{
  if(sig[1]<sig[4] && sig[4]<sig[5] && sig[5]<sig[2] && sig[2]<sig[3] && sig[3]<sig[0] && sig[10]<sig[11] && sig[11]<sig[7] && sig[7]<sig[8] && sig[8]<sig[9] && sig[9]<sig[6])
    return 42;
  if(sig[4]<sig[5] && sig[5]<sig[1] && sig[1]<sig[2] && sig[2]<sig[3] && sig[3]<sig[0] && sig[10]<sig[7] && sig[7]<sig[8] && sig[8]<sig[6] && sig[6]<sig[11] && sig[11]<sig[9])
    return 84;
  if(sig[4]<sig[1] && sig[1]<sig[2] && sig[2]<sig[0] && sig[0]<sig[5] && sig[5]<sig[3] && sig[7]<sig[10] && sig[10]<sig[11] && sig[11]<sig[8] && sig[8]<sig[6] && sig[6]<sig[9])
    return 29;
  if(sig[1]<sig[4] && sig[4]<sig[2] && sig[2]<sig[5] && sig[5]<sig[0] && sig[0]<sig[3] && sig[7]<sig[10] && sig[10]<sig[8] && sig[8]<sig[11] && sig[11]<sig[9] && sig[9]<sig[6])
    return 82;
  ....
  return 0;
}
The function has the name EURUSD_L, meaning it's for long trades with EUR/USD. The list of candle prices is passed to the function as a pointer to a float array named sig. If I'm not mistaken, Empty4 does not support floats and pointers, so you have to change that to something like (double& sig[]). Anyway it evaluates 12 prices, sig[0] to sig[11], which are the Low, High, and Close of the last 3 candles:

sig[0]...sig[11] = H2, L2, C2, H1, L1, C1, H1, L1, C1, H0, L0, C0.

For technical reasons the middle candle appears twice, therefore we have 12 variables and not 9.

The function contains many if() conditions with many comparisons of prices with other prices. Any if() condition represents a pattern. The comparisons are linked with &&, so the if() condition is true when all its comparisons are true. In this case a certain value, like 42 in the first if() condition in the example, is returned by the function. If none of the if() conditions is true, 0 is returned, meaning that no pattern is found. The returned value is the pattern's score - its information ratio multiplied with 100. The higher the information ratio, the more predictive is the pattern.

When the function is called with the prices of the last 3 candles, it enters a trade when the score is above a limit. The equity curve above with the 223% annual profit uses a limit of 30. So any pattern with a score above 30 triggers a trade.

The function is generated by going through the training data and simulating a long and short trade at every bar. The results of the trades are stored together with the preceding candle pattern. So we get a large pattern list. The computer then throws away all patterns that occur less than 4 times or don't precede profitable trades. This reduces the pattern list to about 100 patterns. For every pattern the information ratio is calculated, that's the quotient of profit mean over standard deviation. This is then the return value of that pattern in the generated function.

I hope that explains how the method works. Unfortunately it does not explain why the method works.
You do not have the required permissions to view the files attached to this post.
jb68
Trader
Posts: 71
Joined: Mon Jan 30, 2012 11:30 pm

Re: Price action works. But why?

Post by jb68 »

Hi,

The daily candles are most connected with periodic news announcements as well as with big players like big banks, loan payments, FMI etc.

I was looking to do something similar with NN implementation but the problem here as well as in NN is over-fitting. Did you use data unused by the pattern collector/generator for back-testing?
garyfritz

Re: Price action works. But why?

Post by garyfritz »

Thanks for that, jcl. Hm, so about 100 total patterns. That feels very much like curve-fitting. What period did you train it on?

I converted your code to Tradestation format:

Code: Select all

  if(L[2]<L[1] and L[1]<C[1] and C[1]<C[2] and C[2]<H[1] and H[1]<H[2] and L[0]<C[0] and C[0]<L[1] and L[1]<C[1] and C[1]<H[0] and H[0]<H[1]) 
    then ret =  42;
  if(L[1]<C[1] and C[1]<L[2] and L[2]<C[2] and C[2]<H[1] and H[1]<H[2] and L[0]<L[1] and L[1]<C[1] and C[1]<H[1] and H[1]<C[0] and C[0]<H[0]) 
    then ret =  84;
(etc)

I'm not sure of the trading logic yet so I just displayed the resulting scores. Does this look right? (Green line is the EURUSD_L signal, red is EURUSD_S.) In the signal listing, each line represents the bar that just CLOSED at that time. E.g. the first line, 5/1/13 14:59, is the daily bar that just closed at 14:59 MDT = 5pm NY time on 5/1.
ZorroPA1.gif
ZorroPA2.gif
Then how do you trade it? Does a signal > 30 indicate you go long/short only for the next candle? Or do you stay long/short until you get an opposite signal?

Are the signals mutually exclusive? I.e. is it possible for more than one signal to match? I don't want to try to figure that out manually :D but I suppose I could modify my code to detect it...
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Automated trading systems”