John Ehlers Instantaneous Trendline

John Ehlers Instantaneous Trendline

This is an implementation of John Ehlers’ Instantaneous Trendline, as described in Market Mode Strategies (1999-10-19).

The code has been slightly enhanced to return a Zero Lag exponential moving average, like it was done here.

A more recent formula of Hilbert Transform, described in Squelch those Whipsaws (2000-24-03), can be used, by replacing the beginning of the code with:

The attached screenshot shows the Instantaneous Trendline using original description (top) of and the alternative Hilbert Transform formula (bottom).

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Nicolas • 08/27/2018 #

    Thanks a lot for this new valuable addition to our library. I changed line 76 with “barindex” instead of “currentbar”.

  2. Horance • 08/27/2018 #

    Thanks. I’ve noticed this leftover after submission, but it was too late for editing. BTW, I think it would be nice to add the ability to edit our own posts.

  3. Etienne • 08/27/2018 #

    Thanks Horance for porting this code to PRT.
    I would like to bring some speedup to your code. I’ve been willing to use it some strategies, but the computation time is disastrous when backtesting.
    I optimized some parts of the code. The resulting figures are unchanged, but it the code is 4 time quicker to compute.

    I did 2 optimizations :
    1/ sum of deltaPhases can be computed more quickly if you observe that the current InstPeriod is close to the previous one. (which by the way is functionaly quite intutive).
    Therefore, we reuse the previous InstPeriod to compute the summation[InstPeriod](DeltaPhase) .Then we check if we went above or below 360, then we adjust the current InstPeriod with a few loops…
    On my machine, the code is twice faster on this part…

    2/ averaging using the calculated period
    In PRT, loops are slow, very slow. We are much better off, if we use native function like average…
    The gain in speedup is approx a ratio of 4 on this part…

    I’m providing the full code below.
    Thanks again

    // Instantaneous Trendline
    // Market Mode Strategies
    // 1999-10-19 John F. Ehlers
    // http://www.jamesgoulding.com/Research_II/Ehlers/Ehlers%20(Market%20Mode%20Strategies).doc

    Price = (high+low)/2
    Imult = .635
    Qmult = .338

    If BarIndex > 6 then

    // Detrend Price
    Value3 = Price – Price[7]

    // Compute InPhase and Quadrature components
    Inphase = 1.25*(Value3[4] – Imult*Value3[2]) + Imult*InPhase[3]
    Quadrature = Value3[2] – Qmult*Value3 + Qmult*Quadrature[2]

    // Use ArcTangent to compute the current phase
    If ABS(InPhase + InPhase[1]) > 0 then
    a = ABS((Quadrature+Quadrature[1]) / (InPhase+InPhase[1]))
    Phase = ATAN(a)
    Endif

    // Resolve the ArcTangent ambiguity
    If InPhase 0 then
    Phase = 180 – Phase
    Endif
    If InPhase < 0 and Quadrature 0 and Quadrature < 0 then
    Phase = 360 – Phase
    Endif

    // Compute a differential phase, resolve phase wraparound, and limit delta phase errors
    DeltaPhase = Phase[1] – Phase
    If Phase[1] 270 then
    DeltaPhase = 360 + Phase[1] – Phase
    Endif
    If DeltaPhase 60 then
    DeltaPhase = 60
    Endif

    // Sum DeltaPhases to reach 360 degrees. The sum is the instantaneous period.
    InstPeriod = InstPeriod[1]+1
    Value4 = summation[InstPeriod](DeltaPhase)
    if Value4 360 then
    if Value4 > 360 then
    while Value4 > 360 do
    InstPeriod = InstPeriod -1
    Value4 = Value4 – DeltaPhase[InstPeriod]
    wend
    else
    while Value4 < 360 do
    Value4 = Value4 + DeltaPhase[InstPeriod]
    InstPeriod = InstPeriod + 1
    wend
    InstPeriod = InstPeriod -1
    endif
    endif

    // Resolve Instantaneous Period errors and smooth
    If InstPeriod = 0 then
    InstPeriod = InstPeriod[1]
    Endif
    SmoothPeriod = .25*InstPeriod + .75*SmoothPeriod[1]

    // Compute Trendline as simple average over the measured dominant cycle period
    Period = ROUND(SmoothPeriod)
    Trendline= average [Period + 2](Price)

    Value11 = .33*(Price + .5*(Price – Price[3])) + .67*Value11[1]

    If barindex < 26 then
    Trendline = Price
    Value11 = Price
    Endif

    Endif

    Return Trendline as "TR", Value11 as "ZL"

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
elcortijoverde Muy buen trabajo.Intuitivo y claro.Gracias por tu dedicación y aportación.
Madrosat how do you use carnazzi filter in a strategy : smoothing , stop ,tendance
Bruno Carnazzi I have completely revised the mathematical foundations of this tool and offer you the finali...
Bruno Carnazzi Il me semble que la fonction "floor" n'est disponible qu'avec PRT11, à vérifier
DELBERT Bonjour , merci pour votre réponse , je m'excuse je suis avec PRT v10.3 donc c'est indicateu...
Nicolas c'est juste, c'est une instruction très récente.
RubberToe Is there something we are missing here, I just get the same curved line as well...
Khaled @Nicolas, Hi Nicolas, I've downloaded the itf and it doesn't display as an Oscillator, it"s ...
sal157011 I think the problem here is that you must feed the trigonometric functions cos and sin with ...
Guibourse Hi, I'd like to increase the thickness of support and resistance lines. I do not think that ...
JJ Tec Hello. Thanks for the great contribution of the indicator. At the moment, I have modified i...
Khaled Hi Vonasi, I tried to embed your PP Fractals code in a Strategy and it seems to be a good fi...
IV Mcm I don't speak English and the translation is not clear. Do you have a different turn of ...
IV Mcm stonk ?
avatar
Anonymous Thanks very much for sharing, look forward to testing this idea out.
ggolfet Hi Actarus, what's the name of the histogram indicator below Apple's chart?
Actaru5 Flag ShowState in setting and show histogram
NicolaSilvagni hi, thank you for creating this indicator. i can't figure out how to get the three graphs b...
larouedegann It doesn't work
ggolfet it seems it's not working on prorealtime 11. I changed MACDSignal to MACDSign in order to av...
juanj Please note that the indicator is meant for PRT 10.3
Nicolas Check your custom trading hours and use the default market ones.
fj_pastor Hello Nicolas, Thanks again for all your support. Finally I debugged the problem. The sim...
kallistos Hi Nicolas, Thank you very much indeed for this indicator (and all the others you are provi...
Morrissey38 Muchísimas gracias Nicolás , muy amable.
Bruno Carnazzi extrèmement pertinent
Bruno Carnazzi Is that beatable ?
Sapo Thank you for your indicators. As always it's perfect, I thank you for your help it's preci...
eivaremir have u got the trading view version?
carlvan That's a great indicator and I especially the use of colors, more or less pronounced to indi...
diegofe_2000 CORDIAL SALUDO. CUANDO REALIZO UN PROGRAMA CON ESTE INDICADOR ME SALE EL SIGUIENTE LETRE...
ALE Hello do you want to explain to me in more detail what you have to do? Please replay here:...
Giogio hello dear Vonasi, thank you for your indicator, can I ask you for some help in order to let...
Pottar24 HI Vonasi I would like to know how can this algorithm give me the value of the last max e mi...
parthapersonal Hello Vonasi, Great work. Is it possible to replicate this to get values of "Price Line" (1...
tobytarczy Hi Vonasi, Sounds lovely, I race yachts around europe myself. Most regattas cancelled unfor...
mlouys Hello Vonasi thank for your work ! A question how can we do it for minutes ( or 15 min or x ...
Vonasi I think that would be possible but probably in a whole new indicator as detecting when a new...

Top