Automated Trading Software for Foreign Exchange
Total Page:16
File Type:pdf, Size:1020Kb
Saul Stockhus AUTOMATED TRADING SOFTWARE FOR FOREIGN EXCHANGE Bachelor’s Thesis Information Technology May 2011 DESCRIPTION Date of the bachelor's thesis May 20, 2011 Author(s) Degree programme and option Saul Stockhus Information Technology Name of the bachelor's thesis Automated trading software for Foreign Exchange Abstract The Foreign Exchange market is the largest financial market in the world. It is used by banks, gov- ernments, corporations, hedge funds and other institutions for a number of purposes, such as curren- cy conversion, hedging and speculation. Due to advances in computing, financial data that could pre- viously only be analyzed using charts or calculated manually can now be run through extensive ana- lyses using special algorithms in order to predict the future. The aim of this study is to research trading in the Foreign Exchange market and to implement an au- tomated trading strategy using a suitable programming language and successfully test it with real market data. Of particular interest was the prospect of discovering new trading methods and tools. During the course of this study, different types of trading strategies as well as new chart types were developed for the NinjaTrader platform. The strategies were tested using historic exchange rates as well as captured live rates. Choosing the type of strategy, trading platform or broker, as well as other considerations such as real life implementation is discussed. The study is useful particularly to IT and business students interested in the currency markets and automated trading in general. The study gives guidelines on strategy development and gives room for improvement in the future. Subject headings, (keywords) Foreign Exchange, forex, price analysis, automated trading, algorithmic trading, NinjaTrader Pages Language URN 42 pages + appendices 2 pages English http://www.urn.fi/URN:NBN:f i:amk-201105208891 Remarks, notes on appendices Tutor Employer of the bachelor's thesis Reijo Vuohelainen Mikkeli University of Applied Sciences CONTENTS 1 INTRODUCTION................................................................................................ 1 1 FOREIGN EXCHANGE ..................................................................................... 3 1.1 Overview ..................................................................................................... 3 1.2 Participants ................................................................................................. 4 1.3 Financial instruments .................................................................................. 6 2 TRADING CONCEPTS ...................................................................................... 6 2.1 Trading with currency pairs ........................................................................ 6 2.2 Types of brokers ....................................................................................... 11 2.3 Terminology ............................................................................................. 12 3 ALGORITHMIC TRADING ............................................................................. 14 3.1 Overview ................................................................................................... 14 3.2 Technical Analysis .................................................................................... 14 3.3 Sample strategies ...................................................................................... 17 3.4 Software .................................................................................................... 18 3.5 Communication between platform and broker ......................................... 22 4 PROJECT ........................................................................................................... 23 4.1 Project overview ....................................................................................... 23 4.2 Considerations .......................................................................................... 23 4.3 Developed code ........................................................................................ 31 4.3.1 Strategies ..................................................................................... 31 4.3.2 Bar types ...................................................................................... 33 4.4 Problems ................................................................................................... 35 4.5 Results....................................................................................................... 36 4.6 Real life implementation ........................................................................... 40 5 CONCLUSION .................................................................................................. 40 BIBLIOGRAPHY ........................................................................................................ 42 APPENDICES LIST OF FIGURES Figure 1. Example of a currency pair chart ................................................................................ 7 Figure 2. Market Depth window of the ECN broker MB Trading, showing bids on the left and asks on the right ........................................................................................................................ 12 Figure 3. Bar properties in NinjaTrader ................................................................................... 15 Figure 4. Candlesticks .............................................................................................................. 15 Figure 5. OHLC bar .................................................................................................................. 16 Figure 6. Candlestick ................................................................................................................ 16 Figure 7. Line chart - example of an up trend .......................................................................... 16 Figure 8. MetaTrader 4 main window ...................................................................................... 19 Figure 9. MetaEditor programming environment .................................................................... 20 Figure 10. NinjaTrader 6.5 main window ................................................................................ 21 Figure 11. NinjaTrader script editor ......................................................................................... 22 Figure 12. Market Analyzer window with a custom indicator showing the current spread ..... 25 Figure 13. Range bar chart – a built-in bar type in NinjaTrader .............................................. 27 Figure 14. Renko bar behavior ................................................................................................. 28 Figure 15. New bar type behavior ............................................................................................ 28 Figure 16. Output window used for debugging ........................................................................ 31 Figure 17. Tracker bars ............................................................................................................. 34 Figure 18. 60 minute, Tracker and Neko bars compared ......................................................... 35 Figure 19. Strategy #1 - Cumulated profit ................................................................................ 37 Figure 20. Strategy #1, Profit/Loss Report. Green triangles indicate winning trades and red triangles losing trades. .............................................................................................................. 38 LIST OF TABLES Table 1. Foreign Exchange trading sessions .............................................................................. 3 Table 2. Top 10 currency traders - % of overall volume, May 2010 [Euromoney] ................... 4 Table 3. ISO 4271 codes and currency names for major currencies .......................................... 7 Table 4. Lot names and their sizes ............................................................................................. 8 Table 5. Spread cost compared to bar range. The chosen spread is 3 pips. ............................. 29 Table 6. Mixed mode operation ................................................................................................ 32 Table 7. Account performance ................................................................................................. 38 1 1 INTRODUCTION The Foreign Exchange market today is the largest financial market in the world and is an im- portant tool for international trade. The market allows currency to be bought and sold and in the process the market determines the relative values of currencies against each other. Busi- nesses use it to pay their workers, governments try to control the exchange rates of their cur- rency in order to maintain the economy and investors convert currency back and forth in order to invest and reap the profits. The Foreign Exchange did not always have the importance it has today. When the value of a currency was still tied to real commodities, such as gold and silver, there was little risk that holding a currency would affect profits. Foreign Exchange only had a minor part in finance until the late 1960’s, when governments with the largest economies agreed to part with the established Bretton Woods fixed-rate system and decided to allow trading to determine cur- rency rates, resulting in a floating exchange rate regime. Uncertainty about exchange rates