Measuring Cycle Periods By John Ehlers

amibrokerfans

Well-Known Member
#1
i am a big fan of Mr.John Ehlers's work.though "John Ehlers is, besides his big and valuable work on a lot of indicators, also known for some statements that are pure advertisement that is not based on real results", he is leading researcher of decoding market cycles and lots of work going on nowadays based on his concepts.

"Measuring Cycle Periods",John Ehlers presents a very interesting technique of measuring dominant market cycle periods by means of multiple bandpass filtering. By utilizing an approach similar to audio equalizers, the signal (here, the price series) is fed into a set of simple second-order infinite impulse response bandpass filters.
Filters are tuned to 8,9,10,...,50 periods. The filter with the highest output represents the dominant cycle.
- traders.com march2008 traders tips

below is the afl and the screenshot of SBIN 5min chart from 24.6.13 to 28.6.13.
interesting!the afl spotted the top&bottom several times very accurately!



PHP:
_SECTION_BEGIN("cycle121");

SetChartBkColor(ParamColor("Panel color ",colorOrange));


PI = 3.1415926;
Data = (H+L)/2;
// detrending ( high-pass filter )
HFPeriods = Param("HP filter cutoff", 40, 20, 100 );
alpha1 = ( 1-sin(2*pi/HFPeriods) ) / cos( 2 * pi / HFPeriods );
HP = AMA2( Data - Ref( Data, -1 ), 0.5 * ( 1 + alpha1 ), alpha1 );
// 6-tap low-pass FIR filter
SmoothHP  = ( HP + 2 * Ref( HP, -1 ) + 3 * Ref( HP, -2 ) +
   3 * Ref( HP, -3 ) + 2 * Ref( HP, -4 ) + Ref( HP, -5 ) )/12;
SmoothHPDiff = SmoothHP - Ref( SmoothHP, -1 );
x = BarIndex();
delta = -0.015 * x + 0.5;
delta = Max( delta, 0.15 );
Q  = 0;
Real = 0;
Imag = 0;
Ampl = 0;
DB =  0;
I = SmoothHP;
MaxAmpl = 0;
for( N = 8; N <= 50; N++ )
{
  beta = cos( 2 * PI / N );
  Q = ( N / ( 2 * PI ) ) * SmoothHPDiff;
 
  for( bar = 8; bar < BarCount; bar++ )
  {
     gamma = 1 / cos( 4 * PI * delta[ bar ] / N );
     alpha = gamma - sqrt( gamma ^ 2 - 1 );
 
     Real[ bar ] = 0.5 * ( 1 - alpha ) * ( I[ bar ] - I[ bar - 1 ] ) +
                   beta * ( 1 + alpha ) * Real[ bar - 1 ] -
                   alpha * Real[ bar - 2 ];
     Imag[ bar ] = 0.5 * ( 1- alpha ) * ( Q[ bar ] - Q[ bar - 1 ] ) +
                beta * ( 1 + alpha ) * Imag[ bar - 1 ] -
                alpha * Imag[ bar - 2 ];
   }
   Ampl = Real ^ 2 + Imag ^ 2;
   MaxAmpl = Max( MaxAmpl, Ampl );
   VarSet("Ampl"+N, Ampl );
}
TunedFilterDisplay = ParamToggle("Dom Cycle Tuned Filter", "No|Yes" );
// Plot Heat Map ( Spectrogram )
// and find dominant cycle
DcNum = DcDenom = 0;
for( N = 8; N <= 50; N++ )
{
   Ampl = VarGet("Ampl"+N);
   db  = Nz( -10 * log10( 0.01 / ( 1 - 0.99 * Ampl / MaxAmpl ) ) );
 
   db = Min( db, 20 ) ;
   Red = IIf( db <= 10, 255, 255 * ( 2 - db/10 ) );
   Green = IIf( db <= 10, 255 * ( 1 - db/10 ), 0 );
   if( NOT TunedFilterDisplay  )
      PlotOHLC( N, N, N-1, N-1, "", ColorRGB( Red, Green, 0 ),
                                    styleCloud | styleNoLabel );
   DcNum = DcNum + (db < 3 ) * N * ( 20 - db );
   DcDenom = DcDenom + ( db < 3 ) * ( 20 - db );
}
DC = DcNum / DcDenom;
if( ParamToggle("Show Dom. Cycle?", "No|Yes" ) )
{
  DomCycle = Median( DC, 10 );
  Plot( DomCycle, "Dominant Cycle", colorBlue );
}
if( TunedFilterDisplay )
{
   DomCycle = Median( DC, 10 );
   DomCycle = Max( DomCycle, 8 );
   Value = 0;
   for( bar = 10; bar < BarCount; bar++ )
   {
     beta = cos( 2 * PI / domCycle[ bar ] );
     gamma = 1 / cos( 4 * PI * delta[ bar ] / DomCycle[ bar ] );
     alpha = gamma - sqrt( gamma ^ 2 - 1 );
     Value[ bar ] = 0.5 * ( 1 - alpha ) * SmoothHPDiff[ bar ] +
           beta * ( 1 + alpha ) * Value[ bar - 1 ] -
           alpha * Value[ bar - 2 ];
   }
   Value2 = ( domCycle / ( 2 * PI ) ) * ( Value - Ref( Value, -1 ) );
   Plot( Value, "Sine", colorBlue );
   Plot( Value2, "Cosine", colorWhite );
}
GraphZOrder = 1;
_SECTION_END();
 
