Ehlers Fractal Dimension code correction

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32943 quote
    DAK
    Participant
    Average

    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 !

     

    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"
    
    #33095 quote
    Elsborgtrading
    Participant
    Veteran

    Hi DAX, I don’t think there is anything wrong with your code, but there are a lot of calculation that takes up resources on your pc.

    If you need all the backtracking data it the only way, or you can limit the data with

    //FIRST LINE
    defparam CALCULATEONLASTBARS = 2000

     

    Cheers Kasper

    DAK thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Ehlers Fractal Dimension code correction


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
DAK @dak Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Elsborgtrading
8 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/22/2017
Status: Active
Attachments: No files
Logo Logo
Loading...