<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dominant Cycle &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/dominant-cycle/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Fri, 17 Apr 2026 14:55:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://financial-hacker.com/wp-content/uploads/2017/07/cropped-mask-32x32.jpg</url>
	<title>Dominant Cycle &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>The AutoTune filter</title>
		<link>https://financial-hacker.com/the-autotune-filter/</link>
					<comments>https://financial-hacker.com/the-autotune-filter/#comments</comments>
		
		<dc:creator><![CDATA[Petra Volkova]]></dc:creator>
		<pubDate>Fri, 17 Apr 2026 14:53:29 +0000</pubDate>
				<category><![CDATA[Indicators]]></category>
		<category><![CDATA[Petra on Programming]]></category>
		<category><![CDATA[System Development]]></category>
		<category><![CDATA[Dominant Cycle]]></category>
		<category><![CDATA[Ehlers]]></category>
		<guid isPermaLink="false">https://financial-hacker.com/?p=4989</guid>

					<description><![CDATA[By the Fourier theorem, any price curve is a mix of many long-term and short-term cycles. Once in a while a dominant market cycle emerges and can be exploited for trading. In his TASC 5/2026 article, John Ehlers described an algorithm for detecting such dominant cycles, using them to tune a bandpass filter, and creating &#8230; <a href="https://financial-hacker.com/the-autotune-filter/" class="more-link">Continue reading<span class="screen-reader-text"> "The AutoTune filter"</span></a>]]></description>
										<content:encoded><![CDATA[<p><em>By the Fourier theorem, any price curve is a mix of many long-term and short-term cycles. Once in a while a <strong>dominant market cycle</strong> emerges and can be exploited for trading. In his TASC 5/2026 article, <strong>John Ehlers</strong> described an algorithm for detecting such dominant cycles, using them to tune a bandpass filter, and creating a profitable trading system. Here&#8217;s how to do it.</em></p>
<p><span id="more-4989"></span></p>
<p>Ehlers&#8217; Easylanguage code from the TASC article can be directly converted to C for Zorro.  ChatGPT does the job in a few seconds. First, the cycle detector:</p>
<pre class="prettyprint">var MinCorr, Filt;
var AutoTune(vars Data,int Window)
{
  Filt = HighPass3(Data,Window);
  vars HP = series(Filt);
  var Corr[256];
  int Lag, J;
  for(Lag = 1; Lag &lt;= Window; Lag++)
  {
    var Sx = 0., Sy = 0.;
    var Sxx = 0., Sxy = 0., Syy = 0.;
    for(J = 0; J &lt; Window; J++)
    {
      var X = HP[J];
      var Y = HP[Lag + J];
      Sx += X; Sy += Y;
      Sxx += X*X; Sxy += X*Y; Syy += Y*Y;
    }
    var Den1 = Window*Sxx - Sx*Sx;
    var Den2 = Window*Syy - Sy*Sy;
    Corr[Lag] = (Window*Sxy - Sx*Sy) / sqrt(fix0(Den1*Den2));
  }

  MinCorr = 1.;
  var DC = Window;
  for(Lag = 1; Lag &lt;= Window; Lag++)
    if(Corr[Lag] &lt; MinCorr) {
      MinCorr = Corr[Lag];
      DC = 2*Lag;
    }

  vars DCs = series(DC,2);
  return DCs[0] = clamp(DC,DCs[1]-2.,DCs[1]+2.);
}</pre>
<p>The output of the <strong>AutoTune</strong> function is supposed to be the dominant price cycle in units of bars. It is then used to set the center frequency of a bandpass filter. Since Zorro has already a bandpass filter in its arsenal, I named Ehlers&#8217; new version <strong>BandPass2</strong>:</p>
<pre class="prettyprint">var BandPass2(vars Data, int Period, var Bandwidth)
{
  var L1 = cos(2.*PI/Period);
  var G1 = cos(Bandwidth*2.*PI/Period);
  var S1 = 1./G1 - sqrt(1./(G1*G1) - 1.);
  vars BP = series(0,3);
  return BP[0] = 0.5*(1.-S1)*(Data[0]-Data[2]) 
    + L1*(1.+S1)*BP[1] - S1*BP[2];
}</pre>
<p>Here&#8217;s some code for reproducing Ehlers’ ES chart in the article:</p>
<pre class="prettyprint">function run()
{
  BarPeriod = 1440;
  StartDate = 2024;
  EndDate = 2025;
  asset("ES");
  var DC = AutoTune(seriesC(),20);
  var BP = BandPass2(seriesC(),DC,0.25);
  plot("Zero",0,NEW,BLACK);
  plot("BP",BP,LINE,BLUE);
}</pre>
<p>The resulting chart:</p>
<p><img fetchpriority="high" decoding="async" width="877" height="514" class="wp-image-4990" src="https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-1.png" srcset="https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-1.png 877w, https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-1-300x176.png 300w, https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-1-768x450.png 768w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></p>
<p>How can we use this bandpass output for a trade signal? Ehlers used the zero crossovers of its rate-of-change (ROC). In this way he generated an impressive equity curve in his article, unfortunately with in-sample optimization. For a more realistic result, we’re using <strong>walk-forward analysis</strong> and reinvest profits by the <strong>square root rule</strong>:</p>
<pre class="prettyprint">function run()
{
  BarPeriod = 1440;
  StartDate = 2010;
  EndDate = 2025;
  Capital = 100000;

  asset("ES");
  set(TESTNOW,PARAMETERS);
  NumWFOCycles = 10;

  int Window = optimize("Window",26,10,30,2);
  var BW = optimize("BW",0.22,0.10,0.30,0.01);
  var Thresh = -optimize("Thresh",0.22,0.1,0.3,0.01);
  var DC = AutoTune(seriesC(),Window);
  var BP = BandPass2(seriesC(),DC,BW);
  vars ROCs = series(BP-ref(BP,2));
  
  Lots = 0.5*(Capital+sqrt(1.+ProfitTotal/Capital))/MarginCost;
  MaxLong = MaxShort = 1;
  if(crossOver(ROCs,0) &amp;&amp; MinCorr &lt; Thresh)
    enterLong();
  if(crossUnder(ROCs,0) &amp;&amp; MinCorr &lt; Thresh &amp;&amp; Filt &gt; 0)
    enterShort();
}</pre>
<p>The signals are filtered by a threshold that determines whether we&#8217;re in a cyclic market condition or not. The system is not fully symmetrical in long and short positions. Training and testing produced this equity curve:</p>
<p><img decoding="async" width="701" height="405" class="wp-image-4991" src="https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-2.png" srcset="https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-2.png 701w, https://financial-hacker.com/wp-content/uploads/2026/04/word-image-4989-2-300x173.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></p>
<p>This curve does not look as impressive as Ehler’s one, but the CAGR is in the 25% area, much better than a buy-and-hold strategy. The code can be downloaded from the 2026 script repository.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/the-autotune-filter/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
