<?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>Correlation &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/correlation/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Sun, 19 Apr 2020 11:10:54 +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>Correlation &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Petra on Programming: A Unique Trend Indicator</title>
		<link>https://financial-hacker.com/petra-on-programming-a-unique-trend-indicator/</link>
					<comments>https://financial-hacker.com/petra-on-programming-a-unique-trend-indicator/#comments</comments>
		
		<dc:creator><![CDATA[Petra Volkova]]></dc:creator>
		<pubDate>Fri, 17 Apr 2020 16:21:38 +0000</pubDate>
				<category><![CDATA[Indicators]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Correlation]]></category>
		<category><![CDATA[CTI]]></category>
		<category><![CDATA[Ehlers]]></category>
		<guid isPermaLink="false">https://financial-hacker.com/?p=3424</guid>

					<description><![CDATA[This months project is a new indicator by John Ehlers, first published in the S&#38;C May 2020 issue. Ehlers had a unique idea for early detecting trend in a price curve. No smoothing, no moving average, but something entirely different. Lets see if this new indicator can rule them all. The basic idea of the &#8230; <a href="https://financial-hacker.com/petra-on-programming-a-unique-trend-indicator/" class="more-link">Continue reading<span class="screen-reader-text"> "Petra on Programming: A Unique Trend Indicator"</span></a>]]></description>
										<content:encoded><![CDATA[
<p><em>This months project is a new indicator by <strong>John Ehlers</strong>, first published in the S&amp;C May 2020 issue. Ehlers had a unique idea for early detecting trend in a price curve. No smoothing, no moving average, but something entirely different. Lets see if this new indicator can rule them all.</em></p>
<p><span id="more-3424"></span></p>
<p>The basic idea of the <strong>Correlation Trend Indicator</strong> (CTI) is quite simple. The ideal trend curve is a straight upwards line. So the CTI just measures the correlation of the price curve with this ideal trend line. Ehlers provided TradeStation code that can be directly converted to Zorro&#8217;s C language. This is the indicator:</p>
<pre class="prettyprint">var CTI (vars Data, int Length)<br />{<br />  int count;<br />  var Sx = 0, Sy = 0, Sxx = 0, Sxy = 0, Syy = 0;<br />  for(count = 0; count &lt; Length; count++) {<br />    var X = Data[count]; // the price curve<br />    var Y = -count; // the trend line<br />    Sx = Sx + X; Sy = Sy + Y;<br />    Sxx = Sxx + X*X; Sxy = Sxy + X*Y; Syy = Syy + Y*Y;<br />  }<br />  if(Length*Sxx-Sx*Sx &gt; 0 &amp;&amp; Length*Syy-Sy*Sy &gt; 0)<br />    return (Length*Sxy-Sx*Sy)/sqrt((Length*Sxx-Sx*Sx)*(Length*Syy-Sy*Sy));<br />  else return 0;<br />}</pre>
<p>X represents the price curve, Y the trend line, and correlation is measured with the Spearman algorithm. The trend line is supposed to linearly rise with <strong>count</strong>, but I&#8217;m using the negative <strong>count</strong> here because the <strong>Data</strong> series is stored backwards, with the most recent values at the begin.</p>
<p>This is how the CTI looks when applied to SPY (red = 10 days period, blue = 40 days):</p>
<p><a href="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_SPY.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-3429" src="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_SPY.png" alt="" width="701" height="365" srcset="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_SPY.png 701w, https://financial-hacker.com/wp-content/uploads/2020/04/CTI_SPY-300x156.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a></p>
<p>We can see that the lines reproduce rather well the price curve trend. And we can also see that the blue line, the 40-days trend, is not just a smoothed version of the red 10-days trend &#8211; it looks entirely different. This is an interesting feature of a trend indicator &#8211; it separates long-term and short-term trend perfectly. But does the indicator have predictive power?</p>
<p>For finding out, we could use it for a simple trading system. But a bit more informative is examining a <strong>price difference profile</strong> of its zero crossovers. A price difference profile displays the average price movement and its standard deviation for the bars following a certain event or condition. It is used for testing the quality of trade signals.</p>
<p>The code for plotting a price difference profile from the CTI(20) zero crossings:</p>
<pre class="prettyprint">void run() 
{
   BarPeriod = 1440;
   LookBack = 40;
   StartDate = 2010;

   assetAdd("SPY","STOOQ:SPY.US"); // load SPY history from Stooq
   asset("SPY");

   vars Prices = series(priceClose());
   vars Signals = series(CTI(Prices,20));
   if(crossOver(Signals,0))
      plotPriceProfile(40,0); // plot positive price difference
   else if(crossUnder(Signals,0))
      plotPriceProfile(40,2); // plot negative price difference
}
</pre>
<p>The resulting profile:</p>
<p><a href="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_profile.png"><img decoding="async" class="alignnone size-full wp-image-3430" src="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_profile.png" alt="" width="701" height="362" srcset="https://financial-hacker.com/wp-content/uploads/2020/04/CTI_profile.png 701w, https://financial-hacker.com/wp-content/uploads/2020/04/CTI_profile-300x155.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a></p>
<p>The red bars are the average differences (in cents) to the price at the zero crossings. The X axis shows the days after the crossing.</p>
<p>We can see that the average price differences tend to drop to a negative minimum immediately after a crossing, thus indicating a short term mean reversion effect. Then the differences rise to a trend maximum after about 14 days. The effect is trend neutral by including negative differences at reverse crossings. The optimal trading system for this profile would be entering a long or short position 4 days after the CTI crossing, then holding the position for 10 days. </p>
<p>But we can also see that the standard deviation of the price differences – the grey bars, reduced by factor 4 for better scaling – is about ten times higher than the price difference extrema. So the effect is small, and trading on CTI crossovers would be difficult. A somewhat predictive power of the CTI(SPY,20) exists &#8211; but it is too weak for being directly exploited in a crossover trading system.</p>
<h3>Reference</h3>
<p>John Ehlers, Correlation Trend Indicator, Stocks&amp;Commodities 5/2020</p>
<p>The indicator and price profile test scripts are available in the Scripts 2020 repository.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/petra-on-programming-a-unique-trend-indicator/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