#2
i am a big fan of Mr.John Ehlers's work.though "John Ehlers is, besides his big and valuable work on a lot of indicators, also known for some statements that are pure advertisement that is not based on real results", he is leading researcher of decoding market cycles and lots of work going on nowadays based on his concepts.

"Measuring Cycle Periods",John Ehlers presents a very interesting technique of measuring dominant market cycle periods by means of multiple bandpass filtering. By utilizing an approach similar to audio equalizers, the signal (here, the price series) is fed into a set of simple second-order infinite impulse response bandpass filters.
Filters are tuned to 8,9,10,...,50 periods. The filter with the highest output represents the dominant cycle.
- traders.com march2008 traders tips

below is the afl and the screenshot of SBIN 5min chart from 24.6.13 to 28.6.13.
interesting!the afl spotted the top&bottom several times very accurately!



PHP:
_SECTION_BEGIN("cycle121");

SetChartBkColor(ParamColor("Panel color ",colorOrange));


PI = 3.1415926;
Data = (H+L)/2;
// detrending ( high-pass filter )
HFPeriods = Param("HP filter cutoff", 40, 20, 100 );
alpha1 = ( 1-sin(2*pi/HFPeriods) ) / cos( 2 * pi / HFPeriods );
HP = AMA2( Data - Ref( Data, -1 ), 0.5 * ( 1 + alpha1 ), alpha1 );
// 6-tap low-pass FIR filter
SmoothHP  = ( HP + 2 * Ref( HP, -1 ) + 3 * Ref( HP, -2 ) +
   3 * Ref( HP, -3 ) + 2 * Ref( HP, -4 ) + Ref( HP, -5 ) )/12;
