In “Decyclers” in Sep, 2015, John Ehlers described a method for constructing an oscillator that could help traders detect trend reversals with almost no lag, an oscillator that signals trend reversals with almost zero lag via digital signal processing techniques. A high-pass filter is subtracted from the input data and the high-frequency components are removed via cancellation of terms. Lower-frequency components are filtered from the output, so they are not canceled from the original data. Thus, the decycler displays them with close to zero lag. The fast line has a period of 100 a K value of 1.2 and the slow line has a period of 125 and a K value of 1.
This indicator demonstrates the timely response of the decycler oscillator to market action. It applies the idea of using a decycler oscillator pair with different parameters, as discussed in Ehlers’ article:
1. Enter long when the fast line crosses over the slow line;
2. Exit long when the fast line crosses under the slow line.
//PRC_Ehlers Decycler Oscillator | indicator
//17.03.2021
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
FastHPPeriod = 100 //Fast_HPPeriod
SlowHPPeriod = 125 //Slow_HPPeriod
FastK = 1.2 //Fast_K
SlowK = 1.2 //Slow_K
// --- end of settings
Price = medianprice
once pi = 3.14159265359
if barindex>max(fasthpperiod,slowhpperiod) then
//fast
alpha1 = ( cos ( 0.707 * 2 * pi / FastHPPeriod ) + sin( 0.707 * 2 * pi / FastHPPeriod ) - 1 ) / cos( .707 * 2 * pi / FastHPPeriod )
HP = ( 1 - alpha1 / 2 ) * ( 1 - alpha1 / 2 ) * ( Price - 2 * Price[1] + Price[2] ) + 2 * ( 1 - alpha1 ) * HP[1] - ( 1 - alpha1 ) * ( 1 - alpha1 ) * HP[2]
Decycle = Price - HP
alpha2 = ( cos( 0.707 * 2 * pi / ( 0.5 * FastHPPeriod ) ) + sin( 0.707 * 2 * pi / ( 0.5 * FastHPPeriod ) ) - 1) / cos( 0.707 * 2 * pi / ( 0.5 * FastHPPeriod ) )
DecycleOsc = ( 1 - alpha2 / 2 ) * ( 1 - alpha2 / 2 ) * ( Decycle - 2 * Decycle[1] + Decycle[2] ) + 2 * ( 1 - alpha2 ) * DecycleOsc[1] - ( 1 - alpha2 ) * ( 1 - alpha2 ) * DecycleOsc[2]
DecyclerOscillatorF = 100 * FastK * DecycleOsc / Price
//slow
salpha1 = ( cos ( 0.707 * 2 * pi / SlowHPPeriod ) + sin( 0.707 * 2 * pi / SlowHPPeriod ) - 1 ) / cos( .707 * 2 * pi / SlowHPPeriod )
sHP = ( 1 - salpha1 / 2 ) * ( 1 - salpha1 / 2 ) * ( Price - 2 * Price[1] + Price[2] ) + 2 * ( 1 - salpha1 ) * (sHP[1]) - ( 1 - salpha1 ) * ( 1 - salpha1 ) * (sHP[2])
sDecycle = Price - sHP
salpha2 = ( cos( 0.707 * 2 * pi / ( 0.5 * SlowHPPeriod ) ) + sin( 0.707 * 2 * pi / ( 0.5 * SlowHPPeriod ) ) - 1) / cos( 0.707 * 2 * pi / ( 0.5 * SlowHPPeriod ) )
sDecycleOsc = ( 1 - salpha2 / 2 ) * ( 1 - salpha2 / 2 ) * ( sDecycle - 2 * (sDecycle[1]) + (sDecycle[2]) ) + 2 * ( 1 - salpha2 ) * (sDecycleOsc[1]) - ( 1 - salpha2 ) * ( 1 - salpha2 ) * (sDecycleOsc[2])
DecyclerOscillatorS = 100 * SlowK * sDecycleOsc / Price
endif
return DecyclerOscillatorF coloured(200,200,0) as "Fast Val", DecyclerOscillatorS coloured(200,0,200) as "Slow Val"