As you may know, the Foreign Exchange Forex market is used for trading between currency pairs. A few years ago, driven by my curiosity, I took my first steps into the world of Forex trading algorithms by creating a demo account and playing out simulations with fake money on the Meta Trader 4 trading platform.
Spurred on by my own success, I dug deeper and eventually signed up for a number of forums. Soon, I was spending hours reading about algorithmic trading systems rule sets that determine whether you should buy or sell , custom indicators , market moods, and more.
Around this time, coincidentally, I heard that someone was trying to find a software developer to automate a simple trading system. This was back in my college days when I was learning about concurrent programming in Java threads, semaphores, and all that junk. The client wanted the system built with MQL4 , a functional programming language used by the Meta Trader 4 platform for performing stock-related actions.
The role of the trading platform Meta Trader 4, in this case is to provide a connection to a Forex broker. Through Meta Trader 4, you can access all this data with internal functions, accessible in various timeframes: The movement of the Current Price is called a tick.
In other words, a tick is a change in the Bid or Ask price for a currency pair. During active markets, there may be numerous ticks per second. During slow markets, there can be minutes without a tick. The tick is the heartbeat of a Forex robot. When you place an order through such a platform, you buy or sell a certain volume of a certain currency.
You also set stop-loss and take-profit limits. The stop-loss limit is the maximum amount of pips price variations that you can afford to lose before giving up on a trade. Many come built-in to Meta Trader 4. However, the indicators that my client was interested in came from a custom trading system. They wanted to trade every time two of these custom indicators intersected, and only at a certain angle. The start function is the heart of every MQL4 program since it is executed every time the market moves ergo, this function will execute once per tick.
For example, you could be operating on the H1 one hour timeframe, yet the start function would execute many thousands of times per timeframe. Once I built my algorithmic trading system, I wanted to know: Back-testing is the process of testing a particular automated or not system under the events of the past.
In other words, you test your system using the past as a proxy for the present. MT4 comes with an acceptable tool for back-testing a Forex trading system nowadays, there are more professional tools that offer greater functionality. To start, you setup your timeframes and run your program under a simulation; the tool will simulate each tick knowing that for each unit it should open at certain price, close at a certain price and, reach specified highs and lows.
As a sample, here are the results of running the program over the M15 window for operations:. This particular science is known as Parameter Optimization. I did some rough testing to try and infer the significance of the external parameters on the Return Ratio and came up with something like this:. You may think as I did that you should use the Parameter A.
Specifically, note the unpredictability of Parameter A: In other words, Parameter A is very likely to over-predict future results since any uncertainty, any shift at all will result in worse performance. But indeed, the future is uncertain! And so the return of Parameter A is also uncertain. The best choice, in fact, is to rely on unpredictability. Often, a parameter with a lower maximum return but superior predictability less fluctuation will be preferable to a parameter with high return but poor predictability.
In turn, you must acknowledge this unpredictability. This does not necessarily mean we should use Parameter B, because even the lower returns of Parameter A performs better than Parameter B; this is just to show you that Optimizing Parameters can result in tests that overstate likely future results, and such thinking is not obvious.
This is a subject that fascinates me. Building your own simulation system is an excellent option to learn more about the Forex market, and the possibilities are endless. The Forex world can be overwhelming at times, but I hope that this write-up has given you some points on how to get going.
Nowadays, there is a vast pool of tools to build, test, and improve Trading System Automations: Here are a few write-ups that I recommend for programmers and enthusiastic readers:. A Practical Tale for Engineers View all articles. My First Client Around this time, coincidentally, I heard that someone was trying to find a software developer to automate a simple trading system. MQL5 has since been released. As you might expect, it addresses some of MQL4's issues and comes with more built-in functions, which makes life easier.
If you want to learn more about the basics of trading e. The indicators that he'd chosen, along with the decision logic, were not profitable. Often, systems are un profitable for periods of time based on the market's "mood":. Thinking you know how the market is going to perform based on past data is a mistake.
Rogelio Nicolas Mengual, Argentina member since November 19, Rogelio is a versatile, positive, and self-motivated full-stack engineer with over twelve years of work experience in many programming languages, frameworks, and platforms. He enjoys taking on new challenges and constantly strives to learn new skills. I have always wanted to learn about this. I studied a bit of market theory in college and learned about channel trading.
I always thought that would be a good fit for algo trading since the strategy is recursive. Do you have any pointers on how to implement channel type of strategies as opposed to Moving Average strategies? I'm sure you know this, but some old research shows that Exponential MA strategies make more and even out perform buy and hold strategies without taking into account tax advantages.
Hi Rismay, thanks for commenting, about this: The values of the indicators are referenced as a reverse zero point array [oo.. Young's book is a good starting point to understand how indicators work. Curious if you've engaged in the https: Seems like a great way to get your feet wet. Congrats Great post Rogelio! Just wanted to share my experience as well: Almost every trading book states, that most traders fails because of psychological factor, when they make exceptions from their own strategies, so as an engineer my only tought was that this is a perfect place for a software solution to avoid human inntervention to the trading system once you decide to start using it.
I have spend one entire year of my career just by programming, testing and optimizing with past data every single strategy I was able to find online and on variuos different trading books. And you know what - none of them had constant profitability. And after reading a lot of blog posts etc I came to the conclusion: We are living in a world where everyone can write his own trading robot and big trading corporations, banks etc And here is the result: Once some pattern comes true at least for some period of time it emediatly turns in to no pattern, because everybody on this game are looking for these patterns.
Once you see some pattern you place an order to buy or sell, your order pushes the market to the opposite direction you want it to go at least for a bit. But do not be naieve, if you see the pattern most probably a lot of other traders with hudge investmens sees this pattern as well so this time they are doing the same and you all lose your money all together. Think of it before you decide to become a trader with software engineering background. Hi Simanas, Thanks for the thoughtful comment.
In a previous sketch of this article I described who the really smart players in this game are, and I mentioned the guys from Jane Street among others that play the role of middle-man and arbitrageurs in the market.
We The Editor, Charlie Marsh and Me decided not to include that among another reflections that considered just that you are mentioning in this comment. All that being said, I like to believe that you can find an edge of the market if you use the correct tools and make the correct simulations using the proper variables.
I haven't engaged in that community; it looks awesome to start programming and reuse the code offered there! I enjoyed this article as it is exactly the kinds of important big milestones I ran into. The project which started for a custom formula for several separate clients became a commercial product driven by user submissions. Now users can copy or sell their trades and copy trades from indicators in Meta Trader. You will get your principal back immediately after your investment term is expired..
The Quantopian does not provide any Forex data, right?? The site only provides stock and etf. I like their forex-copy system. You can copy the trades of successful traders and earn money even if you're newbie. And I'd like to say that their trading conditions are very suitable for me.
Spreads are good, I choose 1: Simple question you might be able to answer: Any advice appreciated thanks.
I have been trading with forex since and never encountered any issue. Hello You can try with penny stocks. Interesting article - so Nico, have any of the trading systems you built for clients proved to be consistently profitable?
I've toyed with developing one for a while but question whether or not FX price movement is predictable enough to make a consistent profit.More...