SmoothHPDiff = SmoothHP - Ref( SmoothHP, -1 );
x = BarIndex();
delta = -0.015 * x + 0.5;
delta = Max( delta, 0.15 );
Q  = 0;
Real = 0;
Imag = 0;
Ampl = 0;
DB =  0;
I = SmoothHP;
MaxAmpl = 0;
for( N = 8; N <= 50; N++ )
{
  beta = cos( 2 * PI / N );
  Q = ( N / ( 2 * PI ) ) * SmoothHPDiff;
 
  for( bar = 8; bar < BarCount; bar++ )
  {
     gamma = 1 / cos( 4 * PI * delta[ bar ] / N );
     alpha = gamma - sqrt( gamma ^ 2 - 1 );
 
     Real[ bar ] = 0.5 * ( 1 - alpha ) * ( I[ bar ] - I[ bar - 1 ] ) +
                   beta * ( 1 + alpha ) * Real[ bar - 1 ] -
                   alpha * Real[ bar - 2 ];
     Imag[ bar ] = 0.5 * ( 1- alpha ) * ( Q[ bar ] - Q[ bar - 1 ] ) +
                beta * ( 1 + alpha ) * Imag[ bar - 1 ] -
                alpha * Imag[ bar - 2 ];
   }
   Ampl = Real ^ 2 + Imag ^ 2;
   MaxAmpl = Max( MaxAmpl, Ampl );
   VarSet("Ampl"+N, Ampl );
}
TunedFilterDisplay = ParamToggle("Dom Cycle Tuned Filter", "No|Yes" );
// Plot Heat Map ( Spectrogram )
// and find dominant cycle
DcNum = DcDenom = 0;
for( N = 8; N <= 50; N++ )
{
   Ampl = VarGet("Ampl"+N);
   db  = Nz( -10 * log10( 0.01 / ( 1 - 0.99 * Ampl / MaxAmpl ) ) );
 
   db = Min( db, 20 ) ;
   Red = IIf( db <= 10, 255, 255 * ( 2 - db/10 ) );
   Green = IIf( db <= 10, 255 * ( 1 - db/10 ), 0 );
   if( NOT TunedFilterDisplay  )
      PlotOHLC( N, N, N-1, N-1, "", ColorRGB( Red, Green, 0 ),
                                    styleCloud | styleNoLabel );
   DcNum = DcNum + (db < 3 ) * N * ( 20 - db );
   DcDenom = DcDenom + ( db < 3 ) * ( 20 - db );
}
DC = DcNum / DcDenom;
if( ParamToggle("Show Dom. Cycle?", "No|Yes" ) )
{
  DomCycle = Median( DC, 10 );
  Plot( DomCycle, "Dominant Cycle", colorBlue );
}
if( TunedFilterDisplay )
{
   DomCycle = Median( DC, 10 );
   DomCycle = Max( DomCycle, 8 );
   Value = 0;
   for( bar = 10; bar < BarCount; bar++ )
   {
     beta = cos( 2 * PI / domCycle[ bar ] );
     gamma = 1 / cos( 4 * PI * delta[ bar ] / DomCycle[ bar ] );
     alpha = gamma - sqrt( gamma ^ 2 - 1 );
     Value[ bar ] = 0.5 * ( 1 - alpha ) * SmoothHPDiff[ bar ] +
           beta * ( 1 + alpha ) * Value[ bar - 1 ] -
           alpha * Value[ bar - 2 ];
   }
   Value2 = ( domCycle / ( 2 * PI ) ) * ( Value - Ref( Value, -1 ) );
   Plot( Value, "Sine", colorBlue );
   Plot( Value2, "Cosine", colorWhite );
}
GraphZOrder = 1;
_SECTION_END();


Would u pls post the above Picture AFL. it would be really usefully.
n would u also explain the code u given.. how to read it?


Waiting for picture afl code (kindly post both afls code as shown in picture)

Thanx you
 

amibrokerfans

Well-Known Member
#3
Would u pls post the above Picture AFL. it would be really usefully.
n would u also explain the code u given.. how to read it?
Waiting for picture afl code (kindly post both afls code as shown in picture)
Thanx you
select "dominant cycle tuned filter" as "yes":lol:



and watch the crossing point between two curves .
 

amibrokerfans

Well-Known Member
#4
many of you asked me its long time now why i am not sharing something here in traderji.. ok expanding this thread now..

level trading is most easiest simplest way to trade IF we can calculate the action level 'accurately'. a clear-cut entry stoploss and target, which make a level trader exceptional. we have few good tools like bar pattern pivot etc to draw the support/resistance level and trade with. but i want to show something different way to draw the levels.

Measuring Cycle Periods: the action bar

as its under "Measuring Cycle Periods By John Ehlers" thread, you surely know it has sometime do with Measuring Cycle Periods indicator. yes it is.the bar under the crossing point between two curves of Measuring Cycle Periods indicator i call "action bar". all our action will start from that very bar.

Laguerre RSI: the suppoter

Laguerre RSI indicator, i think we all know this indicator, another master piece of John Ehlers. now how it will play a roll? if Laguerre RSI is under 0.5 of action bar then action bar indicating a uptrend and we will look for buy, if Laguerre RSI is over 0.5 of action bar then action bar indicating a downtrend and we will look for sell.

THE LEVEL

after getting the uptrend/downtrend action bar, we only have to click on that bar, there is an afl which will automaticaly draw s2,s3,s4,s5 and r2,r3,r4,r5.

if its downtrend action bar then we will look only for sell:
s2 will be our trigger price.
s4 will be our 1st target.
s5 will be our 2nd target.
r3 will be our stoploss.

