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
Vonasi There is another version of this indicator that can plot the same lines but onto an indicato...
Martin35 Hello Vonasi, do you think it is possible with PRT to code with the same principle as on thi...
teddy58 Ich habe es mit N= 1,5 und N=2,5 getestet mit 200000 Einheiten. Es funktioniert leider erst ...
Matriciel I use this indicator to help me make a decision when there is a divergence. The divergences ...
Jan Wind Hi, I personnaly am not a big fan of ZIGZAG indicator, as it repaints itself during time. ...
Nicolas Thanks again for all your valuable posts... and well formatted code! :)
Abdelkrim Maksour hi sir is this indicator for mt4 and how i can get one .
Horance This is a good question. John Ehlers explains it in Rocket Science for Traders. You have to ...
cbeukes Much appreciated, I will give that a try. Also, is there any criteria that one could use to ...
avatar
Anonymous Thanks for the code! I'm trying to understand how it works, and have a few questions... line...
Bebbo Grazie del prezioso contributo Nicolas, scusa la mia inesperienza, sono alle prime armi e s...
Nicolas To avoid recalculation, you should use the one from this post.
Bebbo Ok Grazie Nicolas.
Appsoluxions Hi Nicolas, do you have the MT4 version of the indicator? I am not sure if these kind of que...
Nicolas Hi, don't have one sorry. But you can still ask for private coding through our programming s...
Appsoluxions Cool. Thanks for the response.
Etienne Hi, thanks for proving this code. I would like to contribute by adding a computation speed...
Etienne //Compute Super Smoother coefficients once if barindex = 1 then a1 = exp( -1.414 * 3.14159...
Nicolas Thanks a lot!
Bard From the url link #post-65420 above but without the chart image: Stocks & Commodities...
Bard Note: lter = filter
Bard Apologies, there's been an issue with copying "f" and "I" from the article and pasting.. whi...
Nicolas
6 years ago
Nicolas Oui. Pour changer la période, il faudra ajuster la variable MMperiod
macbartin plus la période est grande (en occurrence 20) plus l'indicateur est précis dans les changeme...
Hasardeur Hallo Nicolas, in John Ehlers book "cycle analytics for Traders" from 2013, Mr. Ehlers desc...
mahdi how can I import itf file into mt4? please help
Nicolas That code is not for MT4, we do not offer free assistance for this platform, but you can ask...
guinsu2000 hello could you share your copy in a pdf or where you whant please ?
Khaled Thanks, but if I may ask what's EMA Period? The price which reverses the EMA[20] is not the ...
Francesco78 EMA is not a moving average, it is just the name we called the quantity defined above
Khaled My bad. Thank you so much!
juanj And the point of violation is the close of the candle that violates the line by generating a...
juanj For the latest version of the strategy or to follow updates and developments see the thread ...
phanz i backtested it with 10K units of EURUSD 1 hour i get an equity curve that is going one way ...
Wing Not yet but I plan to.
Leo Have a look in this Forum, I got something interesting for you... https://www.prorealcode.co...
Dávid Gyalus Dear Wing, As I am a daytrader, and one of my best friend is a programmer we think your a...
Gianluca Hello there is a new version, is it possible to translate it? https://www.tradingview.com...
christophe11560 bonjour, PRT me demande de réduire la période d'adaptive cyber Cycle suite à de fort ralent...
Pietro Fontana christophe11560, i've coded this a long time ago for a different version of the PRT, i'm not...
vitatrader35 Hola, Diego Puedes explicar cómo lo usas? Estoy tratando de emplearlo como validación de te...
diegofe_2000 Compra a la baja :  cruce de MEAN sobre AVG PEAK Compra al alza :   cruce de MEAN con AVG...
andrea ronca hi, do you know the best configuration for period, delta and fraction? thanks in advance
Lotech123 PLEASE, PLEASE someone modify the code of this special indicator for V 11. Thank you in k...
Maz Hi all, firstly happy to know that this is helping you. I look into updating it for PRT11 wh...
Nicolas just use 3 times a linear regression channel code you will find in the library.

Top