made some nice code to analyse if any significant periodicity is visible in the data. This time I filter the data in the time domain using a Gaussian type function. When you start the code it will show the raw data and the Gauss filter. In the param window you can toggle to filtered data. Also you can toggle to the Frequency spectrum.

When you display the filtered data you can slide the chart all the way to bar 0 and then have a look at the Gauss filter. The filter can be changed in the param window (width and sigma).

the more data you use the more apparent any periodicity hidden in the data will become. So far I do not see any.

```
/*
© AFL code E.M.Pottasch, 11/2017
originated here: http://forum.amibroker.com/t/fast-fourier-transform-fft/3098/11
code is an attempt to explore the use of frequency analysis in trading
this version filters the data in the time domain using a Gaussian type function
*/
SetBarsRequired( sbrAll, sbrAll );
len = Param( "Length of Data rray", 2048, 16, 4096, 2 );
view = ParamToggle( "Frequency/Time Domain Toggle", "Frequency Domain| Time domain", 1 );
view2 = ParamToggle( "Raw/Filtered Data Toggle (Time Domain)", "Raw Data| Filtered Data", 0 );
bins1 = 0;
bins2 = len / 2;
fw = Param( "Filter Width (Bars)", 21, 1, 150, 2 );
sigma1 = Param( "Sigma", 5, 0.1, 50, 0.1 );
GaussBell = Null; // store the Gauss Bell for display purposes
function FIR_AFL( input, coeff, size )
{
result = 0;
sumcoeff = 0;
for( i = 0; i < Min( size, BarCount ); i++ )
{
sumcoeff += coeff[ i ];
result += coeff[ i ] * Ref( input, - int( size / 2 ) + i );
}
return result / sumcoeff;
}
function ALMA_AFL( input, range, Offset, sigma )
{
local m, im, s, Coeff;
m = floor( Offset * ( range - 1 ) );
s = range / sigma;
for( i = 0; i < Min( range, BarCount ); i++ )
{
im = i - m;
GaussBell[i] = Coeff[ i ] = exp( - ( im * im ) / ( 2 * s * s ) );
}
return FIR_AFL( input, Coeff, range );
}
data = ( H + L + C ) / 3;
// calculate convolution filter
conv = ALMA_AFL( data, fw, 0.5, sigma1 );
filtered_data = data - conv;
// DFT
ffc = FFT( filtered_data, len );
// Real and Imaginary Parts in Frequency Domain (Amibroker manual)
fRe = fIm = 0;
if( len < BarCount )
{
for( k = 0; k < ( len / 2 ); k++ )
{
fRe[k] = ffc[2 * k];
fIm[k] = ffc[2 * k + 1];
}
// http://www.dspguide.com/CH8.PDF, page 153
tRe = 2 * fRe / len;
tRe[0] = fRe[0] / len;
tRe[len / 2 - 1] = fRe[len / 2 - 1] / len;
tIm = -2 * fIm / len;
if( view )
{
if( view2 == 1 )
{
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
Plot( filtered_data, "Filtered Data", ColorRGB( 0, 0, 255 ), styleLine, Null, Null, 0, 0, 2 );
Plot( GaussBell, "", ColorRGB( 0, 250, 255 ), styleLine | styleOwnScale, Null, Null, 0, 0, 5 ); // Gauss Bell Plotted in the first few bars
}
else
if( view2 == 0 )
{
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
Plot( Close, "Price", colorDefault, styleCandle, Null, Null, 0, 0, 1 );
Plot( data, "Raw Data", ColorRGB( 0, 0, 255 ), styleLine, Null, Null, 0, 0, 2 );
Plot( conv, "Filter", ColorRGB( 250, 250, 255 ), styleLine, Null, Null, 0, 0, 2 );
}
}
else
{
// power spectrum calculation
power = ( tRe + tIm ) ^ 2;
GfxSetOverlayMode( 2 );
GfxSetCoordsMode( 0 );
GfxSelectPen( ColorRGB( 90, 90, 90 ), 1, 0 );
pxwidth = Status( "pxwidth" );
pxheight = Status( "pxheight" );
margin = int( pxwidth / 20 );
// chart border
GfxMoveTo( margin, margin );
GfxLineTo( pxwidth - margin, margin );
GfxLineTo( pxwidth - margin, pxheight - margin );
GfxLineTo( margin, pxheight - margin );
GfxLineTo( margin, margin );
GfxSelectFont( "Tahoma", 15, 700, False, False, 0 );
GfxTextOut( " Frequency " , pxwidth / 2, pxheight - margin / 2 );
GfxSelectFont( "Tahoma", 15, 700, False, False, 900 );
GfxTextOut( " Power " , margin / 2, pxheight / 2 );
maxpower = 0;
for( i = 0; i < ( len / 2 ); i++ )
{
if( power[i] > maxpower )
{
maxpower = power[i];
}
}
xbin = ( pxwidth - 2 * margin ) / ( ( len / 2 ) - 1 );
ybin = ( pxheight - 2 * margin ) / maxpower;
GfxSelectPen( ColorRGB( 0, 255, 255 ), 6, 0 );
for( i = 0; i < ( len / 2 ); i++ )
{
GfxMoveTo( margin + i * xbin, pxheight - margin );
GfxLineTo( margin + i * xbin, pxheight - margin - power[i]*ybin );
}
nyquist = 1 / ( 2 * Interval() );
RequestMouseMoveRefresh();
px = GetCursorXPosition( 1 );
py = GetCursorYPosition( 1 );
GfxSelectFont( "Tahoma", 10, 700, False, False, 0 );
if( px > margin AND px < pxwidth - margin )
{
pxr = ( px - margin ) / ( pxwidth - 2 * margin ) ;
freq = pxr * nyquist;
wavelength = ( 1 / freq ) / ( 24 * 60 * 60 );
GfxSetTextColor( ColorRGB( 0, 0, 0 ) );
GfxSetBkColor( ColorRGB( 255, 255, 0 ) );
if( px < pxwidth / 2 )
GfxTextOut( " Frequency: " + pxr * nyquist + " Hz, Wavelength: " + prec( wavelength, 2 ) + " days " , px + 15, py );
if( px > pxwidth / 2 )
GfxTextOut( " Frequency: " + pxr * nyquist + " Hz, Wavelength: " + Prec( wavelength, 2 ) + " days " , px - 400, py );
}
}
}
```