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 Expert Advisors (EA) and indicators we touched on the different ways we can automate trading, today we will focus on Expert Advisors (EA).
Strategy Design
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 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:
- Fundamental Analysis based systems.
- Technical Analysis Based systems.
- Volatility based systems
- Mean reversion based systems.
- Trend Following systems.
Building a Trend Following Based System
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 download a copy of the rules in order to continue with the tutorial.
Learning to Write Pseudo Code
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.
STOP!
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.
There are many benefits in writing your algorithms or trading logic in pseudo code these include:
- You will gain a detailed understanding of the program or algorithm you are developing.
- Errors in logic picked up early.
- Not constrained by a single programming language.
Below is a brief example of pseudo code:
IF movingAverage1 == movingAverage2 THEN
SEND buyOrder
END IF
Structured Pseudo Code
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.
STOP!
Do not move on until you have done this. Below is the first iteration of solving the get milk problem:
Get into the car –> Start the car –> Drive to the closest shop that sells milk –> Get Out of Car –> Lock Car
Enter shop –> Locate milk –> Determine quantity –> Pay for milk –> Locate car –> Unlock Car –> Drive home.
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:
DEFINE approxMilkCost
DEFINE moneyInWallet
IF moneyInWallet < approxMilkCost THEN
CALL enterCar WITH keys
CALL driveTo WITH bank
CALL leaveCar
CALL getMoneyFromBank WITH accountDetails
CALL driveTo WITH shop
CALL leaveCar
ELSE
CALL enterCar WITH keys
CALL driveTo WITH shop
CALL leaveCar
ENDIF
enter shop
CALL locateItem WITH milk
CALL payForItem WITH money
leave shop
CALL enterCar WITH keys
CALL driveTo WITH home
CALL leaveCar
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 PDF file and have uploaded it so you can fully understand the pseudo code presented and can practice writing some pseudo code for yourself. 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.
Popularity: 14% [?]




