Fast Fourier Transform - Cycle Extraction - page 26

 

mindhero

crodzilla:
I've run accross this FFT cycle indicator in the past couple of weeks. It is very interesting to say the least. I would like to know if anybody else has any experience with this type of cycle analysis.

I've know of Hurst, Clyde Lee, and Brian Millard. Brian Millards' work is among the best I've seen. Check out this page if you haven't seen his work yet: Brian Millard

The only thing is I am unsure as to the correct usage of this indicator.

I've been watching how these cycles work for weeks. Sometimes they are spot-on, other times they are out of sync. And, I think they are out of sync because of news that causes a major shift in the outlook of a currency. Its like throwing a stone into a pond. New waves cause the other waves to change phase.

Just playing around this morning (at work!?!?), I wanted to see how these cycle indicators would react. So, after the news, I began watching prices.

I'm using the 1M EURUSD because my account is small (FXCM), but the cycles still seem to work. From these pictures, the RED indicator is a composite of the highest magnitude of 7 cycles. The other colors are the top 4 cycles.

After the news, prices hit the daily pivot. The composite and individual cycles predicted a down move after that "Winding spring" just below the daily pivot at around 1.4320. The light green and orange cycles are topping out. The dark green and aqua are already on the way down. So I got short just before the downside break at 1.4312.

Putting my real money on the line, I made a nice low risk 45 pips for the day.

Crodzilla,

First of all thank you for posting mindhero. Would like to ask if mind hero indicator you posted has some fft or cycle extraction algorithm built in?

 

Hi, this code is supposed to state the dominant cycle period. It is called "Ehlers Dominant Cycle Period". Is it available as mq4 indicator?

Indicator: EhlersDominantCycle

inputs:

Price( MedianPrice ) ;

variables:

alpha1( 0 ),

alpha1Plus1( 0 ),

Log10( 0 ),

HP( 0 ),

SmoothHP( 0 ),

EhlersDelta( 0.1 ),

EhlersBeta( 0 ),

Cos720Delta( 0 ),

EhlersGamma( 0 ),

alpha( 0 ),

OneMinusAlpha( 0 ),

OnePlusAlpha( 0 ),

N( 0 ),

TwoPi( 6.2831854 ),

MaxAmpl( 0 ),

Num( 0 ),

Denom( 0 ),

DC( 0 ),

DomCyc( 0 ),

Cos720DeltaDom( 0 ),

SineLine( 0 ),

CosineLine( 0 ) ;

arrays:

EhlersI[50]( 0 ),

OldI[50]( 0 ),

OlderI[50]( 0 ),

Q[50]( 0 ),

OldQ[50]( 0 ),

OlderQ[50]( 0 ),

Real[50]( 0 ),

OldReal[50]( 0 ),

OlderReal[50]( 0 ),

Imag[50]( 0 ),

OldImag[50]( 0 ),

OlderImag[50]( 0 ),

Ampl[50]( 0 ),

OldAmpl[50]( 0 ),

DB[50]( 0 ) ;

if CurrentBar = 1 then

begin

{ 360 / 40 = 9 }

alpha1 = ( 1 - Sine( 9 ) ) / Cosine( 9 ) ;

alpha1Plus1 = alpha1 + 1 ;

Log10 = Log( 10 ) ;

end ;

HP = 0.5 * alpha1Plus1 * ( Price - Price[1] ) +

alpha1 * HP[1] ;

SmoothHP = ( HP + 2 * HP[1] + 3 * HP[2] + 3 * HP[3] +

2 * HP[4] + HP[5] ) / 12 ;

if CurrentBar = 1 then

SmoothHP = 0

else if CurrentBar < 7 then

SmoothHP = Price - Price[1] ;

EhlersDelta = -0.015 * CurrentBar + 0.5 ;

EhlersDelta = MaxList( 0.15, EhlersDelta ) ;

if CurrentBar > 6 then

begin

for N = 8 to 50

begin

EhlersBeta = Cosine( 360 / N ) ;

Cos720Delta = Cosine( 720 * EhlersDelta / N ) ;

if Cos720Delta 0 then

EhlersGamma = 1 / Cos720Delta ;

alpha = EhlersGamma -

SquareRoot( Square( EhlersGamma ) - 1 ) ;

