<?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>Decycler &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/decycler/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Fri, 22 Oct 2021 14:01:01 +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>Decycler &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>The Trend Experiment</title>
		<link>https://financial-hacker.com/trend-and-exploiting-it/</link>
					<comments>https://financial-hacker.com/trend-and-exploiting-it/#comments</comments>
		
		<dc:creator><![CDATA[jcl]]></dc:creator>
		<pubDate>Mon, 07 Sep 2015 06:44:42 +0000</pubDate>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[System Development]]></category>
		<category><![CDATA[System Evaluation]]></category>
		<category><![CDATA[Decycler]]></category>
		<category><![CDATA[Experiment]]></category>
		<category><![CDATA[Low-Lag]]></category>
		<category><![CDATA[Momentum]]></category>
		<guid isPermaLink="false">http://www.financial-hacker.com/?p=53</guid>

					<description><![CDATA[This is the second part of the trend experiment article series, involving 900 systems and 10 different &#8220;smoothing&#8221; or &#8220;low-lag&#8221; indicators for finding out if trend really exists and can be exploited by a simple algorithmic system. When you do such an experiment, you have normally some expectations about the outcome, such as: Trend exists, but is difficult &#8230; <a href="https://financial-hacker.com/trend-and-exploiting-it/" class="more-link">Continue reading<span class="screen-reader-text"> "The Trend Experiment"</span></a>]]></description>
										<content:encoded><![CDATA[<p>This is the second part of the <a href="http://www.financial-hacker.com/trend-delusion-or-reality/">trend experiment</a> article series, involving 900 systems and 10 different &#8220;smoothing&#8221; or &#8220;low-lag&#8221; indicators for finding out if trend really exists and can be exploited by a <strong>simple algorithmic system</strong>. When you do such an experiment, you have normally some expectations about the outcome, such as:<span id="more-53"></span></p>
<ul style="list-style-type: square;">
<li>Trend exists, but is difficult to detect and to exploit. The experiment will find only a few profitable and a lot more unprofitable systems (with realistic trade costs).</li>
<li>More sophisticated indicators, such as the Decycler or the Lowpass filter, will produce better results than the old SMA, EMA, or HMA. Modern indicators have less lag and thus react faster on the begin and end of a trend.</li>
<li>White&#8217;s Reality Check will reveal a data mining bias rather close to the returns of the best systems from the experiment. If algorithmic trend trading were easy, anyone would be doing it.</li>
<li>EUR/USD will return better results because according to trader&#8217;s wisdom, currencies are &#8220;more trending&#8221;.</li>
</ul>
<p>However the results were quite a surprise.</p>
<h3>The Trend Test System</h3>
<p>This is the script <strong>Trend.c</strong> used for the trend experiment:</p>
<pre class="prettyprint">var objective() 
{ 
  return WinTotal/max(1,LossTotal); <span style="color: #0000ff;">// Profit factor</span>
}

var filter(var* Data,int Period);

void run()
{
  set(PARAMETERS|LOGFILE);
  PlotHeight1 = 200;
  PlotScale = 8;
  ColorBars[1] = BLACK; <span style="color: #0000ff;">// winning trades</span>
  ColorBars[2] = GREY; <span style="color: #0000ff;">// losing trades</span>

  StartDate = 2010;
  BarPeriod = 15;
  LookBack = 80*4*24; <span style="color: #0000ff;">// 80 trading days ~ 4 months</span>
	
  while(asset(loop("EUR/USD","SPX500","XAG/USD")))
  while(algo(loop("M15","H1","H4")))
  {
    if(Algo == "M15")
      TimeFrame = 1; // 15 minutes
    else if(Algo == "H1")
      TimeFrame = 4; // 1 hour
    else if(Algo == "H4")
      TimeFrame = 16;	// 4 hours

    int Periods[10] = { 10,20,50,100,200,500,1000,2000,5000,10000 };
    int Period = Periods[optimize(0,0,9,1)];
		
    vars Prices = series(price());
    vars Smoothed = series(filter(Prices,Period));

    if(valley(Smoothed))
      enterLong();
    else if(peak(Smoothed))
      enterShort();
  } 
}</pre>
<p>This script is supposed to run in Zorro&#8217;s &#8220;Train&#8221; mode. We&#8217;re not really training the systems, but Train mode produces parameter histograms, and that&#8217;s what we want. The script is basically the same as described in the <a href="http://www.financial-hacker.com/trend-delusion-or-reality/">previous article</a>, but two asset and algo loops are now used for cycling through three different assets (EUR/USD, S&amp;P 500, and Silver) and three time frames (15 minutes, 1 hour, 4 hours). The <strong>optimize</strong> function selects the time period of the smoothing indicator, in 10 steps from 10 to 10,000 time frames. The meaning of the Zorro-specific functions like <strong>asset</strong>, <strong>algo</strong>, <strong>loop</strong>, <strong>optimize</strong> can be found in the <a href="http://manual.zorro-trader.com" target="_blank" rel="noopener noreferrer">Zorro manual</a>.</p>
<p>6 years of price history from 2010 to 2015 are used for the simulation. The default trade costs &#8211; commission, bid/ask spread, and rollover &#8211; are taken from the average 2015 parameters of a FXCM microlot account. FXCM is not the cheapest broker, so the expectation value of a random-trading simulation is not zero, but a loss, dependent on the number of trades. For comparing results we&#8217;re using the profit factor, calculated in the <strong>objective</strong> function. The script calls a <strong>filter</strong> function that is defined as a prototype, and contained in a main script that includes <strong>Trend.c</strong>. So any of the indicators is represented by a very short main script like this (<strong>TrendLowpass.c</strong>):</p>
<pre class="prettyprint">#include "Strategy\Trend.c"

var filter(var* Data,int Period)
{
  return LowPass(Data,Period);
}</pre>
<p>All the scripts can be downloaded from the <strong>scripts2015</strong> archive at the sidebar. There&#8217;s also a batch file included that starts them all and lets them run in parallel.</p>
<h3>The Results</h3>
<p>When you select one of the scripts and click Zorro&#8217;s  <strong>[Train]</strong> button, it will grind its wheels about 10 minutes and then spit out a sheet of histograms like this (for the ZMA):</p>
<p><a href="http://www.financial-hacker.com/wp-content/uploads/2015/09/ZMA.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-159" src="http://www.financial-hacker.com/wp-content/uploads/2015/09/ZMA.png" alt="ZMA" width="1253" height="641" srcset="https://financial-hacker.com/wp-content/uploads/2015/09/ZMA.png 1253w, https://financial-hacker.com/wp-content/uploads/2015/09/ZMA-300x153.png 300w, https://financial-hacker.com/wp-content/uploads/2015/09/ZMA-1024x524.png 1024w, https://financial-hacker.com/wp-content/uploads/2015/09/ZMA-1200x614.png 1200w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a></p>
<p>We got 9 histograms from the combinations of EUR/USD, S&amp;P 500, and Silver (horizontally) with bar sizes of 15 minutes, 1 hour, and 4 hours. The red bars are the <strong>objective</strong> return &#8211; in this case, the <strong>profit factor</strong>,  total win divided by total loss. If they are above <strong>1.0</strong> (left scale), the system was profitable. The black and grey bars are the number of winning and losing trades (right scale). The steps on the X axis are the indicator time period; they normally don&#8217;t go all the way to 10 because systems are discarded when the time period exceeded 4 months or the system entered less than 30 trades. That&#8217;s why the experiment didn&#8217;t produce 900 systems, but only 705.</p>
<p>We can see that the profit generally increases, and the number of trades decreases with the time frame. As typical for trend trading systems we got far more losing trades (grey) than winning trades (black). 13 of the 82 systems in the histograms above have been profitable, 69 were losers. Most of the profitable systems traded EUR/USD. Only one S&amp;P 500 system, and only three silver trading systems produced any profit. Here&#8217;s a statistic of all winners and losers from the 705 tested systems:</p>
<table>
<tbody>
<tr>
<td>Asset, Period, Indicator</td>
<td style="text-align: right;">Rate</td>
<td style="text-align: right;">Total</td>
<td style="text-align: right;">Won</td>
<td style="text-align: right;">Lost</td>
</tr>
<tr>
<td><strong>EUR/USD</strong></td>
<td style="text-align: right;"><strong>38%</strong></td>
<td style="text-align: right;"><strong>237</strong></td>
<td style="text-align: right;"><strong>89</strong></td>
<td style="text-align: right;"><strong>148</strong></td>
</tr>
<tr>
<td><strong>S&amp;P 500</strong></td>
<td style="text-align: right;"><strong>3%</strong></td>
<td style="text-align: right;"><strong>237</strong></td>
<td style="text-align: right;"><strong>6</strong></td>
<td style="text-align: right;"><strong>231</strong></td>
</tr>
<tr>
<td><strong>Silver</strong></td>
<td style="text-align: right;"><strong>21%</strong></td>
<td style="text-align: right;"><strong>231</strong></td>
<td style="text-align: right;"><strong>48</strong></td>
<td style="text-align: right;"><strong>183</strong></td>
</tr>
<tr>
<td><strong>15 Minutes</strong></td>
<td style="text-align: right;"><strong>14%</strong></td>
<td style="text-align: right;"><strong>297</strong></td>
<td style="text-align: right;"><strong>41</strong></td>
<td style="text-align: right;"><strong>256</strong></td>
</tr>
<tr>
<td><strong>1 Hour</strong></td>
<td style="text-align: right;"><strong>20%</strong></td>
<td style="text-align: right;"><strong>239</strong></td>
<td style="text-align: right;"><strong>48</strong></td>
<td style="text-align: right;"><strong>191</strong></td>
</tr>
<tr>
<td><strong>4 Hours</strong></td>
<td style="text-align: right;"><strong>32%</strong></td>
<td style="text-align: right;"><strong>169</strong></td>
<td style="text-align: right;"><strong>54</strong></td>
<td style="text-align: right;"><strong>115</strong></td>
</tr>
<tr>
<td><strong>ALMA</strong></td>
<td style="text-align: right;"><strong>16%</strong></td>
<td style="text-align: right;"><strong>64</strong></td>
<td style="text-align: right;"><strong>10</strong></td>
<td style="text-align: right;"><strong>54</strong></td>
</tr>
<tr>
<td><strong>Decycle</strong></td>
<td style="text-align: right;"><strong>15%</strong></td>
<td style="text-align: right;"><strong>74</strong></td>
<td style="text-align: right;"><strong>11</strong></td>
<td style="text-align: right;"><strong>63</strong></td>
</tr>
<tr>
<td><strong>EMA</strong></td>
<td style="text-align: right;"><strong>20%</strong></td>
<td style="text-align: right;"><strong>69</strong></td>
<td style="text-align: right;"><strong>14</strong></td>
<td style="text-align: right;"><strong>55</strong></td>
</tr>
<tr>
<td><strong>HMA</strong></td>
<td style="text-align: right;"><strong>25%</strong></td>
<td style="text-align: right;"><strong>63</strong></td>
<td style="text-align: right;"><strong>16</strong></td>
<td style="text-align: right;"><strong>47</strong></td>
</tr>
<tr>
<td><strong>Laguerre</strong></td>
<td style="text-align: right;"><strong>31%</strong></td>
<td style="text-align: right;"><strong>32</strong></td>
<td style="text-align: right;"><strong>10</strong></td>
<td style="text-align: right;"><strong>22</strong></td>
</tr>
<tr>
<td><strong>LinearReg</strong></td>
<td style="text-align: right;"><strong>26%</strong></td>
<td style="text-align: right;"><strong>74</strong></td>
<td style="text-align: right;"><strong>19</strong></td>
<td style="text-align: right;"><strong>53</strong></td>
</tr>
<tr>
<td><strong>Lowpass</strong></td>
<td style="text-align: right;"><strong>20%</strong></td>
<td style="text-align: right;"><strong>71</strong></td>
<td style="text-align: right;"><strong>14</strong></td>
<td style="text-align: right;"><strong>57</strong></td>
</tr>
<tr>
<td><strong>SMA</strong></td>
<td style="text-align: right;"><strong>23%</strong></td>
<td style="text-align: right;"><strong> 70</strong></td>
<td style="text-align: right;"><strong> 16</strong></td>
<td style="text-align: right;"><strong> 54</strong></td>
</tr>
<tr>
<td><strong>Smooth</strong></td>
<td style="text-align: right;"><strong>19%</strong></td>
<td style="text-align: right;"><strong>108</strong></td>
<td style="text-align: right;"><strong>20</strong></td>
<td style="text-align: right;"><strong>88</strong></td>
</tr>
<tr>
<td><strong>ZMA</strong></td>
<td style="text-align: right;"><strong>16%</strong></td>
<td style="text-align: right;"><strong>82</strong></td>
<td style="text-align: right;"><strong>13</strong></td>
<td style="text-align: right;"><strong>69</strong></td>
</tr>
</tbody>
</table>
<p>Since the results are for 2010-2015, you might get different figures when testing different time periods. The <strong>Rate</strong> column shows the percentage of successful systems. We got a mix of expected and unexpected results. Almost 40% of the EUR/USD systems are winners,  which seems to confirm that currencies tend to trend. The S&amp;P 500 index however is not trending at all &#8211;  and this despite the fact that it shows the most significant trend in the long run, as visible in the title image. But here we&#8217;re looking for shorter term trends that can be exploited by day trading. Silver, with 20% winners, has at least some trend. Longer time frames produce dramatically better results, mostly due to less trade costs, but also partly because trend seems to prefer long cycles and low frequencies. (You can see that the difference comes not from trade costs alone when you test the systems with spread, commission, slippage, and rollover set to zero). 1-day bar periods would be even more profitable. But I haven&#8217;t included them in the test because they produce not enough trades for statistical significance.</p>
<p>The indicators show a surprising behavior. The old traditional indicators put up a good fight. Ehler&#8217;s smoothing, decycling, and zero-lag indicators, produce less profitable systems than their classic counterparts. However we&#8217;ll see later that the modern indicators are in fact more profitable, although within a smaller parameter range. But they all occupy the top of the profit list. The best systems, with modern indicators and long time frames, have profit factors up to <strong>2</strong>.</p>
<p>Does this mean that we can put them together in a compound system and will get rich? I don&#8217;t know, because I haven&#8217;t determined yet the Data Mining Bias produced by this experiment. For this we need to store and randomize the balance curves, and apply <strong>White&#8217;s Reality Check</strong>. This will be the topic of the <a href="http://www.financial-hacker.com/whites-reality-check/">next article</a> of the Trend Experiment series.</p>
<h3>Conclusion</h3>
<ul style="list-style-type: square;">
<li>Different markets show very different behavior. EUR/USD and silver are significantly more profitable with short-term trend following than S&amp;P500.</li>
<li>Low-lag smoothing indicators have a smaller profitable parameter range than traditional indicators, but produce higher profits.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/trend-and-exploiting-it/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Trend Indicators</title>
		<link>https://financial-hacker.com/trend-delusion-or-reality/</link>
					<comments>https://financial-hacker.com/trend-delusion-or-reality/#comments</comments>
		
		<dc:creator><![CDATA[jcl]]></dc:creator>
		<pubDate>Fri, 04 Sep 2015 16:48:13 +0000</pubDate>
				<category><![CDATA[Indicators]]></category>
		<category><![CDATA[System Evaluation]]></category>
		<category><![CDATA[Decycler]]></category>
		<category><![CDATA[Ehlers]]></category>
		<category><![CDATA[Low-Lag]]></category>
		<category><![CDATA[Momentum]]></category>
		<category><![CDATA[Zorro]]></category>
		<guid isPermaLink="false">http://www.lotter.org/hacker/?p=19</guid>

					<description><![CDATA[The most common trade method is &#8216;going with the trend&#8216;. While it&#8217;s not completely clear how one can go with the trend without knowing it beforehand, most traders believe that &#8216;trend&#8217; exists and can be exploited. &#8216;Trend&#8217; is supposed to manifest itself in price curves as a sort of momentum or inertia that continues a price &#8230; <a href="https://financial-hacker.com/trend-delusion-or-reality/" class="more-link">Continue reading<span class="screen-reader-text"> "Trend Indicators"</span></a>]]></description>
										<content:encoded><![CDATA[<p>The most common trade method is &#8216;<strong>going with the trend</strong>&#8216;. While it&#8217;s not completely clear how one can go with the trend without knowing it beforehand, most traders believe that &#8216;trend&#8217; exists and can be exploited. &#8216;Trend&#8217; is supposed to manifest itself in price curves as a sort of <strong>momentum</strong> or <strong>inertia</strong> that continues a price movement once it started. This inertia effect does not appear in random walk curves.<span id="more-19"></span> One can speculate about possible causes of trend, such as:</p>
<ul style="list-style-type: square;">
<li>Information spreads slowly, thus producing a delayed, prolonged reaction and price movement. (There are examples where it took the majority of traders <strong>more than a year</strong> to become aware of essential, fundamental information about a certain market!)</li>
<li>Events trigger other events with a similar effect on the price, causing a sort of avalanche effect.</li>
<li>Traders see the price move, shout &#8220;Ah! Trend!&#8221; and jump onto the bandwagon, thus creating a self fulfilling prophecy.</li>
<li>Trade algorithms detect a trend, attempt to exploit it and amplify it this way.</li>
<li>All of this, but maybe on different time scales.</li>
</ul>
<p>Whatever the cause, hackers prefer experiment over speculation, so let&#8217;s test once and for all if trend in price curves really exists and can be exploited in an algorithmic strategy. Exploiting trend obviously means buying at the begin of a trend, and selling at the end. For this, we simply assume that trend begins at the bottom of a price curve valley and ends at a peak, or vice versa. Obviously this assumption makes no difference between &#8216;real&#8217; trends and random price fluctuations. Such a difference could anyway only be determined in hindsight. However, trade profits and losses by random fluctuations should cancel out each other in the long run, at least when trade costs are disregarded. When trends exist in price curves, this method should produce an overall profit from the the remaining trades that are triggered by real trends and last longer than in random walk curves. And hopefully this profit will exceed the costs of the random trades. At least &#8211; that&#8217;s the theory. So we&#8217;re just looking for peaks and valleys of the price curve. The script of the trend following experiment would look like this (all scripts here are in C for the <a href="http://www.financial-hacker.com/hackers-tools-zorro-and-r/">Zorro</a> platform; <strong>var</strong> is typedef&#8217;d to <strong>double</strong>):</p>
<pre>void run()
{
  var *Price = series(price());
  var *Smoothed = series(Filter(Price,Period));
  
  if(valley(Smoothed))
    enterLong();
  else if(peak(Smoothed))
    enterShort();
}</pre>
<p>This strategy is simple enough. It is basically the first strategy from the <a href="http://manual.zorro-trader.com/tutorial_var.htm" target="_blank" rel="noopener noreferrer">Zorro tutorial</a>. The <strong>valley</strong> function returns <strong>true</strong> when the last price was below the current price and also below the last-but-one price; the <strong>peak</strong> function returns <strong>true</strong> when the last price was above the current and the last-but-one. Trades are thus entered at all peaks and valleys and closed by reversal only. For not getting too many random trades and too high trade costs, we&#8217;re removing the high frequencies from the price curve with some smoothing indicator, named <strong>Filter</strong> in the code above. Trend, after all, is supposed to be longer-lasting and should manifest itself in the lower frequencies. This is an example trade produced by this system: <a href="http://www.financial-hacker.com/wp-content/uploads/2015/09/work4_detail.png"><img decoding="async" class="alignnone size-full wp-image-195" src="http://www.financial-hacker.com/wp-content/uploads/2015/09/work4_detail.png" alt="work4_detail" width="680" height="321" srcset="https://financial-hacker.com/wp-content/uploads/2015/09/work4_detail.png 680w, https://financial-hacker.com/wp-content/uploads/2015/09/work4_detail-300x142.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a> The black jagged line in the chart above is the raw price curve, the red line is the filtered curve. You can see that it lags behind the black curve a little, which is typical of smoothing indicators. It has a peak at the end of September and thus entered a short trade (tiny green dot). The red line continues going down all the way until November 23, when a valley was reached. A long trade (not shown in this chart) was then entered and the short trade was closed by reversal (other tiny green dot). The green straight line connects the entry and exit points of the trade. It was open almost 2 months and made in that time a profit of ~ 13 cents per unit, or 1300 pips.</p>
<p>The only remaining question is &#8211; which indicator shall we use for filtering out the high frequencies, the ripples and jaggies, from the price curve? We&#8217;re spoilt for choice.</p>
<h3><strong>The Smoothing Candidates</strong></h3>
<p>Smoothing a curve in some way is a common task of all trend strategies. Consequently, there&#8217;s a multitude of smoothing, averaging, low-lag and spectral filter indicators at our disposal. We have to test them. The following candidates were selected for the experiment, traditional indicators as well as fancier algorithms:</p>
<ul>
<li><strong>SMA</strong>, the simple moving average, the sum of the last <strong>n</strong> prices divided by <strong>n</strong>.</li>
<li><strong>EMA</strong>, exponential moving average, the current price multiplied with a small factor plus the last EMA multiplied with a large factor. The sum of both factors must be <strong>1</strong>. This is a first order lowpass filter.</li>
<li><strong>LowPass</strong>, a second order lowpass filter with the following source code:
<pre>var LowPass(var *Data,int Period)
{
  var* LP = series(Data[0]);
  var a = 2.0/(1+Period);
  return LP[0] = (a-0.25*a*a)*Data[0]
    + 0.5*a*a*Data[1]
    - (a-0.75*a*a)*Data[2]
    + 2*(1.-a)*LP[1]
    - (1.-a)*(1.-a)*LP[2];
}</pre>
</li>
<li><strong>HMA</strong>, the Hull Moving Average, with the following source code:
<pre>var HMA(var *Data,int Period)
{
  return WMA(series(2*WMA(Data,Period/2)-WMA(Data,Period),sqrt(Period))
}</pre>
</li>
<li><strong>ZMA</strong>, Ehler&#8217;s Zero-Lag Moving Average, an EMA with a correction term for removing lag. This is the source code:
<pre>var ZMA(var *Data,int Period)
{
  var *ZMA = series(Data[0]);
  var a = 2.0/(1+Period);
  var Ema = EMA(Data,Period);
  var Error = 1000000;
  var Gain, GainLimit=5, BestGain=0;
  for(Gain = -GainLimit; Gain &lt; GainLimit; Gain += 0.1) {
     ZMA[0] = a*(Ema + Gain*(Data[0]-ZMA[1])) + (1-a)*ZMA[1];
     var NewError = Data[0] - ZMA[0];
     if(abs(Error) &lt; newError) {
       Error = abs(newError);
       BestGain = Gain;
     }
  }
  return ZMA[0] = a*(Ema + BestGain*(Data[0]-ZMA[1])) + (1-a)*ZMA[1];
}</pre>
</li>
<li><strong>ALMA</strong>, Arnaud Legoux Moving Average, based on a shifted Gaussian distribution (described in <a href="http://www.forexfactory.com/attachment.php?attachmentid=1123528&amp;d=1359078631" target="_blank" rel="noopener noreferrer">this paper</a>):
<pre>var ALMA(var *Data, int Period)
{
  var m = floor(0.85*(Period-1));
  var s = Period/6.0;
  var alma = 0., wSum = 0.;
  int i;
  for (i = 0; i &lt; Period; i++) {
    var w = exp(-(i-m)*(i-m)/(2*s*s));
    alma += Data[Period-1-i] * w;
    wSum += w;
  }
  return alma / wSum;
}</pre>
</li>
<li><strong>Laguerre</strong>, a 4-element Laguerre filter:
<pre>var Laguerre(var *Data, var alpha)
{
  var *L = series(Data[0]);
  L[0] = alpha*Data[0] + (1-alpha)*L[1];
  L[2] = -(1-alpha)*L[0] + L[1] + (1-alpha)*L[2+1];
  L[4] = -(1-alpha)*L[2] + L[2+1] + (1-alpha)*L[4+1];
  L[6] = -(1-alpha)*L[4] + L[4+1] + (1-alpha)*L[6+1];
  return (L[0]+2*L[2]+2*L[4]+L[6])/6;
}</pre>
</li>
<li><strong>Linear regression</strong>, fits a straight line between the data points in a way that the distance between each data point and the line is minimized by the least-squares rule.</li>
<li><strong>Smooth</strong>, John Ehlers&#8217; &#8220;Super Smoother&#8221;, a 2-pole Butterworth filter combined with a 2-bar SMA that suppresses the Nyquist frequency:
<pre>var Smooth(var *Data,int Period)
{
  var f = (1.414*PI) / Period;
  var a = exp(-f);
  var c2 = 2*a*cos(f);
  var c3 = -a*a;
  var c1 = 1 - c2 - c3;
  var *S = series(Data[0]);
  return S[0] = c1*(Data[0]+Data[1])*0.5 + c2*S[1] + c3*S[2];
}</pre>
</li>
<li><strong>Decycle</strong>, another low-lag indicator by John Ehlers. His decycler is simply the difference between the price and its fluctuation, retrieved with a highpass filter:
<pre>var Decycle(var* Data,int Period)
{
  return Data[0]-HighPass2(Data,Period);
}</pre>
</li>
</ul>
<p>The above source codes have been taken from the <strong>indicators.c</strong> file of the Zorro platform, which contains source codes of all supplied indicators.</p>
<h3>Comparing Step Responses</h3>
<p>What is the best of all those indicators? For a first impression here&#8217;s a chart showing them reacting on a simulated sudden price step. You can see that some react slow, some very slow, some fast, and some overshoot: <a href="http://www.financial-hacker.com/wp-content/uploads/2015/09/LowLag_EURUSD.png"><img decoding="async" class="alignnone wp-image-139 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2015/09/LowLag_EURUSD.png" alt="" width="795" height="351" srcset="https://financial-hacker.com/wp-content/uploads/2015/09/LowLag_EURUSD.png 795w, https://financial-hacker.com/wp-content/uploads/2015/09/LowLag_EURUSD-300x132.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a> You can generate such a step response diagram with this Zorro script:</p>
<pre>// compare the step responses of some low-lag MAs
function run()
{
  set(PLOTNOW);
  BarPeriod = 60;
  MaxBars = 1000;
  LookBack = 150;
  asset("");   // don't load an asset
  ColorUp = ColorDn = 0;  // don't plot a price curve
  PlotWidth = 800;
  PlotHeight1 = 400;

  var *Impulse = series(ifelse(Bar&gt;200 &amp;&amp; Bar&lt;400,1,0)); // 0-&gt;1 impulse
  int Period = 50;
  plot("Impulse",Impulse[0],0,GREY);
  plot("SMA",SMA(Impulse,Period),0,BLACK);
  plot("EMA",EMA(Impulse,Period),0,0x808000);
  plot("ALMA",ALMA(Impulse,Period),0,0x008000);
  plot("Laguerre",Laguerre(Impulse,4.0/Period),0,0x800000);
  plot("Hull MA",HMA(Impulse,Period),0,0x00FF00);
  plot("Zero-Lag MA",ZMA(Impulse,Period),0,0x00FFFF); 
  plot("Decycle",Decycle(Impulse,Period),0,0xFF00FF);
  plot("LowPass",LowPass(Impulse,Period),0,0xFF0000);
  plot("Smooth",Smooth(Impulse,Period),0,0x0000FF);
}</pre>
<p>We can see that from all the indicators, the <strong>ALMA</strong> seems to be the best representation of the step, while the <strong>ZMA</strong> produces the fastest response with no overshoot, the <strong>Decycler</strong> the fastest with some overshoot, and <strong>Laguerre</strong> lags a lot behind anything else. Obviously, all this has not much meaning because the time period parameters of the indicators are not really comparable. So the step response per se does not reveal if the indicator is well suited for trend detection. We have no choice: We must use them all.</p>
<h3>The Trend Experiment</h3>
<p>For the experiment, all smoothing indicators above will be applied to a currency, a stock index, and a commodity, and will compete in exploiting trend. Because different time frames can represent different trader groups and thus different markets, the indicators will be applied to price curves made of 15-minutes, 1-hour, and 4-hours bars. And we&#8217;ll also try different indicator time periods in 10 steps from 10 to 10000 bars.</p>
<p>So we&#8217;ll have to program 10 indicators * 3 assets * 3 bar sizes * 10 time periods = 900 systems. Some of the 900 results will be positive, some negative, and some zero. If there are no significant positive results, we&#8217;ll have to conclude that trend in price curves either does not exist, or can at least not be exploited with this all-too-obvious method. However we&#8217;ll likely get some winning systems, if only for statistical reasons.</p>
<p>The next step will be checking if their profits are for real or just caused by a statistical effect dubbed <strong>Data Mining Bias</strong>. There is a method to measure Data Mining Bias from the resulting equity curves: the notorious <strong>White&#8217;s Reality Check</strong>. We&#8217;ll apply that check to the results of our experiment. If some systems survive White&#8217;s Reality Check, we&#8217;ll have the once-and-for-all proof that markets are ineffective, trends really exist, and algorithmic trend trading works.</p>
<p><a href="http://www.financial-hacker.com/trend-and-exploiting-it/">Next Step</a>&#8230;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/trend-delusion-or-reality/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
	</channel>
</rss>