if its uptrend action bar then we will look only for buy:
r2 will be our trigger price.
r4 will be our 1st target.
r5 will be our 2nd target.
s3 will be our stoploss.





THE LEVEL AFL:
PHP:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
Period = Param("Period", 25, 2, 100 ); 
bi = BarIndex(); 

procedure PlotLevel( array, nam, Color ) 
{ 
 x = SelectedValue( bi ); 
 y = SelectedValue( array ); 
 Plot( IIf( bi >= x AND bi < x + Period, y, Null ), 
       nam, Color, styleDashed ); 
 PlotText( nam, x + Period - 1, y, Color ); 
} 

pl = Ref( LLV( Low, Period ), -1 ); 
ph = Ref( HHV( High, Period ), -1 ); 
range = ph - pl; 
pc = Ref( Close, -1 ); 
R5 = ph/pl * pc; 
R4 = pc + Range * 1.1/2; 
R3 = pc + Range * 1.1/4; 
R2 = pc + Range * 1.1/6; 
R1 = pc + Range * 1.1/12; 

S1 = pc - Range * 1.1/12; 
S2 = pc - Range * 1.1/6; 
S3 = pc - Range * 1.1/4; 
S4 = pc - Range * 1.1/2; 
S5 = pc - ( R5 - pc ); 


Plot( C, Name() + " " + Date(), colorDefault, styleCandle ); 

PlotLevel( R5, "R5", colorBlue ); 
PlotLevel( R4, "R4", colorBlue ); 
PlotLevel( R3, "R3", colorBlue ); 
PlotLevel( R2, "R2", colorBlue ); 
//PlotLevel( R1, "R1", colorBlue ); 
//PlotLevel( S1, "S1", colorRed ); 
PlotLevel( S2, "S2", colorRed ); 
PlotLevel( S3, "S3", colorRed ); 
PlotLevel( S4, "S4", colorRed ); 
PlotLevel( S5, "S5", colorRed );
THE Laguerre RSI AFL:
PHP:
//Ehlers laguerre RSI
/*
The Laguerre transform provides a time warp such that the Low frequency components are delayed
 much more than the High frequency components. This enables very smooth filters to be built
 using a Short amount of data.
 The Laguerre RSI operates on four data points AND is smoother than an RSI(4).
*/

SetChartBkColor(ParamColor("Panel color ",colorOrange));

SetBarsRequired(200, 0);

// Ehlers formulas
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. 
// Chapter 14, p. 213. Code on p. 221.

function LRSI(array, gamma)
// Figure 14.8 on p. 221.
{
  L0 = array;  // Initialize as array
  L1 = array;
  L2 = array;
  L3 = array;
  LRSIValue = array;

  for(i = 1; i < BarCount; i++)
  {
     L0[i] = (1 - gamma)*array[i] + gamma*L0[i-1];
     L1[i] = - gamma * L0[i] + L0[i-1] + gamma * L1[i-1];
     L2[i] = - gamma * L1[i] + L1[i-1] + gamma * L2[i-1];
     L3[i] = - gamma * L2[i] + L2[i-1] + gamma * L3[i-1];

     CU = 0;
     CD = 0;
     if (L0[i] >= L1[i]) CU = L0[i] - L1[i]; else (CD = L1[i] - L0[i]);
     if (L1[i] >= L2[i]) CU = CU + L1[i] - L2[i]; else CD = CD + L2[i] - L1[i];
     if (L2[i] >= L3[i]) CU = CU + L2[i] - L3[i]; else CD = CD + L3[i] - L2[i];

     if (CU + CD != 0) LRSIValue[i] = CU / (CU + CD);
  }
  return LRSIValue;
}

Plot(LRSI(C, 0.5), "Laguerre RSI", colorWhite, styleLine);
PlotGrid(0.5);
if you have any question feel free to ask. thank you all.
 
#5
Hello amibrokerfan,
Your study n afls are just Jem.

Thanx you for sharing ur afls. i need your help



Kindly explain below lines again.

after getting the uptrend/downtrend action bar, we only have to click on that bar
What do you mean by Uptrend/Downtrend action bar??


i tried to use the levels afl in 15 min timeframe.
When i click on last bar i didnt find any levels after clicking on previous 2-3 candles then i got.

Kindly put some light on how to plot level and how to use them effectively.

Thanx you.
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?