Hi everyone,
A few weeks ago I discovered the Fractal Dimension Index in the Prorealcode library and got very interested in it.
I did some research and found out that John Ehlers did his own version called the Fractal Dimension (with more smoothing and filtering).
I decided to give it a try and started to code his version of the indicator. See the Easylanguage code here (bottom of page) :
http://traders.com/Documentation/FEEDbk_docs/2010/06/TradersTips.html
I ended up with the below version. However I found it not to be very well working. I lags a lot, wrongly filters range and trending markets. Which is a bit surprising with Ehlers work. I reviewed the code and didn’t manage to find errors (but I’m still a beginner in programming).
To all the experienced programmers : Can you please check the below code and tell me where I did wrong ?
Many thanks !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
N = 30
Price = ((High + Low ) / 2 )
Smooth = (Price + 2 * Price [ 1 ] + 2 * Price [ 2 ] + Price [ 3 ] ) / 6
N3 = (Highest [ N] (Smooth) - Lowest [ N] (Smooth)) / N
HH = Smooth
LL = Smooth
For Count = 0 To ((N/ 2 ) - 1 ) Do
IF Smooth[ Count] > HH THEN
HH = Smooth[ Count]
ENDIF
IF Smooth[ Count] < LL THEN
LL = Smooth[ Count]
ENDIF
NEXT
N1 = (HH - LL) / (N/ 2 )
HH = Smooth[ N/ 2 ]
LL = Smooth[ N/ 2 ]
For Count = (N/ 2 ) To (N- 1 ) Do
IF Smooth[ Count] > HH Then
HH = Smooth[ Count]
ENDIF
IF Smooth[ Count] < LL THEN
LL = Smooth[ Count]
ENDIF
NEXT
N2 = (HH - LL) / (N/ 2 )
IF N1 > 0 AND N2> 0 AND N3> 0 THEN
Ratio = 0.5 * ((LOG (N1+ N2) - LOG (N3)) / LOG (2 ) + Dimen[ 1 ] )
Dimen = Average [ 20 ] (Ratio)
ENDIF
RETURN Dimen as "fractal dimension" , 1.4 as "1.4 level" , 1.6 as "1.6 level"