TradingView
JustUncleL
6 Nov 2016 pukul 23.52

Ehlers Ideal RSI v1.0 by JustUncleL 

New Zealand Dollar/U.S. DollarFXCM

Huraian

Created by Request: Description: This is an implementation of Dr. Ehlers Ideal RSI. It uses a Homodyne Discriminator to calculate the dominate cycle of the trend and then uses the half cycle as the length for the RSI calculation.

Main Reference:
- "jstas.com/RSI/RSI ideaal.htm" it's in Dutch, use Google translate
Komen
aytug_
thanks for sharing,

I am trying to rewrite the homodyne discriminator for pinescript version #4. yet, I can not obtain the same result for smoothed_period. what do you think might be the reason for that difference?

// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © kadirkaanaytug

//@version=4
study("Homodyne Discriminator v1, kka")

c1 = 0.0962
c2 = 0.5769
c3 = 0.075
c4 = 0.54
var period = 0.0
var I2 = 0.0
var Q2 = 0.0
var Re = 0.0
var Im = 0.0
var smooth_period = 0.0
var c_period = (nz(period[1])*0.075+0.54)

// calculation of smoothed price and detrender ///
smooth = ((close*4.0) + ((close[1])*3.0) + ((close[2])*2.0) + (close[3]))/10.0
detrender = (smooth*c1 + nz(smooth[2])*c2 - nz(smooth[4])*c2 - nz(smooth[6])*c1)*c_period

// computation of InPhase and Quadrature Components
Q1 = (detrender*c1 + nz(detrender[2])*c2 - nz(detrender[4])*c2 - nz(detrender[6])*c1)*c_period
I1 = nz(detrender[3])

// advance the phase of I1 and Q1 by 90 degrees
jI = (I1*c1 + nz(I1[2])*c2 - nz(I1[4])*c2 - nz(I1[6])*c1)*c_period
jQ = (Q1*c1 + nz(Q1[2])*c2 - nz(Q1[4])*c2 - nz(Q1[6])*c1)*c_period
//

// phasor addition for 3 bar averaging
I2_ = I1 - jQ
Q2_ = Q1 + jI

// smooth the I and Q components before applying the discriminator
I2 := 0.2*I2_ + 0.8*nz(I2[1])
Q2 := 0.2*Q2_ + 0.8*nz(Q2[1])

//// Homodyne Discriminator ////
Re_ = I2*nz(I2[1]) + Q2*nz(Q2[1])
Im_ = I2*nz(Q2[1]) - Q2*nz(I2[1])
Re := 0.2*Re_ + 0.8*nz(Re[1])
Im := 0.2*Im_ + 0.8*nz(Im[1])

//dp_ = iff(Re != 0 and Im != 0, 6.28318/atan(Im/Re), 0)
//II = nz(period[1])
//dp = max(max(min(min(dp_,1.5*II),50),0.6667*II),6)
//period := dp*0.2 + nz(period[1])*0.8
//smooth_period := 0.33*period + nz(smooth_period[1])*0.67
//(360*2*3.14/360)
if Im != 0 and Re != 0
period := (360*2*3.14/360)/atan(Im/Re)
if period > 1.5*nz(period[1])
period := 1.5*nz(period[1])
if period < 0.67*nz(period[1])
period := 0.67*nz(period[1])
if period < 6.0
period := 6.0
if period > 50.0
period := 50.0

period := 0.2*period + 0.8*nz(period[1])
smooth_period := 0.33*period + 0.67*nz(smooth_period[1])

plot(smooth_period, "dc")

//
JustUncleL
@kadirkaanaytug, Please don't post large pieces of code in comment messages. Use something like pastbin.com to keep code and just paste link here. I'm not sure what is wrong with your code so I just converted from the original, here is the Ideal RSI converted to pinescript v4 pastebin.com/EZiFGGNw
aytug_
@JustUncleL, my bad. thanks for the effort!
hillab
Nice work. thank you
ClearTA
Thanks for this indicator, its really good and under appreciated. Works great to spot trend changes on daily and 4h where i primarily use it. You do great work.
JustUncleL
@ClearTA, You are welcome, yes this is an under valued indicator, particularly on the higher time frames. Good for divergence analysis on the higher times to. It was particularly challenging to get it to work within Pinescript's limitation.
hlavaty4
Hi,

I've been following your indicators for awhile now and they're the best I've used on Tradingview. I'm switching over to Tradestation now but I'm having a problem converting my favorite code of yours, the Ehlers Ideal Rsi. Is there any way you could help me with this? I don't quite understand how nan or nz values are used in easylanguage nor do I get how you are able to get the code to refernce the source with "p" on line 25 without a " p = source " statement.

Thanks! Bryar
syracusepro
Hi uncle on line 70 "II = nz(Period[1])" what period stand for? day, hours, mins etc?

On line 25, what p in the function "irma(p,l) =>" stand for? Same on line 29 "up = irma(max(change(p), 0), l)"

Also on line 72 "Period = dp*0.2 + nz(Period[1])*0.8" period?

Is period on code lines are the same as p on the functions?

Thanks a lot.

JustUncleL
@syracusepro, The "Period" is whatever your chart time frame is set at. The "p" refers to the "source" passed to the sub-function and is not related to the main programs "Period".
syracusepro
@JustUncleL, Thanks a lot.
Lebih