OneMinusAlpha = 1 - alpha ;

OnePlusAlpha = 1 + alpha ;

Q[N] = ( N / TwoPi ) * ( SmoothHP -

SmoothHP[1] ) ;

EhlersI[N] = SmoothHP ;

Real[N] = 0.5 * OneMinusAlpha * ( EhlersI[N] -

OlderI[N] ) + EhlersBeta * OnePlusAlpha *

OldReal[N] - alpha * OlderReal[N] ;

Imag[N] = 0.5 * OneMinusAlpha * ( Q[N] -

OlderQ[N] ) + EhlersBeta * OnePlusAlpha *

OldImag[N] - alpha * OlderImag[N] ;

Ampl[N] = ( Square( Real[N] ) +

Square( Imag[N] ) ) ;

end ;

end ;

for N = 8 to 50

begin

OlderI[N] = OldI[N] ;

OldI[N] = EhlersI[N] ;

OlderQ[N] = OldQ[N] ;

OldQ[N] = Q[N] ;

OlderReal[N] = OldReal[N] ;

OldReal[N] = Real[N] ;

OlderImag[N] = OldImag[N] ;

OldImag[N] = Imag[N] ;

OldAmpl[N] = Ampl[N] ;

end ;

MaxAmpl = Ampl[10] ;

for N = 8 to 50

begin

if Ampl[N] > MaxAmpl then

MaxAmpl = Ampl[N] ;

end ;

for N = 8 to 50

begin

if MaxAmpl 0 and ( Ampl[N] / MaxAmpl ) > 0 then

DB[N] = -10 * Log( 0.01 / ( 1 - .99 * Ampl[N] /

MaxAmpl ) ) / Log10 ;

if DB[N] > 20 then

DB[N] = 20 ;

end ;

Num = 0 ;

Denom = 0 ;

for N = 10 to 50

begin

if DB[N] <= 3 then

begin

Num = Num + N * ( 20 - DB[N] ) ;

Denom = Denom + ( 20 - DB[N] ) ;

end ;

if Denom 0 then

DC = Num / Denom ;

end ;

DomCyc = Median( DC, 10 ) ;

if DomCyc < 8 then

DomCyc = 20 ;

EhlersBeta = Cosine( 360 / DomCyc ) ;

Cos720DeltaDom = Cosine( 720 * EhlersDelta / DomCyc ) ;

if Cos720DeltaDom 0 then

EhlersGamma = 1 / Cos720DeltaDom ;

alpha = EhlersGamma - SquareRoot( Square( EhlersGamma )

- 1 ) ;

SineLine = 0.5 * ( 1 - alpha ) * ( SmoothHP -

SmoothHP[1] ) + EhlersBeta * ( 1 + alpha ) *

SineLine[1] - alpha * SineLine[2] ;

CosineLine = ( DomCyc / TwoPi ) * ( SineLine -

SineLine[1] ) ;

if CurrentBar > 10 then

begin

Plot1( SineLine, "Sine", Red, default, 2 ) ;

Plot2( CosineLine, "Cosine", Cyan, default, 2 ) ;

end ;
 

Hi forex-bmn,

I found this thread:

https://www.mql5.com/en/forum/174980 - I hope - it will help.

 
newdigital:
Hi forex-bmn,

I found this thread:

https://www.mql5.com/en/forum/174980 - I hope - it will help.

Yes, I know this thread. The problem is I cannot identify this indicator. There is no indicator named "Dominant Cycle Period". Maybe it is there under different name. But I have no way to tell..

 

Hi,

It's so-called "DOMINANT CYCLE-TUNED BANDPASS FILTER" according to TASC V. 26:3 (16-22): Measuring Cycle Periods by John F. Ehlers:

"The sine component is plotted in red and the cosine component is plotted in cyan. The sine component is clearly a smoothed replica of the price bars and the cosine component is a leading function of the sine component."

Regards,

Igor

forex-bmn:
Yes, I know this thread. The problem is I cannot identify this indicator. There is no indicator named "Dominant Cycle Period". Maybe it is there under different name. But I have no way to tell..
Files:
 

Creating forecasts using objects

Greetings Mladen,

I have a quick question if I may. I know, in the past, you had created functions to forecasts linear indicators using objects (e.g. cycles). Is it possible you can give me a quick breakdown of the logic and he major function blocks for reference?

