<?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>Trainee Trader &#187; Programming</title>
	<atom:link href="http://www.traineetrader.com/category/software/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.traineetrader.com</link>
	<description>Trainee Trader provides articles and tutorials related to Forex, Derivatives, Equities and Futures markets.</description>
	<lastBuildDate>Thu, 22 Dec 2011 05:16:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Simulated Random Walk in MATLAB</title>
		<link>http://www.traineetrader.com/simulated-random-walk-in-matlab/</link>
		<comments>http://www.traineetrader.com/simulated-random-walk-in-matlab/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 09:11:38 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quantitative Trading]]></category>
		<category><![CDATA[Share Market]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[m file]]></category>
		<category><![CDATA[Random Walk]]></category>
		<category><![CDATA[Simulation]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=1580</guid>
		<description><![CDATA[<p><img width="390" height="249" src="http://www.traineetrader.com/wp-content/uploads/2011/09/simRandomWalk.jpg" class="attachment-featured-image wp-post-image" alt="simRandomWalk" title="simRandomWalk" /></p><br />Put in simple terms, a Random Walk basically involves taking successive random steps and tracing the trajectory. I adapted the example from part one of Wilmott on Quantitative Finance and wrote a quick MATLAB script to simulate a simple random walk. Basically flip a coin if it is heads multiply the equity seed by 1.01 [...]]]></description>
			<content:encoded><![CDATA[<p><img width="390" height="249" src="http://www.traineetrader.com/wp-content/uploads/2011/09/simRandomWalk.jpg" class="attachment-featured-image wp-post-image" alt="simRandomWalk" title="simRandomWalk" /></p><br /><p>Put in simple terms, a Random Walk basically involves taking successive random steps and tracing the trajectory. I adapted the example from part one of Wilmott on Quantitative Finance and wrote a quick MATLAB script to simulate a simple random walk. Basically flip a coin if it is heads multiply the equity seed by 1.01 and if its tails multiply by 0.99.</p>
<h3><span id="more-1580"></span>Results</h3>
<p>The graphs below show succesive runs of the script. I simulated 10,000 coin tosses in each test.</p>
<p><strong>Sim one</strong>: You flipped 5069 heads &amp; 4931 tails</p>
<p style="text-align: center;"><img class="aligncenter size-large wp-image-1585" title="Random Walk One" src="http://www.traineetrader.com/wp-content/uploads/2011/09/sim1-1024x555.png" alt="Random Walk One" width="620" height="336" /></p>
<p><strong>Sim Two</strong>: You flipped 4946 heads &amp; 5054 tails</p>
<p style="text-align: left;"><img class="aligncenter size-large wp-image-1587" title="Random Walk 2 MATLAB" src="http://www.traineetrader.com/wp-content/uploads/2011/09/sim2-1024x555.png" alt="Random Walk 2 MATLAB" width="620" height="336" /><strong>Sim Three</strong>: You flipped 5026 heads &amp; 4974 tails</p>
<p style="text-align: left;"><img class="aligncenter size-large wp-image-1588" title="Random Walk 3 MATLAB" src="http://www.traineetrader.com/wp-content/uploads/2011/09/sim3-1024x555.png" alt="Random Walk 3 MATLAB" width="620" height="336" /><strong>Sim Four</strong>: You flipped 5042 heads &amp; 4958 tails</p>
<h3 style="text-align: left;"><img class="aligncenter size-large wp-image-1589" title="Random Walk 4 MATLAB" src="http://www.traineetrader.com/wp-content/uploads/2011/09/sim4-1024x555.png" alt="Random Walk 4 MATLAB" width="620" height="336" />MATLAB Code</h3>
<p style="text-align: left;">Writing the code in MATLAB is very straightforward I wrote the code in less then five minutes so it is a bit rough around the edges. I probably could refactor it but it does the job.</p>
<pre class="brush: matlab">
% Simple Simulated Random Walk Adapted
% from part 1 Paul Wilmott on Quant Fin

% create matrix with random int either 1 or 2
randMat = randi(2,10000,1);
randEquity = [1:10000];

headCount = 0;
tailCount = 0;
equitySeed = 100.00;

for i=1:10000
    if randMat(i)==1
        % we flipped a heads
        headCount = headCount + 1;
        equitySeed = 1.01 * equitySeed;
        randEquity(i) = equitySeed;
    else
        % must have flipped tails
        tailCount = tailCount + 1;
        equitySeed = 0.99 * equitySeed;
        randEquity(i) = equitySeed;
    end
end

fprintf('You flipped %i heads &#038; %i tails\n', headCount, tailCount);
plot(randEquity);
title('\bf \fontname{Arial} \fontsize{16}Simulated Random Walk');
xlabel('\bf \fontname{Arial} \fontsize{12}Number of Coin Tosses');
ylabel('\bf \fontname{Arial} \fontsize{12}Price in ($)');

% clean-up
clear equitySeed headCount tailCount randMat i;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/simulated-random-walk-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rapid Prototyping Trading Strategies in MATLAB</title>
		<link>http://www.traineetrader.com/rapid-prototyping-trading-strategies-in-matlab/</link>
		<comments>http://www.traineetrader.com/rapid-prototyping-trading-strategies-in-matlab/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 05:04:06 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[How to Build Your Own Algorithmic Trading Business]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quantitative Trading]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[m file]]></category>
		<category><![CDATA[prototyping]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=1563</guid>
		<description><![CDATA[<p><img width="110" height="164" src="http://www.traineetrader.com/wp-content/uploads/2010/03/image7.png" class="attachment-featured-image wp-post-image" alt="image.png" title="image.png" /></p><br />I have finally settled on a prototyping environment for my trading strategies. I have tested many different options but I keep coming back to MATLAB. I have tried python with both iPython and sciLab. I used Octave for a bit and I even tried Excel. None of these solutions have even com close to MATLAB. [...]]]></description>
			<content:encoded><![CDATA[<p><img width="110" height="164" src="http://www.traineetrader.com/wp-content/uploads/2010/03/image7.png" class="attachment-featured-image wp-post-image" alt="image.png" title="image.png" /></p><br /><p>I have finally settled on a prototyping environment for my trading strategies. I have tested many different options but I keep coming back to MATLAB. I have tried python with both iPython and sciLab. I used Octave for a bit and I even tried Excel. None of these solutions have even com close to MATLAB. Given the widespread use in industry and the speed and flexibility I can test trading ideas MATLAB is clearly the superior option.</p>
<blockquote><p>&#8220;MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran.&#8221;</p></blockquote>
<p style="text-align: right;">-MathWorks.com</p>
<p style="text-align: left;"><span id="more-1563"></span>Back in 2010 I first read Ernest Chan&#8217;s Book <a href="http://www.traineetrader.com/book-review-quantitative-trading-how-to-build-your-own-algorithmic-trading-business-by-ernest-chan/" target="_blank">How to Build Your Own Algorithmic Trading Business</a>.  I found the book interesting however I didn&#8217;t implement any of the ideas from the book. I have got the book of the shelf and I am going to work through it.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-1567" title="Matlab 2011b Mac" src="http://www.traineetrader.com/wp-content/uploads/2011/09/Matlab2011bMac.jpg" alt="Matlab 2011b Mac" width="814" height="643" /></p>
<h3 style="text-align: left;">MATLAB on Mac &amp; Solarized Colour Scheme</h3>
<p style="text-align: left;">MTALAB 2011b is much more Mac friendly then previous versions. The menu items are now all at the top of the screen on the Mac menu bar. Below is a basic screenshot showing the setup I use. For all my programming work I use a solarized colour theme with Monaco as the font face. When you spend at least 8 hours a day looking at a computer screen I have found these colour schemes to be easier on the eyes.</p>
<h3 style="text-align: left;"><a href="http://ethanschoonover.com/solarized"><img class="aligncenter" title="Solarized Colour Scheme " src="http://ethanschoonover.com/solarized/img/solarized-vim.png" alt="Solarized Colour Scheme " width="549" height="555" /></a>Clean up MATLAB Environment</h3>
<p style="text-align: left;">I am always looking to save time so I wrote a quick cleanup script that removes all variables, clears history and clears the command window. It is trivial but I have posted it below as it might be helpful to someone.</p>
<pre class="brush: matlab">% simple script to clean up workspace

% remove vars
clear;

% clear command window
clc;

% remove command history
com.mathworks.mlservices.MLCommandHistoryServices.removeAll;</pre>
<h3>Implementation</h3>
<p>I will probably use C++ or a DSL for the actual implemntation of the strategies. I will post some screen casts as I think information is more easily digestible in that format. I am just waiting for my podcasting mic to arrive. I think it is on a slow boat from china.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/rapid-prototyping-trading-strategies-in-matlab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>eSignal 11 Creating your Own Watch List &amp; Ordering by Sector</title>
		<link>http://www.traineetrader.com/esignal-11-creating-your-own-watch-list-ordering-by-sector/</link>
		<comments>http://www.traineetrader.com/esignal-11-creating-your-own-watch-list-ordering-by-sector/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 02:02:20 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[ASX]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[eSignal]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quantitative Trading]]></category>
		<category><![CDATA[Share Market]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[eSignal 11]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[GCIS]]></category>
		<category><![CDATA[Watch List]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=1460</guid>
		<description><![CDATA[eSignal 11 is the newest cab of the rank from Interactive Data, it is a complete rewrite of the famous eSignal software. I will write a full review in an upcoming article. You can read my review of the older version of eSignal on demand, back in October 2009. As I work with a lot [...]]]></description>
			<content:encoded><![CDATA[<p>eSignal 11 is the newest cab of the rank from Interactive Data, it is a complete rewrite of the famous eSignal software. I will write a full review in an upcoming article. You can read my review of the older version of <a href="http://www.traineetrader.com/esignal-ondemand-trading-software-review-is-it-worth-the-money/" target="_blank">eSignal on demand</a>, back in October 2009. As I work with a lot of financial data I like to keep things organized and my workflow as simple as possible. With eSignal data acquisition, testing and analysis it couldn&#8217;t be more simple.</p>
<h4>Getting The Symbol List&#8217;s For ASX Listed Companies</h4>
<p>The first step in the process is to download the symbol lists from the<a href="http://www.asx.com.au/asx/research/listedCompanies.do" target="_blank"> ASX website</a>. The ASX listed companies list is updated daily at 12Am. The easiest way to get the data is to download the CSV file, then we can work with it in Excel. As you can see in the image below there are three columns of data: Company Name, ASX Code and GICS Industry Group.</p>
<p style="text-align: center;"><img class="size-full wp-image-1462 aligncenter" title="Excel-csv-data" src="http://www.traineetrader.com/wp-content/uploads/2011/02/Excel-csv-data.png" alt="" width="495" height="139" /></p>
<p style="text-align: left;">If you are unfamiliar with the GCIS or Global Industry Classification Standard you can read up on it <a href="http://en.wikipedia.org/wiki/Global_Industry_Classification_Standard" target="_blank">here</a>. Basically it is just the industry group assigned to a specific company by Standard and Poor&#8217;s.</p>
<h4>Converting and Sorting the Symbol List</h4>
<p style="text-align: left;">eSignal requires the symbol code and then an exchange code to be added on the end. So for example BHP in eSignal would have the code BHP-ASX. There is over 2000 companies that we wish to change the code for so we need to automate the process. In Excel this can be done with a simple formula and a fill. What we want to do is take the text string in column B of our spreed-sheet and add the text string &#8220;-ASX&#8221; to the end of the stock code. To do this we use the CONCATENATE function, this function takes n text strings and adds them together to form a new string.</p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-1465" title="Excel-data-concatenate" src="http://www.traineetrader.com/wp-content/uploads/2011/02/Excel-data-concatenate.png" alt="" width="494" height="57" />As you can see from the above image in cell D1 we simply type: =CONCATENATE(B4, &#8220;-ASX&#8221;) and we fill down for the entire range and we now have our eSignal symbols ready for export. In order to export our symbol list by GCIS sector we need to custom sort the data first. Simply go to Sort -&gt; Custom Sort and then sort by GCIS Industry Group as shown below.</p>
<h4><img class="aligncenter size-full wp-image-1466" title="custom-sort-symbols" src="http://www.traineetrader.com/wp-content/uploads/2011/02/custom-sort-symbols.png" alt="" width="501" height="231" />Creating a New Page in eSignal 11 and Adding a Watch List</h4>
<p style="text-align: left;">The first step is to create a new page in eSignal, to do this go to eSignal menu -&gt; New Page or CTRL + SHIFT + N.</p>
<p style="text-align: center;"><a href="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal-NewPage.png"><img class="aligncenter size-full wp-image-1467" title="eSignal-NewPage" src="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal-NewPage.png" alt="" width="610" height="545" /></a></p>
<p style="text-align: left;">In the New Window template select Watch List. This will add a blank watch list to the page. After the Watch List has been added it is a good idea to save the page. You can do this be right clicking on the page tab and selecting save.</p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-1469" title="eSignal11-NewPage-watch-list" src="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal11-NewPage-watch-list.png" alt="" width="519" height="301" />For each GCIS group I will create a new list. To do this simply click on the gear icon to the right of the blank symbol list, now rename the list to the appropriate GCIS group.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-1470" title="eSignal11-NewPage-watch-list-rename" src="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal11-NewPage-watch-list-rename.png" alt="" width="360" height="179" /></p>
<p style="text-align: left;">Copy and paste the group symbols from the Excel spreed-sheet, save the list rinse and repeat. The image below shows my ASX sorted GCIS watch lists.</p>
<p><a href="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal-NewPage-asx-data.png"><img class="aligncenter size-full wp-image-1471" title="eSignal-NewPage-asx-data" src="http://www.traineetrader.com/wp-content/uploads/2011/02/eSignal-NewPage-asx-data.png" alt="" width="608" height="541" /></a>In total there are 21 separate lists with 2227 symbols.</p>
<p style="text-align: left;">
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/esignal-11-creating-your-own-watch-list-ordering-by-sector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Numerical Computing Environments for Traders</title>
		<link>http://www.traineetrader.com/numerical-computing-environments-for-traders/</link>
		<comments>http://www.traineetrader.com/numerical-computing-environments-for-traders/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 04:52:07 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[Octave]]></category>
		<category><![CDATA[Quant]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Scilab]]></category>
		<category><![CDATA[SciPy]]></category>
		<category><![CDATA[Trading]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=1271</guid>
		<description><![CDATA[Microsoft Excel is an excellent tool and you will be able to accomplish most of your work in it. However there will come a time when you need to test a complex model, run a large simulation or work with a huge data set that would grind Excel to a halt. Numerical Computing Environments When [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft Excel is an excellent tool and you will be able to accomplish most of your work in it. However there will come a time when you need to test a complex model, run a large simulation or work with a huge data set that would grind Excel to a halt.</p>
<h2>Numerical Computing Environments</h2>
<p>When all is said and done there are 5 main options that each have a large community base. You should try out each environment to see which works best for you and is most cost effective. I have found a happy medium using SciPy and Matlab. I will however be testing out SciLab over the next few weeks.</p>
<h2>Matlab</h2>
<p style="text-align: center;"><a href="http://www.mathworks.com/products/matlab/"><img class="aligncenter size-full wp-image-1280" title="matlab" src="http://www.traineetrader.com/wp-content/uploads/2011/01/matlab.jpg" alt="" width="500" height="559" /></a></p>
<p>Matlab is the &#8220;Big Daddy&#8221; or the King of Numerical computing environments. I don&#8217;t think I really need to add much more. It does pretty much everything and you can extend it with .m code, however you need deep pockets.</p>
<h2>Scilab</h2>
<p style="text-align: center;"><a href="http://www.scilab.org/"><img class="aligncenter size-full wp-image-1277" title="scilab" src="http://www.traineetrader.com/wp-content/uploads/2011/01/scilab.jpg" alt="Scilab Numerical Computing" width="500" height="383" /></a></p>
<p style="text-align: left;"><a href="http://www.scilab.org/" target="_blank">Scilab </a>provides features similar to Matlab and has a built-in Matlab translator. Scilab comes in a complete package and is easy to setup and run. Scilab also has a code editor and allows for C++ code integration.</p>
<h2>Octave</h2>
<p style="text-align: center;"><a href="http://www.gnu.org/software/octave/"><img class="aligncenter size-full wp-image-1278" title="octave" src="http://www.traineetrader.com/wp-content/uploads/2011/01/octave.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://www.gnu.org/software/octave/" target="_blank">Octave</a> is essentially an open source Matlab clone. You will have to port your code between Matlab and octave as they have subtle differences and Octave has no IDE.</p>
<h2>SciPy</h2>
<p style="text-align: center;"><a href="http://www.scipy.org/"><img class="aligncenter size-full wp-image-1279" title="scipy" src="http://www.traineetrader.com/wp-content/uploads/2011/01/scipy.jpg" alt="" width="500" height="266" /></a></p>
<p><span style="font-weight: normal;"><a href="http://www.scipy.org/" target="_blank">SciPy</a> + numpy + matplotlib provides modules for plotting, large datasets, statistics, optimisation, numerical integration, linear algebra, Fourier transforms, signal processing, image processing, ODE solvers, special functions and of course all the power and simplicity of the python. This is the option I have gone with.</span></p>
<h2><span style="font-weight: normal;">R </span></h2>
<p><a href="http://www.r-project.org/"><img class="aligncenter size-full wp-image-1281" title="R" src="http://www.traineetrader.com/wp-content/uploads/2011/01/R.jpg" alt="" width="500" height="334" /></a></p>
<p><span style="font-weight: normal;"><a href="http://www.r-project.org/" target="_blank">R </a>is a software environment for statistical computing and graphics. R is a very powerful yet arcane programming language. I would only recommend for people comfortable programming. I have it on the computer but have as yet not put in the time to learn R.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/numerical-computing-environments-for-traders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building an Automated FOREX System:  Writing the Pseudo Code</title>
		<link>http://www.traineetrader.com/building-an-automated-forex-system-writing-the-pseudo-code/</link>
		<comments>http://www.traineetrader.com/building-an-automated-forex-system-writing-the-pseudo-code/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 05:53:27 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[FOREX]]></category>
		<category><![CDATA[Fundamentals]]></category>
		<category><![CDATA[MetaTrader]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[MetaEditor]]></category>
		<category><![CDATA[Pseudo Code]]></category>
		<category><![CDATA[Turtle Trading]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=971</guid>
		<description><![CDATA[In our last article we examined the basics of writing pseudo code and briefly looked at strategy design. If you have not read Designing a simple strategy and Pseudo Code you will need read that before continuing. In this article we will be translating the original Turtle Trader rules into pseudo code. This will ensure [...]]]></description>
			<content:encoded><![CDATA[<p>In our last article we examined the basics of writing pseudo code and briefly looked at strategy design. If you have not read <a href="http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/" target="_blank">Designing a simple strategy and Pseudo Code</a> you will need read that before continuing. In this article we will be translating the original Turtle Trader rules into pseudo code. This will ensure we have a good understanding of the trading system we will be implementing.</p>
<h3>Writing Pseudo Code in MeataEditor</h3>
<p>For simplicity reasons we will write our trend following system pseudo code in MetaEditor. Open MetaEditor from “[drive]:/Program Files/MetaTrader4/” folder. Alternatively you can open MetaTrader and press F4 or Tools –&gt; Meta Quotes Language Editor.</p>
<p><strong>Step One </strong></p>
<p>Create a New File of type Expert Advisor. File –&gt; New or CTRL +N.</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.traineetrader.com/wp-content/uploads/2010/04/MQL.gif"><img class="aligncenter size-full wp-image-976" title="MQL Expert Advisor" src="http://www.traineetrader.com/wp-content/uploads/2010/04/MQL.gif" alt="MQL Expert Advisor, EA CODE" width="505" height="376" /></a></p>
<p style="text-align: left;"><strong>Step Two</strong></p>
<p style="text-align: left;">Click Next an enter appropriate details for the system. Call your Expert Advisor Turtle System.</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.traineetrader.com/wp-content/uploads/2010/04/Box2.gif"><img class="aligncenter size-full wp-image-977" title="Expert Advisor" src="http://www.traineetrader.com/wp-content/uploads/2010/04/Box2.gif" alt="Expert Advisor Wizard EA, Turtle System" width="505" height="375" /></a></p>
<p style="text-align: left;"><strong>Finally,</strong> you should see a code window similar to the one below:</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.traineetrader.com/wp-content/uploads/2010/04/CodeWindow.png"><img class="aligncenter size-full wp-image-978" title="CodeWindow" src="http://www.traineetrader.com/wp-content/uploads/2010/04/CodeWindow.png" alt="" width="508" height="401" /></a></p>
<p style="text-align: left;">We will be following the pseudo code convention outlined in the pseudo standard  presented in the previous<a href="http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/" target="_blank"> article</a>. We will enter the pseudo code as comments in MetaEditor, for simplicity we will use the quote modifier. Below is sample pseudo code I have written to implement most parts of the Turtle Trading system. This is the first iteration and there are errors present in the code. Can you find the errors in the pseudo code?</p>
<p style="text-align: left;">
<pre class="brush: text">// Calculate True Range
FUNCTION trueRange WITH todaysHigh AND todaysLow AND pDayClose
    RETURN CALL findMax((todaysHigh - todaysLow), abs(todaysHigh - pDayClose), abs(pDayClose - todaysLow))
END FUNCTION       

// Calculate N
FUNCTION calcN WITH prevN and trueRange
    RETURN (19 * prevN + trueRange) / 20
END FUNCTION

// Detrmine the dollar value of a pip
// 1 lot = 100,000 base currency
// PPV = Per Pip Value
FUNCTION PPV WITH lotSize, currentPrice, accCurrency, pipVal
    inCurr = pipVal / currentPrice
    RETURN accCurrency * inCurr * (lotSize *100000)
END FUNCTION

// Calculate the dollar volatility of a currency pair
FUNCTION dollarVol WITH n AND ppv
    RETURN n * ppv
END FUNCTION

// Calculate unit value for given account
FUNCTION calcUnit WITH dollarVol, accBalance
    return (0.01 * accBalance) / dollarVol
END FUNCTION

// Misc rules
// max 12 units in one direction
// if account drops 10% reduce available equity by 20%

////////////////////// Entries ///////////////////
// System One A shorter term 20 period breakout
// buy or sell 20 period breakout
// buy or sell 1 unit
// if previous breakout winner skip trade
// losing if previous breakout 2N loss
// stops set at 2n below entry

IF currentPrice &gt; 20periodHigh AND prevLongTradeLoser THEN
    CALL buyCurr
ELSE IF currentPrice &lt; 20periodLow AND prevShortTradeLoser THEN
    CALL sellCurr
END

// System Two 55 period breakout entry
IF currentPrice &gt; 55periodHigh AND THEN
    CALL buyCurr
ELSE IF currentPrice &lt; 55periodLow THEN
    CALL sellCurr
END

// Adding units
// Additional units added stops raised by half n
// add a unit every 1n move
IF tradeLong AND currentPrice &gt; (lngEntPrice + n) THEN
    CALL buyCurr
    CALL adjStop
ELSE IF tradeShort AND currentPrice &lt; (lngEntPrice - n) THEN
    CALL sellCurr
    CALL adjStop
END

///////////////////Exits ///////////////////////
// System one
// 10 period low for long posn
// 10 period high for short posn 

IF s1tradeLong AND currentPrice &lt; 10periodLow THEN
    CALL sellCurr
ELSE IF s1tradeShort AND currentPrice &gt; 10periodHigh THEN
    CALL buyCurr
END

// System two exit
// 20 period low for long posn
// 20 period high for short posn

IF s2tradeLong AND currentPrice &lt; 20periodLow THEN
    CALL sellCurr
ELSE IF s2tradeShort AND currentPrice &gt; 20periodHigh THEN
    CALL buyCurr
END</pre>
<p>As you can see this code gives us an excellent starting point for the development of our Turtle Trading system. In the next article we will go through the specifics of coding in MQL. I have provided a basic implementation of the code for this trading system but you will derive most benefit from creating your own implementations of this system.</p>
<p><strong>Related Articles</strong></p>
<ul>
<li><strong><a href="http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/" target="_blank"> Building an Automated FOREX System: Designing a Simple Strategy and Introduction to Pseudo Code.</a></strong></li>
<li><strong><a href="http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/" target="_blank">Building an Automated FOREX System: Expert Advisors &amp; Indicators</a></strong></li>
<li><strong><a href="http://www.traineetrader.com/building-an-automated-currency-trading-system-from-scratch/" target="_blank">Building an automated currency trading system from scratch.</a></strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/building-an-automated-forex-system-writing-the-pseudo-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing Stock Data From Yahoo Using Python</title>
		<link>http://www.traineetrader.com/importing-stock-data-from-yahoo-using-python/</link>
		<comments>http://www.traineetrader.com/importing-stock-data-from-yahoo-using-python/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 05:16:45 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quantitative Trading]]></category>
		<category><![CDATA[Share Market]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ipython]]></category>
		<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[stock]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/?p=935</guid>
		<description><![CDATA[As I discussed in my previous post I have started to explore the possibilities of using python for quant fiance applications. To be honest I have only spent about 2 hours working on this project.  In that short amount of time I have been able to: Connect to Interactive Brokers via IbPy. Connect and download [...]]]></description>
			<content:encoded><![CDATA[<p>As I discussed in my previous post I have started to explore the possibilities of using python for quant fiance applications. To be honest I have only spent about 2 hours working on this project.  In that short amount of time I have been able to:</p>
<ul>
<li>Connect to Interactive Brokers via IbPy.</li>
<li>Connect and download free stock data from Yahoo finance via ystockquote.</li>
<li>Visualise stock data using matplotlib.</li>
</ul>
<p>I wont  go through connecting to Interactive Broker here as max has written an excellent tutorial on his <a href="http://www.maxdama.com/2009/12/interactive-brokers-via-python-updated.html" target="_blank">site</a>. Max provides some excellent resources on quant trading.</p>
<h3><strong>Getting Stock Quotes From Yahoo via Python</strong></h3>
<p><a href="http://www.goldb.org/" target="_blank">Corey Goldberg</a> has written a simple module that is a good starting point for getting stock data. I am yet to modify the code but when I do I will post the modified source code. You can download the source code for ystockquote.py below:</p>
<pre class="brush: python">#!/usr/bin/env python
#
#  Copyright (c) 2007-2008, Corey Goldberg (corey@goldb.org)
#
#  license: GNU LGPL
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.

import urllib

"""
This is the "ystockquote" module.

This module provides a Python API for retrieving stock data from Yahoo Finance.

sample usage:
&gt;&gt;&gt; import ystockquote
&gt;&gt;&gt; print ystockquote.get_price('GOOG')
529.46
"""

def __request(symbol, stat):
    url = 'http://finance.yahoo.com/d/quotes.csv?s=%s&amp;f=%s' % (symbol, stat)
    return urllib.urlopen(url).read().strip().strip('"')

def get_all(symbol):
    """
    Get all available quote data for the given ticker symbol.

    Returns a dictionary.
    """
    values = __request(symbol, 'l1c1va2xj1b4j4dyekjm3m4rr5p5p6s7').split(',')
    data = {}
    data['price'] = values[0]
    data['change'] = values[1]
    data['volume'] = values[2]
    data['avg_daily_volume'] = values[3]
    data['stock_exchange'] = values[4]
    data['market_cap'] = values[5]
    data['book_value'] = values[6]
    data['ebitda'] = values[7]
    data['dividend_per_share'] = values[8]
    data['dividend_yield'] = values[9]
    data['earnings_per_share'] = values[10]
    data['52_week_high'] = values[11]
    data['52_week_low'] = values[12]
    data['50day_moving_avg'] = values[13]
    data['200day_moving_avg'] = values[14]
    data['price_earnings_ratio'] = values[15]
    data['price_earnings_growth_ratio'] = values[16]
    data['price_sales_ratio'] = values[17]
    data['price_book_ratio'] = values[18]
    data['short_ratio'] = values[19]
    return data

def get_price(symbol):
    return __request(symbol, 'l1')

def get_change(symbol):
    return __request(symbol, 'c1')

def get_volume(symbol):
    return __request(symbol, 'v')

def get_avg_daily_volume(symbol):
    return __request(symbol, 'a2')

def get_stock_exchange(symbol):
    return __request(symbol, 'x')

def get_market_cap(symbol):
    return __request(symbol, 'j1')

def get_book_value(symbol):
    return __request(symbol, 'b4')

def get_ebitda(symbol):
    return __request(symbol, 'j4')

def get_dividend_per_share(symbol):
    return __request(symbol, 'd')

def get_dividend_yield(symbol):
    return __request(symbol, 'y')

def get_earnings_per_share(symbol):
    return __request(symbol, 'e')

def get_52_week_high(symbol):
    return __request(symbol, 'k')

def get_52_week_low(symbol):
    return __request(symbol, 'j')

def get_50day_moving_avg(symbol):
    return __request(symbol, 'm3')

def get_200day_moving_avg(symbol):
    return __request(symbol, 'm4')

def get_price_earnings_ratio(symbol):
    return __request(symbol, 'r')

def get_price_earnings_growth_ratio(symbol):
    return __request(symbol, 'r5')

def get_price_sales_ratio(symbol):
    return __request(symbol, 'p5')

def get_price_book_ratio(symbol):
    return __request(symbol, 'p6')

def get_short_ratio(symbol):
    return __request(symbol, 's7')

def get_historical_prices(symbol, start_date, end_date):
    """
    Get historical prices for the given ticker symbol.
    Date format is 'YYYYMMDD'

    Returns a nested list.
    """
    url = 'http://ichart.yahoo.com/table.csv?s=%s&amp;' % symbol + \
          'd=%s&amp;' % str(int(end_date[4:6]) - 1) + \
          'e=%s&amp;' % str(int(end_date[6:8])) + \
          'f=%s&amp;' % str(int(end_date[0:4])) + \
          'g=d&amp;' + \
          'a=%s&amp;' % str(int(start_date[4:6]) - 1) + \
          'b=%s&amp;' % str(int(start_date[6:8])) + \
          'c=%s&amp;' % str(int(start_date[0:4])) + \
          'ignore=.csv'
    days = urllib.urlopen(url).readlines()
    data = [day[:-2].split(',') for day in days]
    return data</pre>
<p>As you can see python is a very simple easy to read and understand language.</p>
<h3><strong>A Very Simple Example</strong></h3>
<p>In this simple example we will work in the interactive ipython environment with matplotlib. We will download the data separate the data and store it in separate list data structures. This is a very inefficient way of doing things and is not optimal. This example is for demonstration purposes.</p>
<pre class="brush: python">import ystockquote

# Get Quotes 01/01/2006 - 01/01/2009
GOOG = ystockquote.get_historical_prices('GOOG', '20060101', '20090101')

# Create empty lists, quick and dirty
GOOGOpen = [ ]
GOOGClose = [ ]
GOOGDate = [ ]
GOOGHigh = [ ]
GOOGLow = [ ]
GOOGAdj = [ ]
GOOGVolume = [ ]

# Populate lists from downloaded data
for i in range(1, 755):
	GOOGDate.append(GOOG[i][0])
	GOOGOpen.append(GOOG[i][1])
	GOOGHigh.append(GOOG[i][2])
	GOOGLow.append(GOOG[i][3])
	GOOGClose.append(GOOG[i][4])
	GOOGVolume.append(GOOG[i][5])
 	GOOGAdj.append(GOOG[i][6])

plot(GOOGAdj)
title("Google Adjusted Close")
ylabel(r"GOOG Closing Price ($USD)", fontsize = 12)
xlabel(r"Date", fontsize = 12)
grid(True)</pre>
<p>The image below shows the output we get when we save the plot as a .png file.</p>
<p style="text-align: center;"><a href="http://www.traineetrader.com/wp-content/uploads/2010/04/GOOGADJ.png"><img class="aligncenter size-full wp-image-943" title="Google Adjusted close - Python matplotlib" src="http://www.traineetrader.com/wp-content/uploads/2010/04/GOOGADJ.png" alt="Google Adjusted close - Python matplotlib" width="637" height="470" /></a></p>
<p>As you can see we need to adjust the x category labels. We will do this in an upcoming tutorial.</p>
<h3><strong>Creating a simple linked chart in Python</strong></h3>
<p>In Matlab it is very easy to create linked graphs, it is also possible to create linked graphs using matplotlib. The example below shows how we can link volume and adjusted close for Google.</p>
<pre class="brush: python">import ystockquote

# Get Quotes 01/01/2006 - 01/01/2009
GOOG = ystockquote.get_historical_prices('GOOG', '20060101', '20090101')

# Create empty lists, quick and dirty
GOOGOpen = [ ]
GOOGClose = [ ]
GOOGDate = [ ]
GOOGHigh = [ ]
GOOGLow = [ ]
GOOGAdj = [ ]
GOOGVolume = [ ]

# Populate lists from downloaded data
for i in range(1, 755):
	GOOGDate.append(GOOG[i][0])
	GOOGOpen.append(GOOG[i][1])
	GOOGHigh.append(GOOG[i][2])
	GOOGLow.append(GOOG[i][3])
	GOOGClose.append(GOOG[i][4])
	GOOGVolume.append(GOOG[i][5])
 	GOOGAdj.append(GOOG[i][6])

#create canvas add two plots linked via x-axis
fig = figure()
ax = fig.add_subplot(311)
ax2 = fig.add_subplot(312, sharex=ax)
ax.plot(GOOGAdj)
ax2.plot(GOOGVolume)</pre>
<p>Below you can see the output, you can scroll and zoom these graphs and they remain aligned.</p>
<p style="text-align: center;"><a href="http://www.traineetrader.com/wp-content/uploads/2010/04/linkgoog.gif"><img class="aligncenter size-large wp-image-951" title="Linked Data Graphs Google" src="http://www.traineetrader.com/wp-content/uploads/2010/04/linkgoog-1024x553.gif" alt="Linked Data Graphs Google" width="614" height="332" /></a>Below shows what happens when you zoom in on a chart.</p>
<p style="text-align: center;"><a href="http://www.traineetrader.com/wp-content/uploads/2010/04/zoomlink.gif"><img class="aligncenter size-full wp-image-952" title="Linked Data Graphs Google Zoomed" src="http://www.traineetrader.com/wp-content/uploads/2010/04/zoomlink.gif" alt="zoomlink" width="623" height="337" /></a></p>
<p style="text-align: left;">As you can see from the above examples python is easy to use and is very flexible. In my next post I will go through some more advanced charting and drawing functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/importing-stock-data-from-yahoo-using-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up The Perfect Python Development Environment</title>
		<link>http://www.traineetrader.com/setting-up-the-perfect-python-development-environment/</link>
		<comments>http://www.traineetrader.com/setting-up-the-perfect-python-development-environment/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 03:30:23 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ATS]]></category>
		<category><![CDATA[IbPy]]></category>
		<category><![CDATA[Ipython]]></category>
		<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[NumPy]]></category>
		<category><![CDATA[SciPy]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/setting-up-the-perfect-python-development-environment/</guid>
		<description><![CDATA[I am sure most of you by now have heard about the awesomeness of Python. Python is a lightweight programming / scripting language that is very simple to learn yet powerful. As you know if you have been reading this blog you would know I am looking to test and develop automated trading strategies and [...]]]></description>
			<content:encoded><![CDATA[<p>I am sure most of you by now have heard about the awesomeness of Python. Python is a lightweight programming / scripting language that is very simple to learn yet powerful. As you know if you have been reading this blog you would know I am looking to test and develop automated trading strategies and the for the most part I have been using C++, Matlab, Excel and MetaTrader.</p>
<p>I have kept my head in the sand as I hear readers and colleagues constantly extol the virtues of working with Python. I am for the most part happy with Matlab for strategy evaluation, however it is not very good when it comes to the execution side of a strategy. So this weekend I have decided to get in touch with my inner Python. I like the idea of being able to develop, test and implement a strategy all in the same development environment. The best part about using Python is it&#8217;s Open Source and has a number of useful packages available.</p>
<h3>The Zen of Python</h3>
<blockquote><p>Beautiful is better than ugly.     <br />Explicit is better than implicit.      <br />Simple is better than complex.      <br />Complex is better than complicated.      <br />Flat is better than nested.      <br />Sparse is better than dense.      <br />Readability counts.      <br />Special cases aren&#8217;t special enough to break the rules.      <br />Although practicality beats purity.      <br />Errors should never pass silently.      <br />Unless explicitly silenced.      <br />In the face of ambiguity, refuse the temptation to guess.      <br />There should be one&#8211; and preferably only one &#8211;obvious way to do it.      <br />Although that way may not be obvious at first unless you&#8217;re Dutch.      <br />Now is better than never.      <br />Although never is often better than right now.      <br />If the implementation is hard to explain, it&#8217;s a bad idea.      <br />If the implementation is easy to explain, it may be a good idea.      <br />Namespaces are one honking great idea &#8212; let&#8217;s do more of those!      <br />—Tim Peters</p>
</blockquote>
<p>To get this gem of wisdom simply type <strong>import this</strong> at the interactive python prompt. After a little research I have decided to use iPython as my interactive development environment at this stage I am not sure what I will use to write my static python code. For the moment I will just use emacs while I look into WingIDE.</p>
<p>Setting up Python</p>
<p>If you are not experienced with a UNIX like environment you may have a few issues with setting up all the libraries that are required. For the most part is smooth sailing. As I am running OS X I decided to take the easy / lazy option and just use mac ports.</p>
<p>At the moment I am experimenting with the following packages:</p>
<ul>
<li><a href="http://ipython.scipy.org/moin/" target="_blank">Ipython</a> – An enhanced interactive python shell.</li>
<li><a href="http://www.scipy.org/" target="_blank">SciPy + NumPy</a> – Scientific computing library.</li>
<li><a href="http://scikits.appspot.com/timeseries" target="_blank">SciKits.timeseries</a> – Functions for time series manipulation.</li>
<li><a href="http://matplotlib.sourceforge.net/" target="_blank">matplotlib</a> – Python 2d plotting library. </li>
<li><a href="http://code.enthought.com/projects/mayavi/" target="_blank">Mayavi</a> – 3d data visualization. </li>
<li><a href="http://code.google.com/p/ibpy/" target="_blank">IbPy</a> – Interactive brokers python API.</li>
</ul>
<p>I tested matplotlib with the different back ends and in the end went with TkAgg backend. I have written a few simple shell scripts so I can launch IBTWS and Ipython from the desktop. </p>
<p><strong><u>Hint:</u></strong> If you are running OS X you can simply save your shell scripts as .command files and chmod +x and they are executable from finder.</p>
<p>Now I am going to work through learning the programming language over the coming weeks. The language is very simple and easy to understand and coming from C++ I don’t think it will be to hard to pick up. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/setting-up-the-perfect-python-development-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing a Simple Strategy and Introduction to Pseudo Code</title>
		<link>http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/</link>
		<comments>http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 06:06:49 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[FOREX]]></category>
		<category><![CDATA[MetaTrader]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[EA]]></category>
		<category><![CDATA[Expert Advisor]]></category>
		<category><![CDATA[System ATS]]></category>
		<category><![CDATA[Trading System]]></category>
		<category><![CDATA[Trend]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/</guid>
		<description><![CDATA[Today we will be looking at designing a simple strategy and we will also start to write some pseudo code in MetaEditor. This is of course a multi part tutorial series and if you have not read the previous articles I suggest you do so before moving on to this article. In the previous article [...]]]></description>
			<content:encoded><![CDATA[<p>Today we will be looking at designing a simple strategy and we will also start to write some pseudo code in MetaEditor. This is of course a multi part tutorial series and if you have not read the previous articles I suggest you do so before moving on to this article. In the previous article on <a href="http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/" target="_blank">Expert Advisors (EA) and indicators</a> we touched on the different ways we can automate trading, today we will focus on Expert Advisors (EA).</p>
<p>&#160;</p>
<h3>Strategy Design</h3>
<p>Designing a trading strategy could be the focus of whole encyclopedia, what we discuss here will simply be a quick overview. In it’s simplest from a trading strategy is simply&#160; a set of predefined rules for executing trading decisions. By using an automated trading strategy emotional bias is removed. There are several different types of trading strategies that have been used over the years and usually fall into one of the following categories:&#160; </p>
<ul>
<li>Fundamental Analysis based systems.</li>
<li>Technical Analysis Based systems.</li>
<li>Volatility based systems</li>
<li>Mean reversion based systems.</li>
<li>Trend Following systems.</li>
</ul>
<h3>Building a Trend Following Based System</h3>
<p>We will be building a Trend Following system, this will be a very basic system and will help highlight the development process. When developing a trading system it is very tempting to try and re-invent the wheel, however we will start with a tried and tested system that is publically available. The trading system we will be implementing is the original Turtle Trading System and you will need to <a href="https://www.bsp-capital.com/documents/turtlerules.pdf" target="_blank">download</a> a copy of the rules in order to continue with the tutorial. </p>
<h3>Learning to Write Pseudo Code</h3>
<p>Before reading any more make sure you have printed out and read through the original Turtle Trading System Rules document. This step is very important as the only way to learn this materiel is by taking action and carrying out the steps outlined.</p>
<p align="center"><font color="#ff0000" size="5">STOP!</font></p>
<p>Now we can get on with our discussion of pseudo code. When it comes to writing computer programs or in this case automated trading systems translating English into programming code can be fraught with danger. Pseudo Code on the other hand refers to a more structured English for describing a process or program. It is important that you learn to write quality pseudo code as it will make a big difference when you come to coding your system your self or hiring a programmer. </p>
<p>There are many benefits in writing your algorithms or trading logic in pseudo code these include: </p>
<ul>
<li>You will gain a detailed understanding of the program or algorithm you are developing.</li>
<li>Errors in logic picked up early.</li>
<li>Not constrained by a single programming language.</li>
</ul>
<p>Below is a brief example of pseudo code: </p>
<p>IF movingAverage1 == movingAverage2 THEN   <br />&#160;&#160;&#160; SEND buyOrder    <br />END IF</p>
<h3>Structured Pseudo Code</h3>
<p>In order for us to write quality code we have to take a step back and think about what it is we are actually trying to achieve. Rather then using a trading example we will use an example that everyone is familiar with. Think about the process of going to the shop and buying 1 item let’s say it is milk. What I will ask you to do is sit down and write a step by step process that you could give to a an alien that describes the process in as much detail as possible.</p>
<p align="center"><font color="#ff0000" size="5">STOP!</font></p>
<p>Do not move on until you have done this.&#160; Below is the first iteration of solving the get milk problem:</p>
<p>Get into the car –&gt; Start the car –&gt; Drive to the closest shop that sells milk –&gt; Get Out of Car –&gt; Lock Car</p>
<p>Enter shop –&gt; Locate milk –&gt; Determine quantity –&gt; Pay for milk –&gt; Locate car –&gt; Unlock Car –&gt; Drive home.</p>
<p>As you can see if you think about the steps required to carry out this task it is much more complex then first thought. Let’s try and make this a bit more detailed iteration two:</p>
<blockquote><p>DEFINE approxMilkCost</p>
<p>DEFINE moneyInWallet </p>
<p>&#160;</p>
<p>IF moneyInWallet &lt; approxMilkCost THEN</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL enterCar WITH keys</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL driveTo WITH bank</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL leaveCar</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL getMoneyFromBank WITH accountDetails</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL driveTo WITH shop</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL leaveCar</p>
<p>ELSE</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL enterCar WITH keys</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL driveTo WITH shop</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CALL leaveCar</p>
<p>ENDIF</p>
<p>&#160;</p>
<p>enter shop</p>
<p>CALL locateItem WITH milk</p>
<p>CALL payForItem WITH money</p>
<p>leave shop</p>
<p>CALL enterCar WITH keys</p>
<p>CALL driveTo WITH home</p>
<p>CALL leaveCar</p>
</blockquote>
<p>You can quickly see that by using a more formal language it breaks down complex tasks into simple steps. If we wanted to write a program to solve this problem we would probably go through several more iterations of pseudo code before actually starting coding. I have created a <a href="http://bit.ly/dqwsRN" target="_blank">PDF file</a> and have uploaded it so you can fully understand the pseudo code presented and can practice writing some pseudo code for yourself.&#160; In the next article we will be looking at writing our trend following system out in pseudo code so make sure you review everything presented here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/designing-a-simple-strategy-and-introduction-to-pseudo-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building an Automated FOREX System: Expert Advisors &amp; Indicators</title>
		<link>http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/</link>
		<comments>http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 01:31:52 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[FOREX]]></category>
		<category><![CDATA[MetaTrader]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[ATS]]></category>
		<category><![CDATA[EA]]></category>
		<category><![CDATA[Indicators]]></category>
		<category><![CDATA[MetaEditor]]></category>
		<category><![CDATA[Trading System]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/</guid>
		<description><![CDATA[This is article number two in our tutorial series Building an Automated Currency Trading System from Scratch. If you have not read the introduction to this tutorial series I recommend you read building an ATS before reading this article. MetaTrader 4 The current version that is most widely used and supported is MetaTrader 4 however [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: medium;"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Ind" src="http://www.traineetrader.com/wp-content/uploads/2010/02/Ind.png" border="0" alt="Ind" width="184" height="410" align="right" /></span>This is article number two in our tutorial series Building an Automated Currency Trading System from Scratch. If you have not read the introduction to this tutorial series I recommend you read <a href="http://www.traineetrader.com/building-an-automated-currency-trading-system-from-scratch/" target="_blank">building an ATS</a> before reading this article.</p>
<p><span style="font-size: medium;">MetaTrader 4</span></p>
<p>The current version that is most widely used and supported is MetaTrader 4 however beta versions of MetaTrader 5 are currently in testing. In order to build an automated trading system using MetaTrader 4 we will need to write a program that will run inside MetaTrader. There are three types of programs that run inside MetaTrader, these are Custom Indicators, Expert Advisors and Scripts. The screen shot on the right shows the built in indicators that ship with MetaTrader.</p>
<p align="center">
<p><span style="font-size: medium;">MetaTrader- MetaQuotes Language</span></p>
<p>Custom Indicators, Expert Advisors and scripts are all written in a programming language called MetaQuotes Language, often abbreviated MQL.  Although all three application types are written in MQL there are slight differences between program types.</p>
<p><span style="font-size: medium;">MetaTrader- Indicators and Custom Indicators</span></p>
<p>Custom indicators are written in MQL the client terminal will execute the indicator every time a tick is received. The main use of indicators is to graphically display some user defined or built in data relationship. The most common use for indicators is for Technical Analysis. Below are some screenshots which show a built-in indicator being applied to the daily AUD/USD currency chart.</p>
<ol>
<li>With AUD/USD chart open double click on desired indicator.</li>
<li>Enter parameter settings and execute.</li>
</ol>
<p align="center"><a href="http://www.traineetrader.com/wp-content/uploads/2010/02/IndSetting.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Indicator Setting MetaTrader" src="http://www.traineetrader.com/wp-content/uploads/2010/02/IndSetting_thumb.png" border="0" alt="Indicator Setting MetaTrader" width="504" height="326" /></a></p>
<p align="center"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MACD Indicator" src="http://www.traineetrader.com/wp-content/uploads/2010/02/MetaInd.png" border="0" alt="MACD Indicator" width="504" height="392" /></p>
<p><span style="font-size: medium;">MetaTrader- Expert Advisors</span></p>
<p>An Expert Advisor or EA for short share similar properties to Indicators. Expert Advisors or EA’s are written in MQL and are executed on tick data. Expert Advisors or EA’s have trade logic written into them. Basically an EA does everything an indicator can do, however an EA will also open, close and modify trades programmatically. To attach an EA to a currency pair the process is exactly the same as it is for an indicator. There are two sample EA’s that ship with MetaTrader 4 these are the MACD Sample and Moving Average.</p>
<p><span style="font-size: medium;">MetaTrader- Scripts</span></p>
<p>Scripts are the final type of application that are available in MetaTrader. A script is designed to be executed only once. Scripts are usually used to automate client side non-trading actions, like modifying data. They can however be used to perform simple trade logic tasks.</p>
<p><span style="font-size: medium;">MetaTrader &#8211; MetaEditor</span></p>
<p>All the code we write for our automated trading system will be done MetaTrader’s Integrated Development Environment called MetaEditor. MetaEditor allows you to store and manage source code for all projects in an easy to use way. If you are used to Visual Studio or X-Code IDE’s then you will be disappointed with the functionality of MetaEditor. MedEditor does offer syntax highlighting and code completion which is very handy. There is also a built in on-line library that covers most topics. Below is a screenshot of the IDE:</p>
<p align="center"><a href="http://www.traineetrader.com/wp-content/uploads/2010/02/MetWindow.png"><img style="display: inline; border: 0px;" title="MetaEditor" src="http://www.traineetrader.com/wp-content/uploads/2010/02/MetWindow_thumb.png" border="0" alt="MetaEditor" width="504" height="398" /></a></p>
<p>To open MetaEditor from MetaTrader simply press F4 or from the menu bar:</p>
<p><strong>Tools –&gt; MetaQuotes Language Editor</strong></p>
<p><span style="font-size: medium;">Home Work</span></p>
<p>Before next article make sure you understand the three different program types that are used in MetaTrader. Also try attaching and using some of the built in indicators in MetaTrader. Before moving on I would also recommend downloading the <a href="http://book.mql4.com/" target="_blank">MQL4 book</a> from MetaQuotes. This is a free book that covers the basics of programming in MQL and in later articles I will assume you are up to speed with the concepts presented in the book.</p>
<p>In the next article we will discuss designing a simple trading strategy and pseudo code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/building-an-automated-forex-system-expert-advisors-indicators/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Exporting Data From MetaTrader</title>
		<link>http://www.traineetrader.com/exporting-data-from-metatrader/</link>
		<comments>http://www.traineetrader.com/exporting-data-from-metatrader/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 08:10:00 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[FOREX]]></category>
		<category><![CDATA[MetaTrader]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Pseudo Code]]></category>

		<guid isPermaLink="false">http://www.traineetrader.com/exporting-data-from-metatrader/</guid>
		<description><![CDATA[I received an email today from a reader wanting to know if there was an expert advisor available that would export data to a csv file. although I have not myself seen an EA that does this it is a trivial matter to code such an EA shown below: int handlFile; handlFile = FileOpen(&#8220;symbol.csv&#8221;, FILE_CSV [...]]]></description>
			<content:encoded><![CDATA[<p>I received an email today from a reader wanting to know if there was an expert advisor available that would export data to a csv file. although I have not myself seen an EA that does this it is a trivial matter to code such an EA shown below:</p>
<p class="info">int handlFile;<br />
handlFile = FileOpen(&#8220;symbol.csv&#8221;, FILE_CSV | FILE_WRITE | FILE_READ, &#8216;,&#8217;);<br />
FileSeek(handlFile, 0, SEEK_END);<br />
FileWrite(handlFile, Bid, Ask, Close[1], Volume[1]);<br />
FileClose(handlFile);</p>
<p>Note: This code above is intended as a very rough solution. Time permitting I will write a proper EA with error checking and better features. This code however should be sufficient for basic tasks. For more information on EA coding I strongly recommend you download the getting started book:</p>
<p class="download"><a href="http://www.mql4.com/files/MQl4BookEnglish.chm">MQL Tutorial</a></p>
<p><strong><span style="font-size: medium;">The Non EA Export Option</span></strong></p>
<p>Can’t be bothered with that coding garbage? Never fear there is a very simple option. Go to the Tools Menu then History Centre a dialog box similar to the one shown below will appear simply chose the currency you wish to export and select a file name and your done. This process is shown below:</p>
<p align="center"><img class="”aligncenter”/" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="ExportMetaTraderDataCSV" src="http://www.traineetrader.com/wp-content/uploads/2009/04/exportmetatraderdatacsv.jpg" border="0" alt="ExportMetaTraderDataCSV" width="500" height="500" /></p>
<p>MetaTrader really is an excellent platform for learning the basics of trading and trading systems. I would recommend to anyone starting out in currency trading that they download MetaTrader and start exploring. If you want to learn more about Forex Trading I suggest you visit the <a href="http://www.traineetrader.com/forex/" target="_blank">Forex</a> section of this website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.traineetrader.com/exporting-data-from-metatrader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

