<?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>Au.Tra.Sy blog - Automated trading System &#187; afl</title>
	<atom:link href="http://www.automated-trading-system.com/tag/afl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.automated-trading-system.com</link>
	<description>Systematic Trading research and development, with a flavour of Trend Following</description>
	<lastBuildDate>Mon, 23 Jan 2012 11:58:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Amibroker vs TradersStudio: comparison</title>
		<link>http://www.automated-trading-system.com/amibroker-v-tradersstudio-comparison/</link>
		<comments>http://www.automated-trading-system.com/amibroker-v-tradersstudio-comparison/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 10:18:38 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=981</guid>
		<description><![CDATA[A couple of weeks ago I downloaded Amibroker to see if it could compute the e-ratio much faster than TradersStudio (it did!). The result of the speed comparison is there and the Amibroker code for the e-ratio is there. I thought it might be interesting to do a comparison of how easy it is to [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I downloaded Amibroker to see if it could <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">compute the e-ratio</a> much faster than TradersStudio (it did!). The result of the speed comparison is <a href="http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/">there</a> and the Amibroker code for the e-ratio is <a href="http://www.automated-trading-system.com/e-ratio-amibroker-code/">there</a>.<br />
I thought it might be interesting to do a comparison of how easy it is to get on with both platforms as a new user.</p>
<h3>Software and manuals</h3>
<p>You can download a fully-functioning Amibroker demo (you cannot with TraderStudio and even when you buy it you have to wait for CDs by post!) which contains some limitations (i.e no more than 5 markets back-tested at a time, etc.).<br />
The manuals are all online and very thorough, complemented with additional articles, presentations and other materials. This makes it very handy (again compared to TradersStudio printed 300 page manual &#8211; yet incomplete) as you can search them electronically to look for exactly what you need.<span id="more-981"></span></p>
<h3>Large Community</h3>
<p>The Amibroker community seems much wider and as a result there is <em>loads</em> of available scripts for re-use. There is actually a whole <a href="http://www.amibroker.com/library/list.php" target="_blank" rel="nofollow">library</a> hosted on amibroker website.<br />
There is also much, much more information available on the internet. As a sample test I googled &#8220;Amibroker Donchian&#8221; vs. &#8220;TradersStudio Donchian&#8221;: 23,200 results vs. 17 (including this blog!).<br />
Finally the <a href="http://finance.groups.yahoo.com/group/amibroker/" target="_blank" rel="nofollow">yahoo group</a> is much more active. There are about 10 times more daily messages (although the TradersStudio one can go days without getting a single message). As an example I posted a question related to the custom backtester and got a useful answer the next day.</p>
<h3>The platform</h3>
<p>It takes a bit of time to get used to the concept and principles of Amibroker. It is quite different from TradersStudio. For example, all afl files are self-contained and might implement indicator, system, back-test procedure, scan and exploration code all at once (although only one part really runs at once &#8211; alightly confusing at first). In TradersStudio you can also define functions to be called in other code files; this does not appear possible in Amibroker (you would have to copy/paste the code over and over again). Both platforms allow you to build COM dlls to code up your functions.</p>
<p>The GUI is different but I would not say better or worse than TradersStudio.The charting forms a more central part of the Amibroker platform and just firing up a chart with several indicators is pretty quick. At first glance the money management/portfolio allocation does not appear very rich in Amibroker (in terms of functionality) but I would have to do more testing to confirm this.<br />
<div id="attachment_987" class="wp-caption alignnone" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker.jpg" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker-300x246.jpg" alt="AmiBroker screenshot" title="amibroker screenshot" width="300" height="246" class="size-medium wp-image-987" /></a><p class="wp-caption-text">AmiBroker screenshot</p></div></p>
<p>The language to create your own indicators, systems, etc. (AFL: Amibroker Formula Language) is based on C and not very hard to pick up especially with the very useful in-line help &#8211; it does help to read the tutorials first (!) to get a grasp of the main keywords/built-in functions.</p>
<h3>Data loading</h3>
<p>Loading the <a href="http://www.automated-trading-system.com/unfair-advantage-api-code-c-extract-futures-continuous-data/">data extracted from CSI Unfair Advantage</a> was fairly straight-forward and there seems to be a bunch of ready-made interfaces with other data vendors in addition to the Amiquote utility &#8211; which allows you import quotes in Amibroker. It seems that there is more flexibility in the type of data fields that can be loaded.</p>
<h3>Conclusion</h3>
<p>Overall I was pretty pleased at what I was able to achieve in a short amount of time. For some reason I found it very hard to <em>get into</em> TradersStudio whereas Amibroker was easier to tackle (once you understand its working concept).<br />
Obviously I have not explored all the functionalities of either software and this is definitely not an exhaustive review. As a result of all this I will be buying a copy of Amibroker to complement (or replace?) TradersStudio. I am sure both platforms each have their pros and cons so having both is probably a good idea (and not a very costly one since Amibroker costs only $200!).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/amibroker-v-tradersstudio-comparison/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Amibroker V. TradersStudio: Speed comparison Fight</title>
		<link>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/</link>
		<comments>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 14:41:15 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=930</guid>
		<description><![CDATA[It might not capture the imagination as much as the recent Haye v. Valuev WBA World Heavyweight Championship fight (it probably might for some of you&#8230; ;-) but I decided to organise my own &#8220;fight&#8221;: AmiBroker V. TradersStudio! And similarly to the boxing, speed was of the essence &#8211; with one platform completely out-performing the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/11/valuevhayeposter.jpg" alt="valuevhayeposter" title="valuevhayeposter" width="235" height="287" class="alignleft size-full wp-image-932" style="margin-right:12px; margin-bottom:26px;"/><br />
It might not capture the imagination as much as the recent Haye v. Valuev WBA World Heavyweight Championship fight (it probably might for some of you&#8230; ;-) but I decided to organise my own &#8220;fight&#8221;: AmiBroker V. TradersStudio!<br />
And similarly to the boxing, speed was of the essence &#8211; with one platform completely out-performing the other one. Let&#8217;s find out which one&#8230;<span id="more-930"></span></p>
<p>In the last few posts I have been exploring the <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">e-ratio</a> and wrote the <a href="http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/">code in TradersStudio</a>. I also tried to implement it in <a href="http://www.automated-trading-system.com/e-ratio-amibroker-code/">AmiBroker AFL language</a> mostly to check how it performed speed-wise &#8211; as I found TradersStudio quite slow.</p>
<p>While testing AmiBorker, it actually felt so fast that I decided to perform a more formal speed comparison test.</p>
<h3>Conditions of the test</h3>
<p>I exported the <a href="http://www.automated-trading-system.com/unfair-advantage-api-code-c-extract-futures-continuous-data/">CSI data via the API</a> for a proportionally back-adjusted Corn contract going back to 1949. The data was imported in both AmiBroker and TradersStudio via their ASCII Import.</p>
<p>The system tested is a simple 20-day Donchian Channel Breakout (Buy-only) and the ATR used to normalise the MAE/MFE is 20-day also.<br />
The optimiser in both systems were used to generate the e-ratio for <del datetime="2009-11-10T14:34:18+00:00">50 </del>51 different trade durations (from 10 to 50 days).</p>
<p>One of the condition to validate the results of the test was that the trades generated by both systems are similar (to double-check I did not make a coding mistake resulting in simpler/faster process for one of the platforms).</p>
<p>The computer I was running the test on is a quad-core CPU (2.4 GHz) with 3.25 GB of addressable RAM. Only one platform was running at the time it was tested.</p>
<h3>Results are in!</h3>
<p>And they look astoninglishly good for AmiBroker:</p>
<ul>
<li>The <strong>TradersStudio</strong> test was run first and took <strong>4 mins 15 sec</strong> to complete and produce the custom report (which needs to be manipulated in Excel to calculate the e-ratio). Furthermore, it appeared that every incremental run in the optimisation process took slightly longer than the previous one.</li>
<li>The <strong>AmiBroker</strong> test ran in (&#8230;drumrolls&#8230;) <strong>10 sec!</strong> And the e-ratio was readily available from the results grid:<br />
<div id="attachment_956" class="wp-caption alignnone" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker-optimisation-results.jpg" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker-optimisation-results-300x191.jpg" alt="AmiBroker optimisation results showing the e-ratio. Click to expand" title="amibroker-optimisation-results" width="300" height="191" class="size-medium wp-image-956" /></a><p class="wp-caption-text">AmiBroker optimisation results showing the e-ratio. Click to expand</p></div></li>
</ul>
<p>Both apps maxed out their allocated CPU (i.e. overall CPU usage of 25% = a quarter of the quad-core CPU available).</p>
<p>I then decided to run the AmiBroker code over <strong>5 markets</strong> to get a feel of how long it would take. I added Crude Oil (going back to 1985), Cotton (1968), Gold (1975) and Yen (1972).<br />
AmiBroker ran the same code + optimisation in <strong>2 mins 20 sec</strong>, twice as fast as one market in TradersStudio!</p>
<p>Applying a simple proportional calculation to derive the time it would take in TradersStudio for the same dataset would give us a completion time of 1 hour (59 min 30 sec exactly&#8230;). Since the performance seems to degrade over the course of the optimisation in TradersStudio (i.e. the first back-test is quicker than the last one of the optimisation run) we could assume that it would actually take longer, which is what I experienced when I was testing on similar data in the last few weeks.</p>
<p>So here you have it: <strong>AmiBroker is 25 times faster than TradersStudio</strong> and it gives you the results in a much more friendly format.</p>
<h3>Trade Reconciliation</h3>
<p>As mentioned earlier, to ensure that the test was valid, the set of trades generated by both systems should be compared. I ran one back-test of the system over the Corn data for a single optimisation step (e-ratio for 20 days duration) in both systems.</p>
<p>I could find that 296 trades out of 340 presented a very good match (some matches had one day difference on the Entry date and rounding differences on the prices). But overall the trade comparison was good enough to give assurance that the same systems and results were being tested.</p>
<p>I&#8217;ll keep investigating for myself where these errors are coming from (and post a  further code update if warranted) but we can assume that the differences are trivial with regards to performance comparison.</p>
<p>Did I mention that AmiBroker is 3 times as cheap with a much wider following (many more code samples, better docs, more forums, etc.)?&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Amibroker e-ratio code</title>
		<link>http://www.automated-trading-system.com/e-ratio-amibroker-code/</link>
		<comments>http://www.automated-trading-system.com/e-ratio-amibroker-code/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 12:30:53 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=901</guid>
		<description><![CDATA[I recently posted about the e-ratio as a tool to measure parts of a trading system (the code files to compute the e-ratio in TradersStudio and Excel are also available). The e-ratio is supposed to be a quick tool to check how signals might add some edge to a trading system. However computing the e-ratio [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted about the <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">e-ratio</a> as a tool to measure parts of a trading system (the <a href="http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/">code files to compute the e-ratio in TradersStudio and Excel</a> are also available). The e-ratio is supposed to be a quick tool to check how signals might add some edge to a trading system. However computing the e-ratio in TradersStudio is slow (4+ hours for one signal over 100 different durations).</p>
<p>So I decided to give the &#8220;legendary fast&#8221; Amibroker a test to see if it could better TradersStudio&#8217;s performance. After some &#8220;playing and learning&#8221;, I have finalised the code to compute the e-ratio. My big thanks go to the <a href="http://theasxgorilla.blogspot.com/2007/07/how-to-compute-edge-ratio-in-amibroker.html" target="_blank" rel="nofollow">ASX gorilla</a> whose own version forms a large part of my code.<span id="more-901"></span></p>
<p>Below is the code explanation and downloadable <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/e-ratio-gorilla.afl" target="_blank">afl file</a>.</p>
<p>Directly from the ASX Gorilla&#8217;s website as a prelude to the code:</p>
<blockquote><p>My implementation of the Edge Ratio involves two profound Amibroker fudges. The first is the use of the AddToComposite function to create a composite ticker symbol in which to hold the ATR array of a given stock for later retrieval within the Custom Back Tester via the Foreign function.</p></blockquote>
<blockquote><p>The second fudge is the use of the VarSet/VarGet function to create a quasi array. This was necessary to overcome the limitation where array elements cannot exceed in number the value of barcount-1.</p></blockquote>
<p>The first part is to actually code up your Buy signal (in our case a Donchian Channel Breakout). The Sell signals are tested separately:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//BUY RULES: implemented with Buy Stop on Upper Donchian Channel(17)</span>
BuyStop <span style="color: #002200;">=</span> Ref<span style="color: #002200;">&#40;</span>HHV<span style="color: #002200;">&#40;</span>High, <span style="color: #2400d9;">17</span><span style="color: #002200;">&#41;</span>,<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;
Buy <span style="color: #002200;">=</span> Cross<span style="color: #002200;">&#40;</span> High, BuyStop <span style="color: #002200;">&#41;</span>;
BuyPrice <span style="color: #002200;">=</span> Max<span style="color: #002200;">&#40;</span> BuyStop, Low <span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// make sure buy price &gt;= Low</span></pre></div></div>

<p>Exiting positions is done on a fixed duration basis:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Never Sell so that the position is stopped out after N bar instead</span>
Sell <span style="color: #002200;">=</span> <span style="color: #2400d9;">3</span> &gt; <span style="color: #2400d9;">5</span>;
<span style="color: #11740a; font-style: italic;">//Stop the positon and close it after N bars</span>
<span style="color: #11740a; font-style: italic;">//(eratio = N that we step from 1 to 100 in optimisation)</span>
ApplyStop<span style="color: #002200;">&#40;</span> stopTypeNBar, stopModeBars, eratio <span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The first fudge mentioned above to store the ATR:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">Normaliser <span style="color: #002200;">=</span> ATR<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">17</span><span style="color: #002200;">&#41;</span>;
AddToComposite<span style="color: #002200;">&#40;</span>Normaliser, <span style="color: #bf1d1a;">&quot;~atr_&quot;</span><span style="color: #002200;">+</span>Name<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>, <span style="color: #bf1d1a;">&quot;C&quot;</span>, <span style="color: #2400d9;">1</span><span style="color: #002200;">+</span><span style="color: #2400d9;">2</span><span style="color: #002200;">+</span><span style="color: #2400d9;">8</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>And the &#8220;meat&#8221; of the code: the chunk that implements the custom back-testing to:</p>
<ol>
<li>Loop through the signals and store the Entry ATR value.</li>
<li>Loop through all trades and retrieve MFE, MAE and ATR.</li>
<li>Compute the e-ratio based on values from all trades.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SetCustomBacktestProc<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;&quot;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//activate the custom backtester</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>Status<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;action&quot;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> actionPortfolio<span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//called when backtesting/optimising</span>
<span style="color: #002200;">&#123;</span>
	bo <span style="color: #002200;">=</span> GetBacktesterObject<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
	bo.PreProcess<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// run default backtest procedure</span>
	TradeATR <span style="color: #002200;">=</span> NumTrades <span style="color: #002200;">=</span> ATRArr <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; <span style="color: #11740a; font-style: italic;">//init variables</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> bar<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; bar &lt; BarCount<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>; bar<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		bo.ProcessTradeSignals<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span> sig<span style="color: #002200;">=</span>bo.GetFirstSignal<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span>; sig; sig<span style="color: #002200;">=</span>bo.GetNextSignal<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sig.isEntry<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#123;</span>
				NumTrades<span style="color: #002200;">++</span>;
				ATRArr <span style="color: #002200;">=</span> Foreign<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;~atr_&quot;</span><span style="color: #002200;">+</span>sig.Symbol, <span style="color: #bf1d1a;">&quot;C&quot;</span><span style="color: #002200;">&#41;</span>;
				VarSet<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades, ATRArr<span style="color: #002200;">&#91;</span>bar<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
				_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Symbol &quot;</span> <span style="color: #002200;">+</span> sig.Symbol <span style="color: #002200;">+</span> <span style="color: #bf1d1a;">&quot; ATR: &quot;</span> <span style="color: #002200;">+</span> VarGet<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
&nbsp;
	AvgMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">=</span> AvgMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">=</span> NumTrades <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// iterate through closed trades</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> trade <span style="color: #002200;">=</span> bo.GetFirstTrade<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; trade; trade <span style="color: #002200;">=</span> bo.GetNextTrade<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		NumTrades<span style="color: #002200;">++</span>;
		EntryATR <span style="color: #002200;">=</span> VarGet <span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades<span style="color: #002200;">&#41;</span>;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> EntryATR <span style="color: #002200;">!=</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;EntryATR: &quot;</span> <span style="color: #002200;">+</span> WriteVal<span style="color: #002200;">&#40;</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;AccumMAE : &quot;</span> <span style="color: #002200;">+</span> WriteVal<span style="color: #002200;">&#40;</span>AccumMAE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			AccumMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>trade.GetMAE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">100</span><span style="color: #002200;">*</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			AccumMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>trade.GetMFE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">100</span><span style="color: #002200;">*</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;My MAE&quot;</span>, trade.GetMAE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span>;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;My MFE&quot;</span>, trade.GetMFE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span>;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Entry ATR&quot;</span>, EntryATR<span style="color: #002200;">*</span><span style="color: #2400d9;">10000</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	AvgMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">/</span> NumTrades;
	AvgMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">/</span> NumTrades;
&nbsp;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>AccumMAE <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>NumTrades<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>AvgMAE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	Eratio <span style="color: #002200;">=</span> <span style="color: #a61390;">abs</span><span style="color: #002200;">&#40;</span>AvgMFE<span style="color: #002200;">/</span>AvgMAE<span style="color: #002200;">&#41;</span>;
&nbsp;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>Eratio<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Avg MAE&quot;</span>, AvgMAE <span style="color: #002200;">&#41;</span>;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Avg MFE&quot;</span>, AvgMFE <span style="color: #002200;">&#41;</span>;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Eratio&quot;</span>, Eratio<span style="color: #002200;">&#41;</span>;
&nbsp;
	bo.PostProcess<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>If you want to run this code, you can download the <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/e-ratio-gorilla.afl" target="_blank">e-ratio &#8220;gorilla&#8221; afl file</a> and simply update the BUY signals to whatever you fancy testing.</p>
<p>The next post will be a direct speed comparison between TradersStudio and Amibroker for computing the e-ratio on the same underlying data and with the same signal. I expect Amibroker to <em>win the fight</em> hands-down as it appeared &#8220;way&#8221; faster!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/e-ratio-amibroker-code/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