The objective is to be able to duplicate such functions into other indicators.

Thanks,

Pip

 

...

Pip

I do not know exactly which part are you referring to

In that project (in which you had a big part too) we had a problem with "multi time framing the forecast" and I gues that it is the part that you are talking about (since the forecast itself was straight forward : we had phase and amplitude of waves we were using for composite signal and all it took was to continue doing the "compositing" beyond the current bar too by inverting the sign). The solution for "multi time framing the future" was the simplest it gets : instead of forcing the current time frame to create objects and try to avoid missing bars and all kind of problems coming from not being able to draw on the "real future bars", we let the target time frame create the objects "in the future" and let those object "pretend" being on a current time frame (in which case we simple forced metatrader to draw them with starting and ending points in time determined by the target time frame

I hope that that is the part that you were asking about. If not, please let me know

regards

Mladen

Pip:
Greetings Mladen,

I have a quick question if I may. I know, in the past, you had created functions to forecasts linear indicators using objects (e.g. cycles). Is it possible you can give me a quick breakdown of the logic and he major function blocks for reference?

The objective is to be able to duplicate such functions into other indicators.

Thanks,

Pip
 
mladen:
Pip

I do not know exactly which part are you referring to

In that project (in which you had a big part too) we had a problem with "multi time framing the forecast" and I gues that it is the part that you are talking about (since the forecast itself was straight forward : we had phase and amplitude of waves we were using for composite signal and all it took was to continue doing the "compositing" beyond the current bar too by inverting the sign). The solution for "multi time framing the future" was the simplest it gets : instead of forcing the current time frame to create objects and try to avoid missing bars and all kind of problems coming from not being able to draw on the "real future bars", we let the target time frame create the objects "in the future" and let those object "pretend" being on a current time frame (in which case we simple forced metatrader to draw them with starting and ending points in time determined by the target time frame

I hope that that is the part that you were asking about. If not, please let me know

regards

Mladen

Thanks Mladen,

I will re-read your post to understand, honestly i got a bit lost reading it but it is most likely my ignorance taking play. I will post questions if i have any.

Thanks mate.

Cheers,

Pip

 

Mladen,

I give up! I am trying to extend the cycles identified by the attached indicator into the future. I know it repaints but am running an experiment.

If possible, can you add the code that will enable each cycle (including the composite cycle) to be forecasted into the future with necessary boolean for each?

Also, is it possible to program the forecast so that the starting point of the forecast can be selected? for example, i would like to be able to set the forecast to start at bar 6 instead of bar 0 to sort of test the forecast with most recent history before qualifying it.

If too much work then don't worry about it and I am most thankful for your time reading this post.

Regards,

Pip

mladen:
Pip

I do not know exactly which part are you referring to

In that project (in which you had a big part too) we had a problem with "multi time framing the forecast" and I gues that it is the part that you are talking about (since the forecast itself was straight forward : we had phase and amplitude of waves we were using for composite signal and all it took was to continue doing the "compositing" beyond the current bar too by inverting the sign). The solution for "multi time framing the future" was the simplest it gets : instead of forcing the current time frame to create objects and try to avoid missing bars and all kind of problems coming from not being able to draw on the "real future bars", we let the target time frame create the objects "in the future" and let those object "pretend" being on a current time frame (in which case we simple forced metatrader to draw them with starting and ending points in time determined by the target time frame

I hope that that is the part that you were asking about. If not, please let me know

regards

Mladen
 

...

As far as spedometr is concerned, it will be something like this (just one "forecast" in the example):

Need to convert all the forecasts to object. Will post it when finished

Pip:
Mladen,

I give up! I am trying to extend the cycles identified by the attached indicator into the future. I know it repaints but am running an experiment.

If possible, can you add the code that will enable each cycle (including the composite cycle) to be forecasted into the future with necessary boolean for each?

Also, is it possible to program the forecast so that the starting point of the forecast can be selected? for example, i would like to be able to set the forecast to start at bar 6 instead of bar 0 to sort of test the forecast with most recent history before qualifying it.

If too much work then don't worry about it and I am most thankful for your time reading this post.

Regards,

Pip
Files:
cycles.gif  30 kb
Reason: