Daniel Pinto - Automated Trading in The Forex Market
Daniel Pinto - Automated Trading in The Forex Market
CONTENTS
Contents
1 Getting Started
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 What you should be willing to do. . . . . . . . . . . . . . . . . .
2 First Things First
2.1 What is an Expert Advisor ? . . . . .
2.2 Advantages of Expert Advisors . . . .
2.3 Disadvantages of Expert Advisors . .
2.4 The Psychology of automated trading
7
7
8
8
.
.
.
.
10
10
10
11
12
14
14
15
15
16
16
18
19
20
21
21
5 Types of Strategies
5.1 Characteristics of Unprofitable Strategies . . . . . . . . .
5.1.1 The Risk to Reward Ratio . . . . . . . . . . . . .
5.1.2 The Money Management . . . . . . . . . . . . . .
5.1.3 Fixed Orders . . . . . . . . . . . . . . . . . . . .
5.2 Characteristics of Profitable Systems . . . . . . . . . . . .
5.2.1 The Trend is your Friend . . . . . . . . . . . . . .
5.2.2 Cut your loses, let your profits run . . . . . . . . .
5.2.3 Dynamic Volatility Adjusted Money Management
5.2.4 The Risk to Reward Ratio . . . . . . . . . . . . .
23
23
23
24
25
26
26
26
27
27
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
CONTENTS
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
Is the expert really profitable or
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
28
28
30
31
33
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
38
38
39
39
40
40
40
41
41
43
43
44
48
48
49
51
51
51
52
53
54
56
58
58
CONTENTS
59
60
61
64
64
65
68
9.6
72
72
72
73
73
74
74
75
77
78
79
79
79
80
82
84
87
88
89
91
91
94
CONTENTS
12.5
12.6
12.7
12.8
12.4.6 Backtesting our new closing logic, time for our first optimization ! . . . . . . . . . . . . . . . . . . . . . . . . . .
12.4.7 Letting our Profits Run . . . . . . . . . . . . . . . . . . .
12.4.8 Additional Modifications . . . . . . . . . . . . . . . . . .
12.4.9 Wrapping up, a test with normal risk and a walk forward .
The Watukushay Automated Trading System No.2 - Trading Based
Solely on Price Action . . . . . . . . . . . . . . . . . . . . . . .
12.5.1 The Experts Logic. Which Candlestick Pattern ? . . . . .
12.5.2 Candlestick Pattern Definitions - How do we define these
patterns ? . . . . . . . . . . . . . . . . . . . . . . . . . .
12.5.3 Introducing Additional Candlestick Patterns - A Closing
Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.5.4 Further Improving Profitability - A pair specific closing
criteria . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.5.5 Optimizing Our Trading System, Increasing Profitability .
12.5.6 Would you like a Challenge ? . . . . . . . . . . . . . . .
Watukushay FE - Making a trading system For Everyone . . . . .
12.6.1 The Objective of Watukushay FE . . . . . . . . . . . . .
12.6.2 Understanding the RSI - The Trading Logic . . . . . . . .
12.6.3 Coding Watukushay FE . . . . . . . . . . . . . . . . . .
12.6.4 Testing Watukushay FE. First Observations. . . . . . . . .
12.6.5 Doing Optimizations of the Entry and Exit Criteria . . . .
12.6.6 Further Improvements on Watukushay FE . . . . . . . . .
Making a Better Version Of Watukushay Experts . . . . . . . . .
More Watukushay Experts in Asirikuy . . . . . . . . . . . . . . .
96
98
100
101
101
102
105
109
113
115
117
118
118
118
121
123
126
129
129
130
134
CONTENTS
Remember, there are bold and old traders but there are no old bold traders...
1 GETTING STARTED
1 Getting Started
1.1 Introduction
When I first started trading the forex market a few years ago I quickly came to
the conclusion that manual trading was far too cumbersome. Trading by myself
quickly slaved me to the screen of my computer making my stress level rise and
my quality of life drop. Certainly, there had to be a solution to my problem. After
searching on the Internet I found automated trading. That was the first time that the
world of forex automated trading opened its doors to me, I was amazed at what
could be done and dreaming of what could be achieved. Little did I know that this
journey through the world of expert advisors and automated trading would prove
to be so challenging.
Today I can say that getting to where I am now took a big toll on both my pocket
and my mind. I was once where you are now and I can tell you, I know the things
that are going through your mind, I know all your doubts and your questions. You
have probably already spent some or a lot of money on automated systems that
dont deliver, on experts that have wiped your live accounts, you have probably
wondered if this thing of trading automatically is really profitable. My objective
with this ebook is to answer as many of these questions as I possibly can. I want
to ensure that retail traders like you and me who are beginning their journey in
automated trading as well as those who are more experienced but still have many
questions can profit from the forex market by using automated trading techniques.
Within this ebook you will find a condensate of my experience using and evaluating forex automated trading systems. I will discuss with you what makes and
what breaks automated trading systems, how you evaluate trading systems, the
common flaws of commercial trading systems and many more topics that are of a
paramount interest to anyone who really wants to profit from automated trading.
Will it be easy ? No, it will not. Will it be impossible ? No, it will not. Moreover,
my ebook will try to get you started with your first tested and reliable free automated trading system so that you can start experiencing the benefits that certainly
can be achieved with automated trading systems.
It is my greatest hope that after reading my ebook on automated trading you
will have a much clearer understanding of the whole world of expert advisors and
that you will stop falling into the tricks and traps that commercial expert advisors
7
1 GETTING STARTED
set for you (either with or without their intent). I am certain that even though
reading my ebook will not make you a supreme expert on the subject it will serve
as a solid starting point to start making real profits with automated trading systems.
1.2 Disclaimer
Even though all the results and discussions within this ebook are presented in
good faith it is important to note that the contents do not constitute any type of
investment advice. The contents of this ebook are the sole opinions of the author.
The reader should understand this as well as the risks involved in trading the
foreign exchange market which is one of the most volatile and leveraged. The
author is NOT affiliated with any of the EA creators or EA programs mentioned
through the ebook. The author does NOT receive a commission of ANY type
neither to credit or discredit any of these experts. The evaluation of these programs
is done within the criteria of the author.
1 GETTING STARTED
heard 90% of retail traders lose their money in the forex market. Do you think
that buying a set and forget system for 100 USD that another 10,000 traders are
using will give you an edge ? I am sorry, as you may have suspected, it does NOT.
Be willing to do the WORK. Now that you have accepted that automated trading is NOT an easy task (I will explain this in great detail on the rest of the ebook)
you now have to promise yourself that you will do the work that is necessary to
become profitable in the world of automated trading. What does it involve ? The
first step is to read this ebook and soak in all the information you can. The next
step is to follow the advice I give through the ebook to help you become profitable. Will it involve learning to trade manually ? YES. Will it make you learn
how to program ? Probably YES. Will it take you a lot of time and a lot of sweat
? YES. You may have guessed by now that in order to be a successful trader using
automated trading systems you need an edge. My ebook will not give you this
edge by itself but it will guide you in a path so that you may get it yourself. You
know ? It is far easier to get somewhere when you have a map !
If you are not willing to follow the steps I outlined above, please stop reading
this ebook now. If you thought you could make a living using automated trading
by not doing anything I will have to disappoint you, you will not succeed. Trading
with automated systems in the forex market is not something for anyone and this
may not be a field you can succeed in. However I guess that if you bought my
ebook, you are willing to make an effort an finally see the light at the end of the
losing equity tunnel !
the use of an automated trading system are different than those experienced when
trading manually but they can be as or even more destructive (more on this later).
They can be used as black boxes ! This is a great disadvantage of automated
trading systems because it means that a person who has no idea of how a system
actually works can load it on a trading platform and make it trade. What you get
then is someone who does not understand what the system does or if it is profitable
or not running a system on their computer. This of course is the area commercial
expert advisor sellers exploit and an area you should be specially careful about. If
there is something I have learned during my years of trading it is, do NOT trade
any automated trading system you do NOT fully understand.
Expert advisor testing can be unreliable. This is a huge area of interest and
something I have been asked several times by my web sites visitors and customers. A great problem arises when you combine the unreliability of some of the
tests with the fact that black boxes can be sold. What you get is people buying
systems that they think will perform great only to find out that their accounts get
wiped out. (we will get much deeper into the testing of expert advisors later).
This sums up the main disadvantages and weak points of automated trading
systems. Through the rest of this ebook you will get a lot more of information on
these characteristics as well as how we can get around them to find and trade with
profitable expert advisors.
has made you 50% profit on your account during the past three months. What
would you do ? most people will continue to run this system as the system is
making money. Well, if that was me, I would shut it down immediately ! That
is because I know that a 50% profit demands a high market exposure and trading
such a system at that risk level is simply greedy. The opposite also applies. What
would you do if you have been trading a system for 6 months and it has produced
a 2% constant draw down every month ? Do you continue running it or do you
stop it ? Well, what do the tests tell you ? Do you expect this draw down ? Many
profitable trading systems have extended periods of draw down before long trend
catching moves (take the turtle system for example). As you can see, many people
would just stop trading the ea out of fear.
Fear and greed, in automated trading and in manual trading are a mere consequence of IGNORANCE. If you know your trading systems and you know the
market, you know what to expect and you also know when you are becoming either greedy with your profits or scared with your loses. This is why it is extremely
hard for most people to trade profitable automated trading systems, because these
systems generally trigger the fear part more and are therefore considered hard
to trade because the trader needs to continue trading despite of several continued loses. On the other hand, unprofitable systems usually trigger the other side,
something which makes them a lot more dangerous. Many commercial unprofitable systems usually generate a lot of short term wins which trigger the greedy
side of the trader and make him or her continue to trade the system until it wipes
them out. Now you can see why so many people lose in forex using automated
trading systems ? It starts from here.
13
You should then have in mind that trading an expert advisor successfully requires as much knowledge as it is needed for trading in a successful way manually.
As I said earlier on the ebook, the road to success with an EA is not easy, even
if the EA was already programmed you require this knowledge in order to know
if the ea is really fit to trade the instrument you are going to use it on. How do
you know if the system will work for you in the long term ? Only your knowledge of the given instrument coupled with the testing (which will be covered in
a subsequent section) that has to be done are likely to shine any light into this
problem.
14
15
16
You should have already noticed by now that the distinction between a profitable and an unprofitable trading system is not so straightforward, a very careful
examination of the trading system is required as said above, in order to tell an
unprofitable trading system from a profitable one. To help regular traders examine a trading system and determine if it has the potential to be profitable in the
long term I have prepared the following check list. Please make sure you read
the whole ebook before using it on a trading system as the following sections will
shed a lot of light into the different items mentioned below.
Does the trading system use a higher timeframe ? (greater than or 60 min)
Is the Risk to Reward ratio equal to or lower than 2 ?
Are the SL, TP and TL calculated dynamically ?
Is lot size calculated dynamically ?
Is the system based in a trend following strategy ?
Does the system have any type of filter for non trending periods ?
Is the largest profit 4 times higher than the largest loss ?
Is backtesting from 2000 to 2009 linear and profitable (like the graph showed
above) ?
Is there any live or forward testing that proves consistency with backtesting
?
Please note that a linear increase, does NOT mean that the system takes profit
in a straight line but that global equity growth resembles a line, like on the graph
shown below. A system that has an equity curve that looks like a straight line is
NOT good, this usually means that the risk to reward ratio of the system is VERY
HIGH or that losing positions are NEVER being closed.
17
If you answered yes to all of the above questions, then your system is likely
a long term profitable trading system. If you did not then you need to check if
the strategy fulfills the criteria. If you answered no to most of the above questions
then your system is probably NOT long term profitable and is probably just a short
term profitable trading system. Please note that it is VITAL that the answer to the
last two questions be YES for a system to be long term profitable. If the system
cannot be backtested (because it uses several currencies, etc), you would need at
least 3 years of forward testing to say anything about its profitability. For that
reason I usually limit my trading to systems that can be reliably backtested on a
single currency.
exposure. A similar thing happens in the forex market, the fact that a system
made 20% for three months just means that it went lucky and has an over the top
market exposure. Hopefully after reading this you will never fall again for this
false and absurd claims !
4.6 How much Draw Down can I expect from a profitable strategy ?
As I said earlier in my section about market exposure, maximum draw downs are
usually 1/5 to 1/2 of your yearly profits. In order to be safe I always consider the
worst possible case which is a 1/2 of yearly profits draw down. Being pessimistic
guarantees that you will do as much as you can to preserve your equity while
having realistic and achievable profit expectations.
In the case above, for example, a trading system making 100% a year would
mean a maximum draw down of 50%. Is this something you can tolerate ? If this
21
is something you are not able to tolerate then you need to tone down your risk
settings until you reach a draw down level you feel sufficiently comfortable with.
For example, you may settle for a 50% yearly profit with a 25% maximum draw
down. Your draw down could probably be lower but you always need to consider
the worst possible case in the event that it happens (and eventually it will).
This is just a small glimpse of the values that I know are achievable using
automated trading systems, however you should determine the draw down and
profit potentials of your profitable automated trading system by backtesting (after
you confirm through live testing that the expert backtests similarly to how it trades
in the real market).
22
5 TYPES OF STRATEGIES
5 Types of Strategies
5.1 Characteristics of Unprofitable Strategies
Amongst the different trading strategies that can be used in an automated trading system we know for certain that several strategies have smaller possibilities
of working than others. Most certainly, I know that most unprofitable strategies
share some characteristics that make them easy to identify and eliminate from
your trading portfolio. If you find any strategy that has any of the characteristics
outlined below, then it is very probable that this strategy will most likely NOT
work in the long run. These strategies may generate juicy short term profits which
make novice traders praise them as profitable and holy grails but these strategies
all eventually wipe their accounts out.
5.1.1 The Risk to Reward Ratio
The risk to reward ratio of a trading strategy is defined as the amount of dollars
risked for every dollar won. For example, if on one trade I risk 2 dollars to make 3
then my risk to reward ratio would be 2/3 or 0.66, this means that for every dollar
I make I am risking only 0.66 dollars. Commercial expert advisor sellers quickly
realized that having large risk to reward ratios guaranteed test results with better
success. As you may see, it is much easier to reach a certain take profit value if
your stop loss is further away (this is a consequence of the mean reversion theory).
Market Reversion Theory : This theory states that price is bound to reach again a price
level it has reached in the past in the near future. This means that if for example, the
EUR/USD is at 1.3657 and then goes to 1.3660 it is bound to retouch the 1.3657 level.
Because of this reason, the smaller a takeprofit and the larger the stop loss the easier the
take profit will be reached
This is the reason why commercial system developers started to use huge risk
to reward ratios. The main problem with using such high risk to reward ratios is
that a lot of money is risked for a little so a single loss usually wipes out many
winners. For example, on a 10 risk to reward ratio, it takes 10 wins to overcome
a single lose. With this type of systems you will win most of the time (more
than 90% of the time) but this will not be enough for your to be profitable. So
you should NOT look at the winning percentage of an EA as a means to estimate
23
5 TYPES OF STRATEGIES
This is of course a very good reason why profitable trading systems are much
harder to find than commercial systems with high risk to reward ratios. Almost
any strategy you can think of can be made profitable in the short term by increasing
the risk to reward ratio while strategies that have risk to reward ratios lower than
one and retain profits are extremely hard to come by. So when you are looking for
a trading system, always look for risk to reward ratios lower than one, the lower
the better. Systems with risk to reward ratios higher than 3 are very likely to be
unprofitable in the long term so stay away from this type of strategies.
5.1.2 The Money Management
A very important aspect of every trading strategy that is usually neglected by
most people that trade automated trading systems is the money management. I
cannot tell you how many expert advisors I have seen that use a fixed lot size or
a percentage of equity even though this two money management approaches are
bound to make their strategy unprofitable or breakeven in the long term. Money
management is extremely important and it CAN make the difference. What you
should do with your money management is to try it to make you the same amount
of money under any set of market conditions. The problem with a fixed Lot size
or a lot size based in equity is that they ignore the market completely. I put it this
way, would you buy the same amount of stocks if we where in a rally or in the
middle of a market crisis ? Probably not ! The same thing happens in the forex
24
5 TYPES OF STRATEGIES
market, your lot sizing should adjust to the market in order to make your strategy
more adaptable to changing market conditions.
Now, there are certainly ways that are not beneficial to money management
(like fixed lot size or trading a percentage of equity) but there are money management schemes that are a definite no no and are SURE to eventually wipe your
account out. Any strategy that increases lot sizes with loses is BOUND to cause
this. For example, a strategy that doubles lot sizes after every loss (called a Martingale strategy) WILL wipe your account. No matter how many times someone
comes out with a Martingale EA that they say wont wipe your account, it eventually WILL. A martingale strategy is a type of strategy that can show you year
long back, forward and live testing results that are profitable and then wipe your
account the next week. When you see a Martingale or a system that increases
lot sizes in anyway, run ! These strategies will end up with your account being
wiped out. If you have an ea with a fixed Lot size or account percentage based lot
size, change it for a volatility adjusted lot size and you are bound to increase your
systems reliability by a big percentage.
5.1.3 Fixed Orders
After years of testing many different testing systems and coming to learn the trading systems of successful traders I discovered something all of them had in common that all other unprofitable trading systems failed to have. All the long term
profitable trading systems I have known up until now have dynamic Stop loss
(SL), take profit (TP) or trailing stop (TL) values. This means that the systems do
not assign a fixed pip size to these values but the values are dynamically assigned
based on another criteria. This criteria can be volatility, a week low, a resistance
level, etc. The few automated trading systems I know that have long term profitability use dynamic SL, TP and TL. The reason why this makes systems more
profitable than using fixed values is the same reason as why dynamic lot sizing
works better than fixed lot sizes. When you have your orders changing according to the market, your positions are adjusted so that you always get the most out
of market moves. For example, (hypothetically) if the GBP/USD trended always
around 150% of its ATR value then you would constantly get out too early or
too late when using a fixed TP, unless your TP matched the 150% ATR, on the
contrary, if you had an ATR adjusted TP, the value would be reached every time
and you would get a larger profit and a much better and reliable system.
25
5 TYPES OF STRATEGIES
The ATR or Average True Range Indicator was developed by Welles Wilder and its
concept as a money management adaptive tools was developed by the creators of the
Turtle Trading system as a way to control position sizing and order placing. The Average
true Range is a useful indicator to adjust your TP, SL or TL values against market volatility
5 TYPES OF STRATEGIES
popular Turtle trading system. This also reinforces the hypothesis of not using
fixed SL and TP and even more it further gives the idea of not having a TP at
all and exiting either on an alternate exit criteria such as a price, indicator or TL
based one.
For example some profitable trading systems use a TL as a dynamic exit criteria while others such as the turtle trading system or the 4 week breakout system
use certain day length high or low breakout in order to exit trades. Both strategies can be profitable depending on the actual trading system. Other exits such
as indicator based exits in the gods gift ATR system also prove to be incredibly
beneficial when cutting loses short as the system can save itself from reaching the
value of SL on many cases while keeping profitable trades alive to reach higher
values.
5.2.3 Dynamic Volatility Adjusted Money Management
Another key aspect of profitable trading systems is having a money management
system that can control the lot size traded in a way that it can adapt to the evolving market. Having a volatility adjusted money management system can help your
trading strategy maintain its profit through a large variety of different market conditions. This also ensures that profits during various volatility levels stay constant
something which smooths out equity curves and guarantees a much more homogeneous return from the trading system. There can be profitable systems with no
dynamic lot sizing but their profit potential increases or decreases as a function of
market volatility.
5.2.4 The Risk to Reward Ratio
Since long term profitable trading systems are expected to take advantage of inherent market characteristics rather than market randomness it is usually expected
for these systems to have a low risk to reward ratio. All the systems I have seen
have risk to reward ratios of 3 or lower with the most profitable systems having
risk to reward ratios of even 0.2 with 5 losing trades equaling one average profitable trade. These systems usually also have very large trend following profitable
trades which make the largest profitable trade even 20 times larger than the average losing trade. Systems that trade with no TP and an SL usually benefit from
this as the amount of capital you are willing to lose is fixed but the amount of
capital you can win is unlimited.
27
6.1 Backtesting
The first and one of the most important tests that has to be done on an expert
advisor is a backtest. These tests are done with historical data and are a way to
simulate how your expert advisor might have performed in the past. They also let
you know if your expert advisors logic is working the right way or if the code
needs to be corrected in order to address trading problems. Backtesting however
has several problems related to the way in which the simulations are carried out.
Did you know ? Running high quality backtests is essential for accurate EA evaluation of
trading systems that do NOT exploit the outlined backtester faults shown below. A video
is available on the Asirikuy which explains to you exaclty how to achieve 90% modeling
quality backtests on the metatrader 4 platforms strategy tester.
Since the metatrader platform does not store ANY tick data but only one
minute candle data and volume data there is no way in which the expert can accurately know how the data within a one minute candle evolved (the strategy tester
guesses how price moved from the one minute candle open to the one minute
closing price). The metatrader 4 strategy tester does simple random data interpolations along the open and close of the candle trying to fill the whole volume
assigned to that particular minute. What happens is that if you have a trade that
was opened and has either its TP or its SL within a one minute candle then the
result of the trade has no meaning because the nature of the ticks is not accurately
simulated by the backtesting. This is the reason why MANY systems do NOT
give reliable results when backtested. As a guide, backtesting results of systems
with the following characteristics should NOT be taken into account :
28
Did you know ? ALL brokers use Metaquotes historical data to run 10 year backtests so
running backtests on different brokers makes NO sense. However, backtests should only
be run on FIVE digit brokers since the 4 digit broker data set is UNRELIABLE with 1 pip
daily candles, Sunday candles, gaps in data, etc. If you want to have good backtests use
the Alpari platform to run your backtests with the 5 digit data set. .
Finding a system that fulfills all the above characteristic and succeeds in the
backtest is VERY DIFFICULT, it takes a lot of trading knowledge and skill to design a trading system that can in fact tackle an inherent characteristic of the market
for such a long period of time. However, simple breakout trend following systems
with simple filters have shown to be very good trading systems even though they
are not popular (because they dont offer short term profits or trade ten times a
day).
30
pear in backtesting). Always make sure you test your long term profitable systems
for AT LEAST 2 years, this is enough to really ensure backtesting consistency and
is what I would consider an ideal initial proof about the real profitability of a
trading system. As a minimum to believe that an EA sold commercially is long
term profitable we would need an 8-10 year period backtesting with a 1 year period
of live testing that can validate the backtest, the live test should also have an investor password and login to confirm the veracity of the claims. ANY TRADING
SYSTEM THAT DOES NOT HAVE THIS SHOULD NOT BE CONSIDERED
PROVEN. A live test of at least 4 months that matches backtesting would be a
BEAR MINIMUM to even consider testing the system.
As you can see, the information you can really obtain from testing is limited
and you CANNOT substitute testing for thinking. Many people try to get a bunch
of indicator signals together and test them with the hope that the system will be
profitable in testing. The truth is that you should THINK FIRST program second.
If your system has been developed with long term profitability in mind with a
sound trading strategy, then testing is just he icing in the cake.
6.3 Comparing Live and Backtesting. Is the expert really profitable or NOT ?
If an expert advisor performs well in backtesting from 1999 and is then tested
against live trading the backtesting of the live trading period should be done in
order to compare the results of both trading periods. Often results will differ
because the backtesting and the live testing data feeds are different. However,
this still does not mean that results are NOT comparable. What you should look
for is for both live testing and backtesting results to show the exact same trading
patterns. That is, winning and losing periods should be of similar length and
intensity with both tests reaching similar results. An example of this is shown
below.
31
The above image shows a comparison between LIVE and backtesting results
for the gods gift ATR expert advisor. You should notice how the expert advisor
behaves globally the same around all the marked periods. For example, periods
1, 5 and 7 are losing while periods 2 and 4 are winning. Although the tests are
not carbon copies because of the broker difference between metaquotes and fxclearing, it is still clear that the gods gift ATR took similar trades in similar time
periods. A closer look reveals that some trades are lost or won by a few differences in pips while others are not taken because the indicators did not reach the
needed levels. However, this is a perfect example of what a trading comparison
between backtesting and live testing is done.
Please see that the EA is long term profitable even though the results of the
BACK and LIVE testing for this period of time IS NOT. The logic is pretty simple.
The EA is profitable in backtesting from 1999. We know however that the EA has
losing periods which can last for even several months. What we want to know
is simply: Is the backtesting really accurate ? So if the live tests say it IS then
we can suppose that the EA was profitable since 1999 and hence, we are talking
about a long term profitable trading system. Short term profitability results mean
NOTHING. Please say that out loud !
As a matter of fact, a comparison of a much longer period of back/live testing
consistency from March 2008 to Decemeber 2009 reveals that the Gods Gift ATR
still maintains its live/back testing consistency (live and backtesting results are
extrapolated to 100K to make them directly comparable). The image below shows
you the comparison between live and backtesting for this period of time. You can
see that live testing is even more profitable than the backtesting results obtained
32
for this EA. Please take into account that trades do not perfectly align since the
charts are plotted as Trade Number Vs Balance and the trade number for both
tests does not perfectly align since there are differences between the number of
trades taken on both tests. However notice how globally the same equity highs
are achiever as a function of time and the final equity achieved and the behavior
amongst the different market periods is similar. This longer testing period does
show the experts long term profitability.
34
35
37
38
8.2 The Gods Gift ATR - A Long Term Profitable Trading System
8.2.1 The Experts Logic
The Gods gift expert advisor follows a pretty complicated logic with 15 parameters determined for market entries and 10 parameters designated for the closing
of orders. Mainly, the expert advisor reacts to three different types of indicators.
The first are volatility indicators in the form of Bollinger Bands and the Keltner Channel indicators, the second are oscillators in the form of several different
stochastics and the Wadahh Attar Explosion indicators and the third are lagging
indicators in the form of exponential moving averages. What we are looking for
with this expert is to enter the market when we are at the start of a new market
cycle. For this we want long and medium term stochastics to be at the opposite
extreme of the short term stochastic. We also want price to be inside the Bollinger
bands and keltner channels and we also want price to be below or above the slow
ema. The experts logic may not sound too familiar to most new traders at first
but a careful study of the rules and the indicators shows why this expert advisor is
geared towards long term profitability. We aim for the start of big market moves.
As many of my customers and website readers have asked me I have decided to
extend the explanation of both the logic, variables and criteria in order to make it
far more understandable. The gods gift expert advisor aims at entering trades
when the market retraces from a trend. The main idea is that the short term
stochastics should show an inverted direction while the long term trends should
show the right direction of the trend. This is the way in which the expert advisor
determines that it is within a retracement of a larger market movement. The fact
that price must remain within the Bollinger band and Keltner Channel indicators
just ensures that the movements are true retracements. If the market movement
is outside the volatility indicators then the movement is most likely a price spike
and not a true market retracement. This entering of positions within a retracement
ensures that the gods gift catches large market moves.
I will now try to explain the systems logic and variables so that traders who
want to trade this great system will have a better idea of what the system is doing
and what they can an cannot expect from its logic.
39
40
41
43
1000 USD of equity without the Risk variable setting higher than 5. This settings should, as per the already obtained results, give us a profit of around 50% a
year with a draw down never exceeding 30%. Bear in mind that this expert can
have many several consecutive loses (as many as 25) and then one very big profitable trade. You should wait for at least 6 months of forward testing to actually
see a good spectrum of results from the expert. As you can see on the tests, there
are periods in which the expert makes 20-30% profits followed by flat or slightly
losing periods which end up with another large profitable trade. The logic followed by this expert advisor has shown to be reliable and I can say I trust it and
use it on my personal live accounts. However, you should as always understand
that this does not constitute any investment advice and that past performance is at
the most an indicative but not a guarantee of future results.
44
A : The alerts are generated by the indicators and in no way represent the
experts logic. You should completely ignore these alerts, do not execute any
trades as these alerts do NOT consitute trading signals of the EA and are NOT in
anyway related to the trading logic, they are just alerts generated independently
by the indicators used by the EA. The EA is a totally automated system and will
execute and manage trades when the market meets its entry logic.
Q : Can the gods gift ATR EA be traded with other experts ?
A: Yes, just make sure you set the magic number of the EA to a unique integer
different to that of other systems.
Q : Can the gods gift ATR EA be traded on several pairs ?
A : Yes, the gods gift ATR has been optimized to trade the EUR/USD, the
USD/JPY and the GBP/USD. However, each one of these currencies must be
tested on a SEPARATE account and each one has to be traded with its OWN
OPTIMIZED SETTINGS. These settings are provided as set files with the forex
automated trading ebook support materials.
Q : How long will it take to see results ?
A : The gods gift EA can have draw down periods that can last for as long as
6 months so always trade the EA for at least 2 years before you decide anything.
Please remember that the forex market is NOT your 9 to 5 job. You do not get paid
every month and sometimes it may take a while to reap your rewards. This is a
characteristic of several profitable trading systems and something that experienced
traders have known for more than 20 years.
Q : Do I need a VPS to trade the gods gift ATR EA ?
A : YES ! A VPS or virtual private server is ALWAYS needed if you want to
trade the gods gift ATR EA in a reproducible, profitable and safe way.
Q : Does the EA comply with new NFA regulations ?
A : The EA actually does comply with NFA regulations and ECN brokers.
45
Q : Has all the work been done for me ? Do I set and forget the Gods gift ?
A : You should know by now that the answer to these questions is NO. The
gods gift ATR was developed with all the long term profitable concepts in mind
but it is apt to you to be able to grasp these concepts and trade the EA correctly.
Probably most of the people trading this EA will desist after the first 4 month
draw down because they failed to understand how the system worked. Please
remember that fear and greed play a VITAL part in automated trading and that the
understanding of both the code and the inner working of the expert advisor are the
only thing that can save you from undermining or overestimating the profitability
of the gods gift ATR.
Q : What Tests have been done with the gods gift EA ?
A:
Backtesting of the gods gift 7c from 1999 to 2007
One year forward testing of the gods gift 7c from 2007 to 2008
Backtesting of the gods gift ATR from 1999 to 2009
Optimization of parameters in backtesting for the EUR/USD, GBP/USD
and USD/JPY
Live testing on accounts owned by myself on the EUR/USD, GBP/USD and
USD/JPY (from 01 March 2009)
Independent live tests currently being carried on the USD/JPY and GBP/USD
Q : What broker should I use ?
A : Up until now the EA has been tested on FXDD, fxclearing and fxlite. I
would advice you choose a non US broker because of the absence of the new
NFA regulations regarding pending orders. The EA is fairly broker independent
and should show you similar results regardless of your broker. Please choose a
broker you feel comfortable with. The EA is unlikely to be much affected by
broker feeds and spreads because its main targets are long trend moves which do
46
NOT change. The stoploss of the EA is also big enough to avoid any potential
stop hunting made by the broker.
Q : The EA has been on the chart for a few days but there are not trades yet.
Is this ok ?
A : Since the gods gift ATR EA aims for high probability trades it does not
enter the market very often. This EA usually trades 2 or 3 times per week and
sometimes it does not trade even for one or two weeks depending on the overall
market conditions. Do NOT expect this EA to trade everyday or several times a
day. Only expect an average of 4 to 8 trades per month. However you should
check the Journal tab of your metatrader terminal to see if there are any errors
being generated by the EA. Errors can arise if you choose the wrong digit number
(set five_digit_broker to true if you have a five digit broker), if you choose the
wrong account type (setting mini_account to true if you dont have a 10,000 USD
contract size WILL cause problems) or if you fail to have adequate funding on
your account (you need at least 1000 USD to trade this EA with 100 USD with a
10,000 USD contract size being the BARE minimum).
Q : Do the indicators need to be on the charts ? Do I need to copy the indicators
? how do I install the expert advisor ?
A :The indicators do NOT need to be loaded on the charts since they are AUTOMATICALLY loaded by the EA once it starts to run. They do however need
to be copied to the /experts/indicators directory and compiled (just restart mt4) in
order for the EA to find them. You can also find a wealth of videos on youtube
and other websites about how to accurately install an expert advisor.
Q : Can the EA be traded on a different time frame ?
A : Maybe it can be done but I have NEVER tested the EA on a different
timeframe other than the one hour. It is therefore EXTREMELY recommended
to stay within this timeframe. Separate live and backtesting would be necessary
if you expect to trade the EA profitably on another timeframe. Personally I have
NOT found any set of results that are profitable from 1999 using anything but the
one hour chart.
47
48
Even though not all of our losing trades derive from this type of scenario, all
of them arise from the EA thinking the market is trending when it is actually doing
another type of behavior. The EA also fails when the market begins deep retracement movements. However, the nature of these loses is pretty much limited and
it is the market exposure price that has to be paid in order to have the possibility
to catch the large winning trades the gods gift ATR has the potential to actually
catch.
8.4.2 Winning Trades
After watching the gods gift ATR EA trade live for several months we have seen
several great trend catching moves when the EA accurately entered the market
on a small retracement and then followed the market into profit efficiently. Most
of the time, the trailing stop and internal closing mechanism did a great job at
securing high amounts of possible profits. The EA can make roughly 5 to 10% of
its account size on each one of this great moves. In the following pictures you can
see some trend following trades taken on the GBP/USD and USD/JPY accounts.
You can see that the tighter closing criteria in the USD/JPY did not prevent it from
following this trend which effectively was the equivalent of at least 10 consecutive
average loses of the USD/JPY account.
It is worth noting that we have just seen medium term trend following success.
We have still failed to see the real potential of this EA in live testing as backtesting
49
predicts we should see (at least in the GBP/USD and EUR/USD instances with
lighter closing criteria) trend following trades which can increase equity by even
30% in a single trade. The EUR/USD had such a trade almost half a month after
it started trading but sadly I could not take a screen shot of the trade because of a
VPS restart which was necessary to update the system. Since we now know this
EA to be consistent between back and live testing we should expect to see some
very profitable trades of this nature as soon as the market starts to trend strongly.
This large winning trades are NOT expected to happen very/ often and should
be expected once or twice every year with much smaller (5-10%) winning trades
happening every 2 or 3 months. Please be very careful when you choose your
account type as choosing the wrong contract size (if you set mini_account to true
but your contract size is NOT 10,000 USD) or if your accounts size is ust too low
for your risk setting (like having a 500 USD account with Risk = 1 ) will cause
the EA to miscalculate your lot size and generate you a much larger risk. Please
always start accounts with at least 1000 USD to avoid this problem or any other
issues related with money management.
50
systems based on statistical principles I have always found these empirircal observations and suggestions to be misleading at best. For this reason I decided to
develop an adequate criteria regarding testing and evaluation so that I could know
how much testing could be considered enough as to better understand how I
should decide and trade my systems.
After dedicating a lot of time to this problem I finally concluded that any
system needs at least a period of 5 years of evaluation to get a good idea about its
trading characteristics. A period of 5 years is statistically significant because it is
representative of a large long term volatility cycle in the market. If you take any
profitable system and analyze it within a 5 year period you will find that it reaches
a new equity high while unprofitable systems are bound to wipe accounts within
this period of time. Since in Metatrader 4 we have enough reliable history to do
evaluations from the year 2000 to present it is viable to do 10 year long simulations
to measure the performance of our trading systems and determine their long term
characteristics.
When you develop your trading systems it is important that you do all testing
through a 10 year period on the currency pair of your choice. Doing this extensive
testing will allow you to see how your system behaves around different market
conditions and how it trades under a statistically relevant period of time. You
wont get fooled my small draw down and profit periods and you will be able to
get a true perspective about the quality and characteristics of your strategy.
The image above shows you what I considered here an ideal trading setup and
54
when I would have ideally wanted to enter the market. Notice how this entry
would have put us in a place where all movement would have been towards the
favorable movement after the trade was entered. The tricky thing now is to device
an entry logic that would have put us in that place that stores the fundamental characteristics of the trading setup we want to achieve. The technique can be simply
price based or it can use an indicator that is able to convey the basic information
regarding our entry setup (both cases are shown on the images given below). The
important thing here is to remember that you have to capture the setup you want
that will let you enter your trade right where you want.
55
After we finish the development of our initial entry logic that will let us get
into the exact trading setups we want, it is time to see if this trading setups lead
to statistically meaningful results over the long term. This takes us to our next
topic which is the Mathematical Expectancy of entries, how you can measure it
and how it will allow you to accurately and quantitatively measure the quality of
your entry logic.
9.4.2 The Mathematical Expectancy of Entries
Perhaps the chief reason why most people fail with their attempts to create successful trading systems is rooted in the fact that they never do an adequate evalution regarding the potential of their entry logic. If the entry logic of your system
does not lead with statistically significant results into favorable territory then your
trading system is bound to be unsuccessful regardless of how much effort your
put into your exit logic or money management. This is exactly the moment where
unsound trading tactics such as the use of very large risk to reward ratios and
Martingale systems arise, the failure to get a good entry logic makes people attempt to improve their trading system by using artifical methods such as the
above mentioned unsound trading tactics that tend to improve short term results
but eventually the market cashes on the systems exposure and wipes the accounts.
56
However there is a simple way in which you can evaluate the quality of your
entry logic and measure its potential before comitting yourself to the design of a
full trading tactic based on your initial entry logic developments. This study called
mathematical expectancy entry analysis allows you to calculate the maximum
average moves into profitable and unprofitable territory after a set number of bars
of a given entry logic on different time frames. This analysis can be done using
the mathematical expectancy analysis tool located within the Asirikuy systems
section. You should watch the practical and theoretical mathematical expectancy
analysis videos included within the Asirikuy training section to learn more about
how this analysis is done in practice and how you can do it for your own entry
logic.
Once finished, the analysis will give us a lot of vital information about our
entry logic, it will tell you if the mathematical expectancy of the system is positive
and on what time frame and along what number of bars it is more positive. The
actual amounts of the maximum averages will also allow you to design the exit
logic of your system since it will allow you to place dynamic SL and TP values
based on the 14-daily ATR as a first approach. This study will also allow you to
see if your system actually captures the movements you wanted or if it is better
suited at capturing shorter/larger movements or moves on other time frames.
For example if you do a mathematical expectancy of your system and your
maximum movements into postivie territory for longs and shorts are 65 and 70%
and the moves into unprofitable territory are 50 and 60% of the 14-day ATR for
a 100 period analysis then your system has a positive mathematical expectancy
on entries of +15 and +10% showing you that your entry leads into profitable
territory with statistically greater favorability. You might then select initial SL
and TP values of 65% since this value leads into your TP in average while the
average of the move into losing territory is smaller (60%) meaning that it wont
be reached in average.
If the mathematical expectancy analysis of your strategy is negative, do not
despair. You will often see that unprofitable systems have unsymmetrical mathematical expectancy measurements (for example longs have a positive expectancy
while shorts do not) something that means that your system has the same potential
as a random entry. Systems that have negative mathematical expectancy on both
values can be reverted to arrive to a system with potential while systems that have
unsymmetrical values simply have no potential as I explained before. If your sys57
tem is unsymmetrical, go back to the drawing board, reselect your ideal case, look
into other options, look into the ideal setup of your system and come up with other
entry choices. If your system has a positive mathematical expectancy on entries
then it is time to start the hardest part of its development :o).
9.4.3 A Warning About Entries
I have frequently noticed that people tend to obcess with entries when developing
trading systems and that this often leads to systems that have extremely complex
entry logic sets that still dont lead to systems that have any long term potential.
Failure to do the above mathematical expectancy analysis and a lack of focus in
the developing of adequate money management (lot sizing plus exit logic) tactics
makes this problem very common and largely responsible for the failure of most
community developed trading systems available online. Often you will notice
that on forums systems become more complex with time often starting with entry
filter restrictions and usually evolving and ending with such things as recovery
modes, Martingale implementations, etc. My advice here is simple, focus on
the development of simple entries with a positive mathematical expectancy and
then put the majority of your effort in the development of the money management
part of your strategy. Do not make your entries overly complex in an attempt to
improve your system !
58
provides us with a great tool we can use so that our trading systems money
management can change as the market starts to evolve.
9.5.2 Coming Up with an Exit Logic
What separates good from excellent trading system developers is the ability to
come up with exit mechanisms that are able to cut losing trades short and let profitable trades reach their full potential. The development of adequate exit mechanisms is necessary for a system to reach its full trading potential and this can
definitely only be done through the analysis of 10 year backtests. Of course, in
order to backtest your system you first need an initial money management implementation that will allow you to start to do some analysis and make improvements.
Since you have done a mathematical expectancy analysis of your entry the values
given there will allow you to have a good idea of what ATR% adjusted SL and TP
values you could use while you can use a % balance adjusted loss against your SL
so that you risk a fixed percentage of equity on each losing trade.
What comes after you do this is perhaps the hardest part of system development, the creation of exit mechanisms. The first thing you need to do in order to
achieve this is to run a ten year backtest and go through all the trades within the
test. The trades we are most interested in are trades that go into losing territory
without touching profiable ground, these trades are the most unfavorable and they
are the ones we need to counter the most. Once you pin point ALL these trades
within your 10 year backtest you should take screenshots of each one and analyze them to see what they have in common and what makes them different from
profitable trades. The idea here is that you should device an exit mechanism that
allows these trades to be cut short without affecting other trades which did turn
out profitable. Sadly there is no mechanical way to develop exit mechanisms since
each different system has different exit mechanisms that may suite it better. What
you need to clearly understand is that the idea here is to exit losing trades quickly
and to let profitable trades reach their highest potential.
Of course, another important aspect is to determine when profitable trades
significantly lose their probability to reach their full potential. You might want to
analyze trades that go significantly into profitable territory and then reach the SL
so that you might find out what they have in common and what signals that a
trade which was entered is no longer likely to reach its profit targets. These exits
are also very important since they allow us to exit trades when the setup that first
60
61
62
63
64
65
The image above shows us the appearance of different draw down periods
along a 10 year backtest from Jan 2000 to Jan 2010 on the GBP/USD using the
settings of the FXDD live account within Asirikuys test section (only Risk was
changed to 1 from 3). The image shows us that the largest draw down period began
in 2000 and amounted to a draw down level of 6.58%, a draw down period which
lasted all the way until 2004 when the system managed to achieve its next equity
high. This means that the system had a draw down period of 3 years showing us
that this could also happen in the future. However it is worth noting that this draw
down period was controlled and the EA was able to cut loses short during this
whole time when the systems trading did not achieve new equity highs. After
this draw down period ended the system more than compensated for the three
years of loses with the achievement of new equity highs every year until the end
of the test.
66
The last image shows us the monthly profit of the EA for the 10 year period,
we can see that unprofitable months are almost as frequent as profitable months
but the average profitability of profitable months is almost twice as large. This is
in line with the systems trading tactic that waits for large trades that amount to
a great majority of the systems trading profits. Even though trades taken by the
Gods Gift ATR do not frequently reach their highest potential those that do make
up for the losses taken by the EA during unprofitable periods.
A person trying to trade this EA without the above information would easily desist from trading it after a break even year while a person with the above
information understands the systems trading tactic and KNOWS that the systems characteristics predict periods of extensive draw down which are followed
by sharp profitable periods that make up for all the waiting time. However this
does NOT mean that systems should be traded merely on faith since a system can
become too risky to be traded, reason why we always need to have a worst case
scenario that tells us if we should or if we should not continue to trade a given
strategy. Learning how to come up with this worst case scenarios will be the subject of the next sub-section. Part of why automated trading is extremely hard lies
in the fact that long term profitable systems are emotionally discouraging to trade
in the short or even medium term, reason why understanding is a HUGE part of
success with automated trading systems.
67
ing accurate draw down period analysis and worst-case scenario estimations will
be VITAL for your success as a currency trader, especially when dealing with
mechanical trading systems.
69
portfolio analysis.
Our analysis of portfolio profit and draw down figures is currently done using
Gabors draw down and profit analysis tool which allows you to load the 10 year
backtests you want to evaluate and choose an appropiate reset period. You should
watch the videos about this analysis tool as well as the SQL scrip and VBA macro
videos so that you get a better understanding of how this is done and how the actual
analysis within the tool is implemented to give us the best possible estimations of
historical portfolio profit and draw down targets.
71
a reliable source for people willing to learn all the things that have to go through
the process of building and making an automated trading system. Now please join
me on this exciting journey for expert advisor creation !
12.2 The hard part, deciding on the main logic of an automated trading system
In order to create an automated trading system we first need to understand what
composes an EA and what parameters we need to define in order to program one.
A trading system in general, to be automated, has to have the following minimal
features : An entry criteria, an exit criteria and a money management criteria.
That is, we must know how much to trade, when to trade it and how to trade it.
This section will focus on how you can decide what suites you best and what I
chose for the first EA of the Watukushay project. My idea with this is that you go
through all the same experience as I did creating this EA so I would be very glad
if you follow all the same steps I take and arrive at the same end product.
12.2.1 Where is our profit coming from ?
The first thing we need to look for when developing a profitable automated trading
system is where our profit is coming from. What fundamental characteristic of the
market are we going to exploit ? Up until now, the only characteristic I have found
a system can exploit profitably in the long term is a trend. I have not found any
other way to trade that can generate profits in the long run. This of course, is
based on all the facts I already explained about market randomness, etc. People
who are more interested in this subject should also research the concept of market
efficiency in particular, you should realize that in order for technical trading to be
profitable, the market must be inefficient to some degree, something which almost
certainly only happens with trends in the long run. The market quickly becomes
efficient to anything that could predict future prices in lower time frames making
long term profitable systems based on things like scalping, in fact, impossible. To
make it clear, the development of expert advisors I will focus on on this project
will be aimed only at trend following systems. Our objective will be to capture
trends and to follow as close as possible all the guidelines I highlighted earlier on
the ebook.
73
achieve a significant profit from the trends movements. This is a tricky part and
this is the part where most traders believe the actual gold is. Well, it is actually
not. Entry points in the forex market are totally irrelevant because anytime you
enter a position you have a chance of being profitable either way . The exits, on
the other hand, are vital because they determine whether you were profitable or
not on the trade you took. A rather common exercise when learning how to trade
the forex market is to flip a coin and enter a currency pair either long or short
depending on the result, then the trader decides how to actually handle the trade.
This is the most important thing you must know how to do. Just so that you can
follow the concept I would like you to try this for two weeks. At a fixed time each
day of the week, on the EUR/USD, enter a position either long or short according
to the results of a coin toss. Then decide how you will handle the trade, how much
will you trade and what conditions you will employ to exit the trade. You will
notice that handling exits is far more critical than handling entries.
12.2.4 Deciding on our first indicators
After deciding exactly what we are after, we now have to decide which indicators
we must use to achieve our designated entry strategy. What indicator will we use
to allow us to enter a trend after it has started but has not yet finished ? You should
think in an extremely basic fashion when dealing with these questions. A trading
system is far more accurate and easy to evaluate and understand when it is started
on a very simple basis and then elaborated towards a more complex type of system
(if this is at all necessary).
A very simple system that lets us within a trend after a certain time has passed
from its beginning is a moving average cross. A moving average is simply the
average of price calculated over a certain number of periods. A moving average
cross is simply defined as when the average calculated over a period changes from
being higher to being lower than the average from another period of time. It is
important to understand the logic behind using a moving average cross. What does
it mean ? When the average of price in a long period of time is, for example 10,
this means that 10 is the expected value of the instrument, if the average of price
over a smaller period is, for example 8, then this means that price is trading below
where it is expected to be traded. Certainly, depending on the market conditions,
two things can happen, if the market is just ranging, then price is bound to return
to its average value which is the accurate value of the instrument. However, if
the market is trending, then the moving average will move to lower values because
75
price is changing rapidly in relation to its long term average. When the average
of price on a shorter term crosses over the average of a longer term it means that,
if the market is going to trend, then we will get in at a good point. If it is not,
then we are going to lose as the market will try to return to its previous mean
value. The fact that this possibilities exist is what defines the market exposure of
this system. By taking the moving average cross as if it signaled a trend we are
exposing ourselves to the times in which is does not.
The longer the timeframe we use for the moving average, that is, the higher the
number of periods of the long term moving average, the more reliable the signals
will become but they will also become far more infrequent. But where do we start
? A good place to start would be at a 250 simple moving average cross against a
15 simple moving average cross. This is a system that has actually been studied
before academically to prove market inefficiencies in the forex market (this study
was done in 1985). Now, another important problem arises. What price will
we use to calculate the moving average ? It clearly depends on which bars your
going to trade on. You must keep in mind that the system must be backtesting
reliable which means that we must enter trades on a bar opening price, something
which will guarantee we will have no one minute interpolation errors on entries
(which is very important !). So there are mainly two options. You can either enter
trades based on the cross of two moving averages based on closing prices with
a 1 bar lag or enter trades on the same cross but based on moving averages that
use opening prices and then you could have no lag and enter the trade as soon as
the bar opens. Which strategy is better ? Truth be told, both of them are roughly
the same because the lag you save when you use opening prices you gain because
of the difference between both. Please note that you could tell the program to
use a moving average close with no lag and it will backtest without errors and
with billions in profit but that is only because the EA knows the closing price of a
current bar (it looks into the future) so we should always take into consideration
the actual logic of the things we are telling the computer. Please remember that
computer do not solve problems, they execute solutions.
For now we will not consider how to filter the aforementioned ranging trades
that will obviously cause a lot of loses in our present system. For now we will just
build a system based on a 15 SMA (simple moving average) cross over a 250
SMA. System rules in plain English would be enter a long when the 15 moving
average moves above the 250 moving average and enter a short when the reverse
happens. Now, for a computer, this language would just be too vain because
76
many things are not said. You should take into account that a computer needs
to know every detail about your system to execute it correctly, so a much better
rephrasing of this scenario would be if the 15 moving average calculated on
closing prices is less than the 250 moving average calculated on closing prices
two periods in the past and it is above the 250 moving average calculated on
closing prices one period in the past then enter a long, enter a short for the reverse
situation. A computer would definitely understand this because it is the logical
way of explaining it. The concept of cross is ambiguous and such a system
would not work because the value of a moving average can move above or below
the other one or many times within a single candle, in order to be completely sure
that the signals have been generated accurately and have no errors about it we
need to look into the past and check if a cross occurred on the candle before the
candle we are currently on because we need the cross to actually have happened.
There are thousands of crosses that happen while a bar is opened that you simply
do not see, we need to filter all this out and just keep the ones that DO happen.
12.2.5 Exiting a Trade
Now that we know how we are going to enter the market the hardest thing becomes
to decide the rest. How will we get out of the market now ? To answer this
question you need to actually think about several things. When do we want to
get out ? What is the cost of getting out when we want to ? Of course, we know
that we would like to get out of the trade when the maximum amount of profit
is reached (the trend runs out) and we can actually achieve that but then, what
is the cost of doing that ? If you want to catch the whole trend move you will
have to allow a lot of market exposure because you are opening possibilities. For
example, the market may retrace significantly along a trend so we would have to
get a large stoploss which would in some cases be touched, and this cases would
give as further loses than the profits we get from actually getting everything we
can. So we actually need to rephrase the question. When can I get out, so that I
am able to accumulate profits in the long run ? Much better ! The truth is that
we dont know the answer to this question and it is most likely something we will
have to find out by optimization. However, certainly we will need some sort of
adjustable system to get in and out of the market so that volatility changes dont
take a big toll on our profitability. For this reason we will use an adjustable ATR
Stoploss, Take profit and Trailing stop, programming all this into the EA will
allow us to see which one is the actual best strategy for our system. There are
other exit strategies that are adjusted with volatility implicitly such as exiting on
77
a slower moving average cross, for example, a 25 moving average. This strategy
is also valid and probably a combination of both of this should be the best in the
future but as Ive said, the optimizations we will run in the future will tell us this
in a much more explicit way. So keep in mind we will exit the market on ATR
adjusted stoploss (SL), take profit (TP) or trailing stop (TL).
12.2.6 Money Management
Probably this is MOST critical aspect of trading and where people fail the most. I
have seen hundreds of traders that have systems that actually have decent entries
but that have awful exits and money management (usually just a percentage of
equity) so they think that the problem is with their entry and they add a zillion
more indicators to try to filter every possible trade where they are failing out. This
is the WRONG approach. As you may have seen on my blog, it is actually easy
to make a system profitable by giving it the adequate conditioning. Money management plays a VITAL role and it does make the difference between a profitable
and an unprofitable trading system. For example, the turtle trading system, without the ATR adjusted money management wipes an entire account in less than 2
years when you try to backtest it but it turns profitable with this addition. Money
management is greatly underestimated and extremely important. You should also
take into account that trading x percent of equity is NOT money managing because money management takes into account THE MARKET and this strategies
completely ignore the market and just relies on account balance. A proper money
management system should take into account : the market, your equity and the risk
you want to take with the system. All of these THREE THINGS are completely
vital and any money management system cannot be called one if it ignores one
of them. For our trading system we will include a simple yet extremely effective
method of money management based on the ATR indicator which fits very well
with our previous choices. This ATR adjusted scenario is a very good choice when
there is not a very clear way of where to actually start looking. However there are
many alternatives to exits and money management, for an example of these you
would want to look into my GBP/JPY daily breakout system which uses a market
range defined by an hour breakout period as a measure of volatility with which it
calculates the exit strategy.
78
serves a great purpose as a way to develop the main logical base for our expert
advisors. This applet is located at the following web address : http://sufx.core.t3ism.net/ExpertAdvisorBuilder/ . We will use this tools to build the overall logic
code for our expert advisor and I will then explain all the different aspects of
the code as well as where, how and why to introduce the modifications we will
do in order to really adjust the expert to our needs. Building an expert this way
has several advantages over trying to teach people how to build this from zero.
The code will be already optimized against errors and it will be clean, polished
and very easy to modify. It is the perfect way for people to start building their
own indicator based expert advisors. During the next few pages we will use this
website so please go into it so that we may start our coding process.
12.3.2 Introducing the entry logic
Now we want to introduce the entry logic into our expert advisor. You should go
to the Buy strategy button and click on it. Now you should change the values
on the drop down menus to fit the values shown on the image below.
80
After you finish with the first one click the add button and introduce the
second conditions into the logic. What we are saying here is pretty simple :
Enter a long trade when the 15 moving average of the second bar in the past
(shift=2 means two bars in the past, 0 is current bar, 1 is bar before, 2 is bar
before the bar before, values in green rectangles) is below the 250 moving
average and the 15 moving average is above the 250 moving average in the
first bar in the past.
As you can see, this is the logical way in which you would express a crossing logic, the value of the 15 MA was below the 250 moving average and
after it was above.
Please note we are using the first closed values in the past we can find because
we need values for the MA that have already been defined, if you tried this on the
81
current bar (in real trading) , the value of the MA would change constantly since
the close of the bar has not been truly defined and the average is continuously
recalculated (in real life this would mean lots of fake signals). This also gives
MEANINGLESS backtesting results because the backtester uses actual bar closes
so it sees into the future you trade bar closes of bars that have not closed. So
please do NOT change these Shifts and tell me that it is more profitable because it
obviously is since you are exploiting a backtesting failure. The current approach
ensures that no exploiting of backtesting faults takes place, something you must
always be very careful about.
Introducing the short logic is pretty much the same but with the reverse logic.
Give it a shot ! Now go click on the sell strategy button and add the two trading
conditions but reverse the > and < signs so that the logic becomes this :
Enter a short trade when the 15 moving average on the second bar in the past
is above the 250 moving average on that bar and the 15 moving average is
below the 250 moving average in the first bar in the past.
You see ? It really is not that hard to build a simple expert advisor like this ! As you
can see, this introduces all of our entry logic. Now, we dont have any close logic
at the moment so this should be enough to get our expert. Of course, this script
will generate an expert advisor with a fixed take profit, stoploss and trailing stop,
something we should definitely change for the dynamically adjusted values we
talked about on the earlier sections. Now you just need to click on the complete!
button at the end of the web page and save your EA on your computer. We will
heavily modify this file and return to our expert advisor making website in the
future for further additions (closing logic, etc).
12.3.3 Explaining each part of the experts code.
Now that we have a draft of our first expert advisor we should now look into the
code and globally understand what is truly going on behind the curtains. If you
have metatrader installed (which you should) you will find that double clicking
on the file we just generated will launch the metatrader mql4 editor which is the
platform we will use for further editing of the code including future additions,
variable changes, etc.
You will see that the code has been commented and divided into sections so
that we may easily see what each section is and what its function is. Right now it
82
is not extremely important to now the ins and outs of how each segment of code
works but is a very good idea to take a look at the general aspects of the code
and see how the expert is actually going to work when trading, that is, the overall
operating scheme of the program. This is what each of the sections of the code
does in very general terms :
The first section, after the header and before the expert initialization function section is the place where external variables (the variables you change
when backtesting or forward trading the EA are defined). If there is anything we should optimize or want to change in the future, we should add it
here.
Expert initialization function. This section tells the expert what it should
do as soon as it is started. This is only executed once, when the expert is
loaded on the chart.
Expert deinitilization function. This is the opposite of the last and has code
the expert should execute once when a chart is closed or when a backtest is
finished.
Expert Start Function. The main part of the expert advisor begins here,
every section after this is a subsection of this Start function. This is where all
the action the expert takes on every tick are defined. You should remember
that the whole program is executed on every tick (all experts are).
Variable Begin. In this section we define our internal variables. You will
see that this section now contains a bunch of Buy and Sell defined variables
which define the logic we previously defined on the website applet.
Variable End. This just signals the end of the variable section
Check Position. This part of the expert checks for open positions, if there
are any opened positions, then the expert would check to see if the closing
criteria is closed for any of them. In this case, the expert will just avoid
further trading if there are any positions opened. The Signal Exit sections
are empty because we dont have any closing logic at the time besides, TL,
TP and SL. The trailing stop code is defined after the Signal end section.
You should notice that two trailing stop codes are defined, one for longs and
one for shorts after the pertaining Signal End sections.
83
84
This logic also adds a lot of variables which are not yet defined on the expert
and which should be defined as external variables as it is shown on the next image.
85
So what does this logic mean ? I will now explain what each chunk of this
logic actually means.
Section (1) of the logic simply defines the ATR indicator which will be a
daily ATR indicator calculated over a 14 day period over the current instrument, it also defines the contract size variable which is used in the formula
that calculates lot sizes.
Section (2) adjusts the ATR value if the ATR is larger than 0.1, something
which must be done for pairs that only have 2 or 3 decimal places.
Section (3) modifies the contract size if a mini account, that is, an account
in which a one pip movement with a 0.01 lot position equals 1 cent, is used.
Section (4) this section, if Orders_ATR is set to true, calculates the stoploss, take profit and trailing stop as a percentage of the ATR indicator, that
is, a percentage of the average true range, this is done with the formula
: 100*percentage_desired*ATR. Where percentage_desired is the percentage of the ATR you want to be SL, TL or TP and ATR is the value of the
ATR defined in (1)
86
changes to the expert advisor. Adding additional features and indicator filters
to an expert advisors is NOT a simple matter of trying random filters until one
works, it is a process that must be thought off carefully after examining the expert
advisors backtesting results. There are several things we need to analyze about
our expert advisor, of particular interest are the total profit in equity percentage
and the maximum draw down. We then have to think about what causes these
things and what we can do to eliminate them. I will now explain in a little more
detail what things contribute to each one of these two extremely important values.
12.4.1 Contributions to the Total Profit
The total profit is simply the sum of all the profitable trades we have got, different
from the net profit in that the total profit does not take into account losing trades.
The total profit of an expert advisor depends on three different things. How many
trades we take, how many of those trades are winners and what is the average
profit for those winners. Taking this factors into account it is easy to see that there
are at least three different strategies that can increase the profit of our automated
trading system.
Increase the number of profitable trades. This approach tries to increase
the number of profitable trades by increasing the number of overall trades
. That is, if the overall number of trades the EA takes is larger, then more
profitable trades will occur. Of course, the amount of losing trades we find
should also be taken into account (see next subsection).
Increasing the amount of profit earned per winning trade. This approach
tries to increase the amount of profit simply by trying to grasp more profit
per winning trade. This could also have the effect of increasing the number of loses as trades that try to get higher profits have an inherent lower
probability.
Increase the percentage of profitable trades. That is, we would like to increase the amount of profitable trades we have against break even or losing
trades. However, trying to get more trades would mean we would have to
increase our probability of catching a profitable trade which is also coupled
with a diminishment of the average winning trade.
As you can see, the above three strategies we can follow all even out against each
other as changing one is likely to affect the other. The real science in optimization
88
is in analyzing the losing and winning trades we get and looking if there is a
statistical possibility we are missing out on. For example, if we suddenly notice
that 20% of profitable trades are made on highly volatile markets but 40% of
losing trades are also made on this markets then we could introduce a volatility
filter that will have a net decrease in losing trades. Of course, the danger with
this filters, as you can see, is that their overall effect is to reduce the total number
of trades we take and therefore it can also reduce our overall profit. It becomes
a matter of testing each one of the possibilities we have against what the trade
analysis is giving us. When optimizing the expert advisor we are analyzing you
are going to take into account each one of the above possibilities and your going to
suggest one idea to use each one of these strategies to improve the profitability of
the expert. Now you understand what I meant by hard work in automated trading
? You now need to go manually after a backtest and analyze the trades taken by
the EA, notice when we are making loses, when we are making profits and come
up with strategies to improve these particular situations.
12.4.2 Contributions to the Maximum Drawdown
The other important factor we are going to discuss is the maximum draw down.
Most of the time it is most important to diminish market exposure rather than to
try to increase the levels of profit achieved. Finally what determines the actual
usefulness of a trading system is its ability to preserve capital and maintain itself
out of the market when it has to. Draw down is caused mainly by three different
factors, the total number of overall trades, the percentage of those that are losing
and the average amount of capital lost per losing trade. So what strategies can we
use to diminish draw downs after analyzing the trades produces by our automated
trading system ? In analogy to what we previously said about total profits, we can
use the following strategies to deal with the maximum draw down problem :
Decreasing the total number of trades. If we diminish trades it is obvious
that we will eliminate losing trades, therefore, this is a strategy to eliminate
losing trades. However, depending on if more profitable than negative trades
are eliminated this could actually increase the percentage of losing trades.
Decreasing the percentage of losing trades. If we want to decrease the percentage of losing trades then we would have to decrease the tightness of our
closing mechanism and therefore we would probably also expose ourselves
to an increase in the average loss per losing trades.
89
90
12.4.3 Back to our EA... So what initial settings , what pair, what time
frame?
This is always a very intriguing question. When starting to test an expert advisor
like this, what should our first testing parameters be ? How do we know which
ones we could use ? Well, a good starting place is to use a 50% ATR TP and 50%
ATR SL, this values will generally fall into what trends will generally do and the
analysis of this trading will give us a very good idea of how to improve the expert
advisor. For now we should disable the Trailing stop and we will enable it later
if we see that the trades could benefit from using it. Now get ready for your first
backtest of the first draft of the Watukushay I EA ! (remember to backtest to Jan
2000 to Jan 2009) We are not going to use the last 8 months for backtesting as
we want to keep some data to test against once we finish the whole improvement
process. This way we would know how this would have worked 8 months ago and
it will give us a very good idea about long term profitability. Of course, if all this
turns out great we would still need to check for live-back testing consistency by
running a live test of at least 6 months to compare to a backtest of that exact same
period of time. Meaning that we should do a backtest of the 8 months we did not
test, then trade 6 months live and then do a backtest of those 6 live tested months
to check for back/live testing consistency.
Another important question is to ask which currency pair and which timeframe. I would have to say that any trend following system should be able to
work on the GBP/USD or the EUR/USD as these are the pairs that have the most
directional trends. In my experience I would say that every time you test one of
these systems it is better to start with one of these two pairs. For this example
we will start testing on the GBP/USD one hour chart. We are going to use the
one hour to get a similar trading frequency as the gods gift ATR since the whole
goal is to make a similar or better expert advisor that trades in a similar fashion.
In an important note, also remember to use a balance of 100K USD to test the
strategy on the backtester to avoid any lot size calculation related errors (which
could arise if a low risk is used with a small account size due to the one decimal
lot size limitation).
12.4.4 First Backtesting Results. What can we improve ?
The WA2_1.htm file inside the Watukushay project folder shows you the result of
backtesting the expert we just programmed from Jan 01 2000 to Jan 01 2009 using
91
the settings we previously discussed. As you can see by the equity curve, the EA is
already almost completely long term profitable. You see how simple it really is to
create a profitable trading system ? When you tackle a fundamental characteristic
of the market and you have dynamic TP, SL, TL and lot size management, many
systems become profitable. As I said before, money management is the most
critical aspect of successful trading and one that we have successfully tackled
with the ATR adjustable logic.
This expert however has some problems, as you can see by the graph, the
expert experiences a period of almost 2 years of overall loses which in a real
account would bring us into significant draw down. For example, if you repeat
this backtest with a risk of 10 you will see the results in the WA2_2.htm file. As
you can see, the expert realizes a 20% yearly profit but has a draw down in excess
of 68%. Even more, profits are only achieved in significantly high amounts over
the past two years. However, you can see how the ATR logic does protect us even
when we increase risk. A linear increase in risk with any of the common money
management systems (supposing they could achieve the same results, which they
cant) would have multiplied risk by 10 bringing us close to account wipe out
while the ATR adjustable money management is able to scale draw down to a
lesser extent so we actually get better drawdown/profit relationships on higher
risks (of course, the magnitude of draw downs do increase so this does not mean
that it is better to trade higher risks since you are also increasing your market
exposure although to a lesser extent than with traditional money management
systems).
So how can we improve our strategy ? Some people may argue, by looking
at the trades, that we are just losing lots of profit on profitable trades due to the
fact that we are exiting the market too soon. The truth is, if you look at the next
image, that we are truly getting only about 20% of what could be our maximum
profit target on about 20% of the trades.
92
However, it is also worth noting that in order to get this profit we would need
to overcome barriers and ignore these whipsaws until we exit the market at a
more favorable level. If you try to increase the TP value by just 20%, to 70%
(WA2_3.htm) you will notice that there is a significant loss of profits and an increase in draw down. This is the price that you must pay to increase the average
profitable trade by 40%. So you have to bear in mind that getting these big trades
will mean getting more overall losing trades, that is, the percentage of losing
trades increases as you must increase your tolerance to market exposure in order
to realize these higher targets. When developing these systems keep in mind that
there is just a certain percentage you can reliable obtain from each trade you take,
of course, this does not mean we should stop looking for strategies to let our profits run but we should also realize the limits in which we can do this. We will later
see what this limit appears to be for this system.
If you closely analyze the trades taken on the first and second backtests you
will notice that the most important losing periods are mainly composed of trades
that go almost instantly against us because we have entered the market too late
these trades are due to whipsaw signals from the moving averages and are part of
the regular market exposure of the strategy.(an example of such losing trades is
shown below)
However, we now need to think about a strategy that will allow us to exit
these trades as fast as possible without getting out of our winning trades. Of
course, moving the SL closer is NOT an option since doing this also affects all
our profitable trades. What ideas do you have ? Before continuing, write the ideas
for closing systems you think could affect only our losing trades, that is, trades
that rapidly go against us. Review the previous backtests, look at the trades and
think deeply about this. What can I do to exit these losing trades quickly but stay
on the profitable ones ?
93
Before I continue I would like to explain a little bit to you what the code
actually means. For example, on the first line of code added double CloseBuy1_1
94
This section should be empty before you add this line of code. The only thing
this line of code does is to change the Order class to SIGNAL_CLOSEBUY which
tells the EA to close an open order if the conditions specified by the if statement
are true. If you take a close look at the if statement you will see that we are saying
if the 15 moving average is less than the 25 moving average one bar in the past
but it was also above that average two bars in the past then signal a close. This
is expressed by the > and < signs and by the && symbol which just means AND.
95
As an exercise, please relate each one of the variables to what it means and turn
this statement by steps into an English language statement. That is, start with
variable1 smaller than variable2 and variable3 greater than variable 4 and start
replacing each variable by what it represents. This will give you a much clearer
idea of what is going on.
Ready with that ? Now that you have introduced the Buy close trigger do the
same for the Sell trigger, it should be inserted in the Signal Begin (Exit Sell)
section. Write the sell trigger yourself and think about the meaning of the statement you are writing (check the variable names !) , also remember to replace
the SIGNAL_CLOSEBUY with SIGNAL_CLOSELL at the end of the statement
(also remember the semicolon at the end !).
Now it is time to test our expert advisor. Compile this version (by pressing F5
on the metatrader editor), now it is ready to be backtested ! Congratulations, you
have now introduced the first closing logic of the Watukushay 1 EA ! Again, if
you want to be lazy and skip all the exercises and programming and just use the
experts included you should keep in mind that somebody will not be lazy and will
go through everything and that person will have an edge over you in forex trading.
You always have to do as much work as you can and learn as much as you can if
you want to be a profitable trader.
12.4.6 Backtesting our new closing logic, time for our first optimization !
If everything goes well our backtest result should show the average loss should be
lower than before and our percentage of profitable trades should not be affected
significantly. You can see the backtesting results for this expert on the WA3_1.htm
file. As you can see, we have a significant improvement of our trading results
using this simple additional closing logic. The actual percentage of profitable
trades remains fairly constant while the average loss decreases significantly. This
means we have effectively decreased the risk to reward ratio without affecting the
number of winning trades. Awesome !
You might be thinking that everything has been explained with certain detail
about the closing logic except the arbitrary choice for a 25 MA on the closing
logic. You are totally right, this decision was arbitrary and based on my visual
inspection of about 30 different losing trades which showed that the 25 MA gave
the best results, larger moving averages lag too much so we touch the SL before
96
triggering a close while shorter averages interact too strongly with the 15 MA and
do not give us accurate closing signals. But what about 24 or 26 ? We now need
to find out which is the appropriate moving average to use in our closing logic.
We know it must be around 25 so what we will do now is called an optimization. What this does is to make the metatrader strategy tester do several different
tests changing one or several variables in an effort to show the best trading results. Optimizations must be done for the 10 year period and this makes them
computationally expensive so we will try to do as few optimizations as we can.
To start an optimization of this period we first need to make it an external
variable, so that the strategy tester has something to change. In order to do this,
you should change the 25 values on the internal variable definition for a variable
name and then define a new variable on the initial part of the expert by using the
command extern double variable_name. Your internal variables and external
variables should look something like the following images respectively. I named
the new variable closing_MA_period.
After doing this, you now need to recompile the expert (each time you make a
change you need to !). Now you must check the optimization box on the strategy
tester settings and define which variable to optimize on the expert properties
dialog. We are going to make an optimization of this variable starting from 20
to 30 doing a +1 step on the variable on each calculation. This means that the
strategy tester will run 10 different backtests from Jan 01 2000 to Jan 01 2009.
Now that you have started this go and have some lunch, it may take a while !
It is now worth saying what strategy we will choose over others as a result of
optimizations. In principle, we will always take the strategy with the smallest
97
profit close to that of a TP of the same value, although TL strategies are generally
more robust, in the sense that they are more flexible against changes in market
conditions.
It is however evident that the trailing stop variable (as well as the TP before)
are not at their optimum values, so our task will now be to try to see what the best
TL or TP value would be. For this we will run two separate tests first, to see what
the effects of lowering the TL to 40 and increasing it to 60 are. This will give us
an idea of what direction we should move or if the optimum TL is already around
50. Increasing the TL will most likely increase the number of losing trades but
it will also increase the average profit while reducing it would have the opposite
effect. We need to run both tests to try to see if we are missing significant profit
levels or if we are already near the right stop. Given the fact that a fixed TP
cannot be discarded as the most profitable approach we will also run the same
tests for a fixed TP of 40 and 60. The results can be checked by accessing the files
WA_3_TL1, WA_3_TL2, WA_3_TP1 and WA_3_TP2.
By checking up the tests you can observe that our best results are obtained
with the use of a fixed TP. It could be said that this strategy is better adjusted to
letting profits run up to a certain point and cutting loses short by using an MA
close strategy that simply prevents us from reaching the stoploss a little bit more
than 15% of the time. You should notice how trying to decrease the TL generates
much higher draw down levels as the number of losing trades is diminished but
this does not compensate for the lack of profits caused by the reduction of the
average profitable trade (opposite to the case of the TP). Some of you may wonder
if this strategy works better if we just let the smaller MA cross do the trade closing
job all the time, without the use of a TP or TL. As an exercise, set TP and TL to
false and do a backtest. Analyze the results, open up the backtest chart and think
about why you see the results you observe. Going back to the fixed TP, now
that we know that the best results are between 40 and 50 we should now do an
optimization run to determine what the best TP value actually is. As in the case
of the moving average, we will run an optimization by a step of one between 40
and 50 for the TP variable. This optimization is found in the WA3_OPT.htm file.
It is easily observed that all TP values have similar profits and draw downs with
most differences being caused by 2 or 3 trades. Changing the TP of 50 for a lower
one which may risk the introduction of further errors in backtesting is therefore
not desirable, mainly because the gain in equity or draw down is negligible.
99
results and they must also be traded for very extended periods of time. Since I
plan to discuss the Watukushay experts on my newsletters and make them prone
to a lot of analysis by you (my dear readers !) I will not introduce further filters
into this expert advisor (although this does NOT mean I do not like very long term
strategies, I do believe they ARE good and profitable).
12.4.9 Wrapping up, a test with normal risk and a walk forward
Now that we have all the necessary logic and parameters within the first Watukushay
EA its now time to do a backtest of the EA with the normal equity size and risk
we would have used on a live account since Jan 01 2000 until Jan 01 2009. This
will give us profit and draw down targets for the past 10 years. After this, the final
test of the EA will be a test from Jan 01 2009 to Sep 01 2009 to see how the expert
would have actually performed for this last 9 months. With this in mind we will
see if yearly draw down and profit targets where hit and we will see if the EA behaved like it did from 2000. You can find the first test in the WA_final_2000.htm
file. The second test is an exercise for you so that you can see how the EA would
have performed from January to September.
As you can see, we have developed a fairly decent likely long term profitable
system for the GBP/USD. The system adjusts dynamically to the market by changing its TP, SL and lot size according to the market volatility signaled by the 14
period daily ATR indicator. It is important to say that this EA CAN be subject to
more optimization, testing, etc. Of course, you are extremely welcome to modify
and play with the Watukushay EA 1 and see if you can make it perform better
(without exploiting backtesting glitches). I will be thrilled to hear your suggestions ! (although I do expect you to have statistical information to back it up, dont
suggest anything from the top of your head !)
12.5 The Watukushay Automated Trading System No.2 - Trading Based Solely on Price Action
After the development of the first Watukushay Project Expert Advisor I decided
that I wanted to develop an EA that would be different from all the other experts I
have programmed and tested before. My challenge with this new trading system
would be to achieve profitable long term reliable results using a trading logic that
was based on sound trading principles which lacked any input from traditional
indicators to achieve its results. More precisely I wanted to code a system based
101
on candlestick patterns that would also help fellow traders understand how candlestick patterns are mathematically and computationally defined and how their
detection is not trivial from a programming point of view. After a lot of work and
careful collection of all my development efforts I am very excited to present you
with this section of this ebook which deals with all the programming, analysis and
conclusions of this second chapter of my Watukushay Project.
12.5.1 The Experts Logic. Which Candlestick Pattern ?
As I said on the introduction to this section, my idea was to make the Watukushay
No.2 automated trading system a system based on the exploitation of candlestick
patterns. The first thing that came to my mind when I started to look for reliable
candlestick patterns to use as trading signals is that the finding of these patterns
and the reliable use of them in a mechanical trading system is not at all straightforward. Candlestick patterns depend to a great extent on the context in which they
occur, more over, candlestick patterns do not tell you any possible exit targets or
mechanisms, a second aspect that made the development of a candlestick based
trading system harder. There is also the additional problem of choosing between
reversal or continuation patterns to trade. Should we enter the market on a retracement ? Should we enter the market on a confirmation of a trend continuation
?
The first thing I thought of was to find a statistical source that could tell me the
success rate and the actual expectations I could have about different candlestick
patterns that ocurred in markets in general. After searching a lot I found out
that some of the patterns with the highest recorded success rate seemed to be
reversal patterns, more specifically patterns like a shooting star, a morning star, a
hanging man or a hammer. This prompted me to program the first trading attempt
using a reverse logic, aiming at taking profits from a reversal, however I was
not very convinced as how I would be able to set my SL and TP or what exit
mechanisms I should use to get out of trades early. A close look at the EUR/USD
charts also made me wonder how the accuracy of this trading patterns had been
measured by the studies I read. Obviously it became apparent that most of this
studies defined a pattern as accurate if there was any sort of reversal when the
pattern showed on the charts, nonetheless, it is impossible to predict the extent of
this reversal with variations in the nature of the reversal from 10 to 50% of the
daily ATR. As you see on the following image, the reversals can be small or non
existent.
102
It then became clear that when a reversal pattern with high accuracy appears
there is almost certainly a reversal of some sort, however the nature of such a
reversal is not easily defined and to profit mechanically from entries after these
reversal patterns happen would be non trivial. That is, knowing how to exit the
market would be terribly hard and no obvious adaptive technique such as a percentage based ATR take profit or a signal candle length adjusted TP seemed to be
up to the task. For this reason I decided that trading these reversal patterns would
not be the correct way to go and I decided not to proceed with the coding of a
trading system based on such trading patterns as entry signals.
103
It then became obvious that the only solution I had left was the implementation
of continuation candlestick patterns to enter the market. From all the continuation
candlestick patterns I researched I decided to code a system that used the three
white soldiers and three black crows patterns as entry signals. I chose these patterns because they are easy to code and have a good accuracy as defined per the
previous paragraph. This means that the white soldiers and black crows patterns
most likely lead towards a trend continuation when they happen. These candlestick patterns are formed by the appearance of three consecutive long (white soldiers) or short (black crows) bars which have similar bodies in size and have short
or non existent shadows (the shadow being the distance between the ends of the
body and the high/low of the candle). A sample of the 3 white soldiers pattern is
shown below.
done ? All these questions will be answered during the following few sections in
which the code structure will be discussed together with the analysis that lead to
the inclusion or deletion of the reversal patterns used as well as the adjustment
criteria used to define them.
12.5.2 Candlestick Pattern Definitions - How do we define these patterns ?
The next important thing we need to do is to define the candlestick patterns mathematically so that they can be incorporated into the code of our automated trading systems. The main questions we need to ask ourselves in order to define a
candlestick pattern in a mathematical way are the following ones : What is the
relationship between the different candlesticks composing the patterns and what
are the main characteristics of each one of the candlesticks forming the pattern. In
the case of the 3 white soldiers pattern we can make the following observations :
Each one of the candles is bullish (the close is higher than the open)
The candles have a short shadow
The first argument is easily defined mathematically :
The close of candle one is higher than the open of candle one
The close of candle two is higher than the open of candle two
The close of candle three is higher than the open of candle three
The second argument is a little bit harder to define because we dont know exactly
what short is. What is the minimum length of the shadow we need to have in
order for the pattern to be valid ? In order to start my tests I decided to require each
candle to have a ratio between its body (close-open) and range (high-low) which
should be less than 3. This means that the body of the candle should be able to
fit less than three times inside the range. This guarantees that our pattern will
maintain a given ratio between its body and its range, preventing bullish candles
which are of an odd shape to trigger trades. Finally it is also useful to consider
the size of the candles since you will not want to enter a trade if there are three
consecutive bullish candles 10 pips long during the Asian session. For this reason
we must also make the body of each candle a certain minimum number of pips.
Since it makes no sense to define the number of pips in an absolute fashion we
go to the ATR indicator and define the minimum size of each candle as a set
percentage of the daily 14-period average true range.
105
106
After we do this we will replace the entry logic of the EA by using our candlestick definition (you also need to add a line with extern double multatr=0.15 ;
at the beginning of the EA (where all the external variables are defined) in order
to define the multatr variable) :
There are several things you may notice about the if statement above which
may not coincide with the definition we gave about the candles a few paragraphs
above. The first obvious mismatch is the fact that we only require bars 1 and 2 in
107
the past to have a certain length, bar 3 is never required to have a certain length,
something which means that the third bar may be any type of bullish candle. The
second one is that the ratio restriction mentioned above is only applied to bar 1 in
the past and not to bars 2 and 3, something which must have been done in order
to match the 3 white soldiers pattern exactly. The main reason why these changes
were made by me is pretty simple, the actual exact representation of the 3 white
soldier pattern is very unprofitable on the EUR/USD (as well as on other pairs
such as the GBP/USD and the USD/JPY). As a matter of fact, the presence of
a strict 3 white soldiers pattern is pretty rare and seldom occurs, when it does,
most of the time the movement is pretty much finished and we head towards a
significant retracement. However I found out that many trending periods started
with the formation of a modified 3 white soldier pattern in which the first bar had
very variable shapes, but the second and third bar always had a significant length
(which I calculated to be around 10-15% of the ATR in most cases). As shown on
the following picture, the candlestick patterns found that led to significant trends
are shown against the ideal pattern :
This shows us a very important lesson about the design of automated trading
systems. What is written in the books about the use of candlesticks and indicators rarely works in a mechanical fashion, it requires creativity and a lot of
observation to truly find the inefficiencies within the FX trading market or any
market for that matter. I would like you to run backtests now using your newly
developed expert advisor. Before you do so please remember to add a // in front
of the if statements which include the Order=SIGNAL_CLOSEBUY and Order=SIGNAL_CLOSESELL statements. This will ensure that the closing logic of
the Watukushay No.1 expert advisor is not used in the process. Now you should
be able to compile the expert without errors and run a backtest of the EA. In order
108
to first test the logic, I used a 100% ATR adjusted TP and SL. The EA you should
have until now is found on the Watukushay Project folder under EA2. The EA is
called WA2_1.
Now that you have run the backtests from Jan 01 2000 to Jan 01 2009 please
answer the following questions. Was the EA profitable ? Where there any particular periods of time in which the EA failed dramatically ? Open up the chart with
the trades and analyze the entries. How do you think this EA can be improved ?
12.5.3 Introducing Additional Candlestick Patterns - A Closing Criteria
You may have found through your observations of the backtests that the EA fails
to grab profits when the market moves in its favor. Furthermore, many times the
EA holds onto trades for very long periods of time even after the system had gone
through some periods of time in which there were some obvious reversals which
pointed out to an end of the medium term trend. How do we further improve this
EA ? The answer is fairly simple. We need to limit our loses and let our profits
run, another very sound application of traditional trading knowledge. How do we
limit our loses ? The easiest answer would be to add a closing mechanism to the
automated trading system. As I said in section 9.5.1, candlestick reversal patterns
with high accuracy will be a very good choice to limit our loses since they will
almost without failure get us out of a trade when a reversal of any magnitude is
imminent.
Which candlestick pattern do we add then ? My first choice was a hammer
pattern (and its bullish reversal equivalent) since my research pointed this out to
be the most accurate pattern. Meaning that this is the pattern after which most of
the time a reversal followed. How do we program a hammer into the system ?
Ask yourself the same questions we asked at the beginning of section 9.5.2. Can
you describe which things are characteristic of a hammer pattern ? What is the
relationship between the body and the range ? what other characteristic can you
think of ?
As you may be thinking by now, there are several ways of defining a hammer
pattern. The most relevant information that I could think of was the hammers
body to range ratio and its shadow length. Opposite to the 3 soldier and 3 crow
pattern, the hammer and hanging man patterns have very long shadows with short
bodies. This means that we should make the shadow a minimum percentage of
109
the ATR and the body to range ratio larger than 3. This means that contrary to
the pattern we studied before, the body of the hammer and hanging man will have
to fit at least three times within its range. The shadow length must be defined in
the right fashion in order to avoid odd candlesticks. For the hammer this means
defining the distance from close to low as a minimum ATR percentage (opposite
for the hanging man).
With this criteria in mind we should now replace the closing logic of the EA
with the given logic that defines this trading pattern. Please replace the given if
statements you commented before with the bits of code shown in the following
image. You should also introduce the multatrhammer variable within the external
variable section at the beginning of the ea by introducing the line extern double
multatrhammer=0.4 ; (dont forget the semicolon !).
110
After this has been done you should be able to compile the EA without problems. If you want to see if you did anything wrong please refer to the WA2_2
expert advisor file which is the exact result you should have got up until now. After having coded our first exit logic we now need to run some new backtests on
the EA to see if there is any improvement on the profitability from Jan 01 2000 to
Jan 01 2009. Is there any improvement ? Why do you think I decided to set the
multatrhammer variable to 0.4 (40% of the ATR) ? Open up the chart and look at
the trades. You will now see that the EA is getting out of trades in a much better
fashion than before, however you will also notice that the hammer and hanging
man exit patterns are not enough to keep us away from most losing trades which
cost the EA a significant amount of profit (specially from 2005-2009). How do we
further limit our loses then ? Can you think of other reversal patterns that should
be useful ? Analyze the backtest and think about the best exit points, what other
candlestick pattern could contribute to better profitability ?
The next candlestick pattern which crossed my mind after analyzing the results obtained from the hammer/hanging man closing system were the bullish and
bearish engulfing patterns. These are both high accuracy reversal patterns which
are quiet common in the EUR/USD and often signal trend endings before they
are signaled by hammer/hanging man patterns. The actual patterns as they ideally
look in the forex market are shown below.
As you can see, in an engulfing pattern the second candle swallows the first
one. The bigger the second candle is over the first one, the stronger the engulfing
pattern signal is. This pattern is most likely the hardest to define up until now
since it requires a very cautious positioning of the open and close values of each
bar as the relative positions are vital to the adequate functioning of the candlestick
111
pattern. For example, for the bearish engulfing pattern you would have to fulfill
the following criteria (bars are numbered from left to right):
Open of bar 2 should be lower than the open of bar 1
Close of bar 2 should be higher than the close of bar 1
Close of bar 1 should be lower than open of bar 2
Close of bar 2 should be lower than open of bar 1
The difference between both candles bodies should be a certain percentage
of the ATR (since the higher the difference the stronger the signal we may
want to only take into account signals that have a certain strength which
is represented as a % based ATR difference between both candles)
The difference between both candles ranges should also be controlled to be
a certain percentage of the ATR
The difference between candle number ones range and body should also be
controlled to be a certain percentage of the ATR
As you see, the first four conditions arise as necessary parameters to arrive at a
pattern with the desired positioning while the last 3 conditions are used as a way
to control the shape of the candlestick pattern so that we may only obtain candle
formations that resemble what we want as a valid filter. The fifth and sixth conditions control the relationship between both candles while the eight controls the
relationship between range and body of the last candle. This is in order to eliminate the possibility of the last candle being a hammer/hanging man type candle
with a large body, something which does not account for a valid engulfing pattern.
By transcribing the statements given before into code we get the if statement shown below. You should add the following sections of code above the
sections you added for the hammer and hanging man patterns. By introducing the
additional if statements we are adding a second criteria for closing which will be
triggered if the conditions for the defined candlestick pattern are met.
112
and caused most of the big loses that hindered profitability during the last few
years of simulation. This of course could be eliminated by lowering the TP to a
level near 40-50% but this of course hindered most profitable trades and made the
EA become almost globally losing with its equity curve ruined from 2000 to 2004.
The solution I came up with was pretty simple and eliminated the problem almost
entirely . It became clear that we could simply exit trades if during a single bar the
trade moved in our favor by a certain percentage of the ATR. After analyzing most
of these movements I realized that this percentage was somewhere near 40%. The
final logic I came up with to exit trades early is as follows (for example for exiting
a short trade, opposite for a long trade):
Close of bar 1 minus the Open of bar 1 is smaller than 0. This means that
the candle is bearish
Close of bar 2 minus the Open of bar 2 is larger than 0. This means that the
candle before is bullish. I found out this was the case for most of these bars.
Body of bar 1 is greater than a certain ATR percentage (40% was the approximate ideal I calculated from the evaluation of different trades on the
backtests of the expert prior to the inclusion of this criteria. I evaluated
about 70 trades between 2007 and 2009 to come out with this conclusion)
When we translate this to code we get the if statement shown on the below
image. Please add the statements within the green rectangles below the previously added logic for the other two candlestick patterns. Also add the multatrtake
variable with a value of 0.40 as you have done for the previously explained code
additions. Below only the code for exiting selling trades is shown. What would
be the code for exiting long trades ? As an exercise write the code yourself (based
on the given code below and the other examples given before)
114
What happens now ? If you run the backtests from 2000 to 2009 you will
notice that the automated trading system shows a smooth up trending equity curve
that is even smoother than the one obtained from backtests of the Gods gift ATR
(The EA you should have coded up until now is called WA2_4). As you see,
the EA has been developed based exclusively on previous bar closes and price
action and with a 100% ATR TP and SL it holds absolutely no possibility of
giving erroneous backtests because of one minute interpolation errors. Now the
questions remains, is there any further room to improve the EA ? What would you
do to finish the development of this automated trading system ? What would be
your final steps to the optimization of the variables of this trading system ?
12.5.5 Optimizing Our Trading System, Increasing Profitability
After having an overall profitable equity curve from 2000 to 2009 we should consider that our system is not at its optimum performance. It would be extremely
lucky to develop a system and have the initial values be the exact optimums for
trading. In the case of our price based system it is specially true that all the ATR
adjustable parameters may have better values than the values currently assigned
to them.
In order to further improve the systems profitability we have to run systematic
optimizations that improve our performance. The first thing I always like to run
is an optimization of the TP and SL values. Since I had already run a backtest
with a TP and SL of 50 which was unprofitable (as I said on the last section) I
ran an optimization that scanned all SL and TP possibilities from 70 to 120% of
the ATR in steps of 10%. This optimization led to the optimization grid shown
115
below (darker results have a larger profit factor). As you can see, the EA performs
profitably on almost all settings but the optimum level for the SL and the TP are
around 80 for the TP and 100 for the SL, meaning that we were actually not very
far from the optimum values.
Obviously it is possible to run similar optimizations for all the ATR adjustable
parameters of the EA. As an exercise, run separate optimizations for each one of
the parameters varying 0.1 points in 0.01 increments from the default value -0.1
to the default value +0.1. As a result you will obtain a list depicting all the results
with each tests draw down and profits. What parameter will you use to choose
the parameters you need to trade ? Is it better to optimize one parameter and then
optimize the other on the first optimum or optimize the second parameter also on
the default settings ? What are the most profitable settings you found ? Take those
settings and run 9 separate backtests, one for each year and compare each years
profit and draw down, what would you expect for each year ? could you handle
the year with the worst profit/ maximum draw down ?
After doing all the above exercises I found out the most profitable settings
for the Watukushay No.2 expert advisors. These settings have astounded me
with the most profitable results I have ever seen for a long term profitable expert advisor (expecting a 40% draw down for a 100% average yearly profit (noncompounded)). The results are better than the gods gift ATRs backtesting results
and they have shown to be consistent in live trading (please watch the back/live
testing consistency video for Watukushay No.2 and FE). The backtesting curve is
given below (statement is also available on the experts folder).
116
117
RSI = 100
118
100
1 + RS
where
RS =
Average Gain
Average Loss
and
Average Gain = EMA [14] o f U p Periods
Average Loss = EMA [14] o f Down Periods
if the previous close is above the last close then :
U p Period = |Current Close PreviousClose|
Down Period = 0
if the previous close is below the last close then :
Down Period = |Current Close PreviousClose|
U p Period = 0
If you look at the mathematical formula above, it becomes clear that what the
RSI displays can be interpreted as the percentage of the market which is being
taken by gains or loses. For example, an RSI of 50 means that the average gain
and loss have been exactly the same while RSI values above 50 indicate that gains
are becoming more predominant in the market (constituting a higher percentage
of the change for the last X periods) while values below 50 mean the opposite
(that loses are becoming predominant).
If you would want to use the RSI indicator to get into a trend then you would
need to get into the market when certain movement was predominant (which is
what a trend is all about). However you would also want to get into the trend on
a retracement from the main trend which means that you would need the market
to be at a certain extreme RSI value and then return to a more median RSI value
to give you a better place of entry to enter a trend. There would also be several
ways to exit the market, the first one that ocurred to me would be to exit the
market upon a reentry of extreme RSI values since being here suggests that the
119
loses/gains have already happened and that a retracement is due to happen soon.
The following image shows you an example of my idea with the Watukushay FE
RSI strategy.
Our previous analysis also points out the reason why the main RSI strategy
of buying on values below 30 and selling on values above 70 is not long term
profitable. The problem with this strategy is that most of the time you will be
trading against the trend and possibly the retracements that take place wont be
strong enough to generate you substantial profits. The strategy above points to a
straightforward way in which the RSI can be used to actually follow the trend and
get into trades at a very favorable position. However many questions still remain.
What RSI period do we use ? What values do we use for the exit and entry criteria
? These are all matters which I resolved through analysis of the charts and later
fine-tuned through the use of system optimization. I also used ATR adjusted SL,
TP and lot size values in order to further increase the adaptability of the EA and
increase its profitability. The best values of these parameters were also solved
through optimization as you will see within the following subsections. In the
following section we will discuss the mathematical definition of the RSI logic
used in Watukushay FE. How do you think this logic is defined mathematically ?
How would you define the logic ? As an exercise, write the mathematical entry
120
and exit conditions you would use to code the above explained system. You can
try first by writing sentences that say what you want to do, for example enter a
trade if the RSI value for bar 2 in the past is below X and the last bars RSI is
above X then write a mathematical expression for this sentence.
12.6.3 Coding Watukushay FE
You can code Watukushay FE in several ways. I will show you now the modifications you should do over Watukushay No.1 in order to change its logic for the
logic of Watukushay FE. You can also use the expert advisor builder and then add
the ATR adjusted modifications as we did in the case of Watukushay No.1. There
are just a few changes that need to be made in order to code Watukushay FE from
Watukushay No.1. The first thing we need to do is to add the external variables we
will be using later to define the RSI indicator values as well as our entry and exit
parameters. You may remove the variables inherent to Watukushay No.1, such as
the closing MA period we added then.
121
The next step will be to define the entry and exit logic of the RSI logic which
is defined in place of the logic used on Watukushay No.1. The only thing that
needs to be done is the replacement of the code within the if statements which
define the entry and exit logic of the expert advisor. We will define the logic for
the entry by entering a position when coming back from extreme RSI values. We
will enter a short when the RSI is below X value and then moves above X and
we will enter a long trade when the RSI is above Y and then moves below Y. The
exit criteria will be upon a reentry of an extreme zone, because as I explained on
the last section, a reentry of an extreme zone means that the trend has already
resumed (since the RSI looks at the past) and it is time to exit the trade. So we
will use mainly the same entry logic but reversed for exits. If the RSI is above A
and then moves below A then close a short trade and if the RSI is below B and
then moves above B then close a long trade. The values of X and Y will depend
on our observation and optimization but since X,A,Y and B are extreme values
our beginning parameters should definitely be above 70 for Y and B and below
30 for X and A. The following image shows the code changes necessary for the
implementation.
122
Now that we have the logic of the EA coded and ready to be tested it is time to
ask ourselves what values we should start with on the tests. Since we are looking
to catch trend movements that happen on the one hour bar between retracements it
would be wise to start with SL and TP values below 100% of the ATR so we could
start with a test of the SL and TP at 50% then do optimizations to find better values
for this parameters. We could also start testing with a 14 period RSI and then test
higher and lower periods. What values of the entry and exit parameters would you
choose ? These values are the values of X,A,B and Y we discussed earlier, what
parameters would you start with ? As an exercise, backtest Watukushay FE on
the settings you propose. What are the results ? how would you improve the EA
? why does the EA fail on unfavorable markets ? The key to profitable trading is
many times found in limiting the systems loses. How could you limit the loses of
Watukushay FE ?
12.6.4 Testing Watukushay FE. First Observations.
You can see the first backtest I did for Watukushay FE by accessing the WAFE_1
backtest on the FE folder under the Watukushay Project main folder. What conclusions can we draw from the performance of the trading system ? Did it do what it
promised ? does it have a positive mathematical expectancy ? What are favorable
and unfavorable market conditions ? All of these are questions which you have to
ask yourself when developing long term profitable systems. The equity curve for
the backtest is shown below.The system managed to achieve a positive mathemat-
123
ical expectancy for the past 10 years, something which speaks very good about
the trading logic used. However, the fact that the average yearly profit is only
around 2% for each 11% draw down points out that there is still a lot of room for
improvement. How can we improve the strategy ?
First of all, before starting to do any optimization, we should first see the
trades taken and analyze different market conditions. Do the same backtest on
your computer. Analyze the trades on the 2004-2005 period, why did the system
have so many loses there ? What is the systems market exposure ? What are
the systems weaknesses ? By analyzing the backtesting trades, we can answer
these and more questions pertaining to the Watukushay FE and any other trading
system. To start this analysis, let us look at the winning trades of the EA, did
the EA manage to do what it was supposed to under favorable market conditions
(trending markets with mild retracements) ? The following chart shows the typical
profitable setup achieved by the EA during profitable market conditions.
124
As you can see, the EA does exactly what it is supposed to when there is a
clearly defined down trend on the EUR/USD. The EA enters trades on retracements of the trends at very favorable positions and exits trades accurately in proportion to market volatility as determined by the ATR. What are the losing conditions for the EA ? Tight market ranges, when the RSI becomes contracted and
signals overbought or oversold conditions on markets which do not have significant volatility we get many whipsaw signals because the market is just bouncing
off overbought and oversold zones. An example of such losing trades is given on
the chart below.
The fact that this fake trends were the leading cause of unprofitability on unfavorable periods prompted me to first optimize the EA towards other RSI periods
to see if these unfavorable periods were less frequent or more limited on different
values of the RSI. In order to measure this effect I ran an optimization of the RSI
period variable from 5 to 30 in a 5 step in order to see the effect of increasing or
decreasing the value of the RSI. You can see the results of this optimization as
OPTRSI on the Watukushay FE folder.
As you can see by the tests, low RSI values give us unprofitable results, mainly
125
because the market becomes much more blurry with the use of fewer periods
increasing the problem we had with the 14-period RSI. Higher RSI periods values
have an obvious positive effect, especially regarding the draw down. As you see,
the maximum draw down is reduced from 23% to less than 10% from using a 10
to a 15 period RSI, this effect continues arriving to values as low as 3% for the
30 period RSI. However this carries with it the diminishment of profitability since
many trades that would have been taken on a lower period RSI are actually not
taken due to the fact that the signals are smoothed over a longer period. This
is why we see a global diminishment in the number of trades from almost 2000
on the 10 period RSI to 60 on the 30 period RSI. The optimum value for the RSI
seems to be compromise of both worlds which seem to be found at around a 20
period RSI which has a 5.03% draw down maintaining about 300 trades which
would give as about one trade every two weeks for a 10 year period of testing.
Effectively increasing the RSI diminishes the number of unfavorable trades.
12.6.5 Doing Optimizations of the Entry and Exit Criteria
The next obvious step to take in order to limit loses and letting profits run is the
optimization of the closing and opening parameters of the EA. Would trades benefit from being closed at a higher or lower RSI cross ? In other words, would trades
benefit from having more room or less room as retracements happen ? should
trades tolerate smaller or larger moves against them ? I optimized the closing
criteria of long and short trades in order to find an answer to this question. However it is very important to consider the symmetry on this matter since one could
introduce hindsight by simply making one value asymmetric with the other. For
example, an exit level of 80 for longs and 40 for shorts would favor shorts since
they are unsymmetrical regarding the 0 line. For this reason I made some coding
changes to allow a single variable to change both variables symmetrically. The
coding changes are highlighted on the below image.
126
The next step was to optimize the newly created entry_sym and exit_sym variables in order to find the optimum parameters for entry and exit for the RSI logic
used on the Watukushay FE expert advisor. I ran these optimizations between 20
and 40 for both variables using a 4 step. This allows the coverage of a very wide
area on the RSI and brought invaluable information about the characteristics of
the trading strategy. The result of the optimization is shown below. You can also
access the optimization file - OPTENTRYEXIT - inside the experts folder.
Below we see the equity curves for the three most profitable settings (backtests
are accessible on the experts folder, WAFE_2a, WAFE_2b, WAFE_2c.). Notice
how much the EA has improved from our first backtest thanks to an intelligently
directed optimization.
As you can see, all of them exhibit smooth equity curves with new equity
highs achieved almost every year. Given the fact that all of the equity curves
are smooth we choose the most profitable results to continue our tests. The most
profitable result shows a maximum draw down near 3% with an average yearly
profit of 3.6%. This means that we would expect to have an average yearly profit
close to the maximum draw down level, a very good first profitability target for an
expert advisor. It will also become obvious now to you that we are only missing
the optimization of the SL and TP criteria which are clearly very important to the
experts profitability since they are the primordial factors that influence the exit
criteria of the trading system. In order to determine the best TP and SL values
for the EA a correlated optimization was done between the SL and TP from 30 to
70 varying each one in a step of 5 units. The test results - also contained on the
OPTSLTP file - are shown on the graph below.
128
By looking at the graph above we find that incredibly a 50% ATR TP and SL
is the optimum value of both parameters for the EA (it is very rare to have the first
guess be the most profitable settings). It is important to note that some values
have slightly higher profit values than the 50-50 SL/TP but those results also have
significantly more draw down which does not make up for the small increase in
profitability. For example, the 60-40 SL/TP setting achieves a higher profit but
its draw down increases by more than 2% for an increase of less than 0.2% to the
average yearly profit, a clearly bad trade off.
12.6.6 Further Improvements on Watukushay FE
Can the profitability of Watukushay FE be improved further ? Can it be used
on more currency pairs ? As an exercise, repeat all the above analysis and optimization process for the USD/JPY and GBP/USD. Does the EA work on those
currency pairs ? Why does the EA work or does work on those pairs ? What are
the unfavorable and favorable periods on those currency pairs ? I will be glad to
hear about any positive results you may have of Watukushay FE on other currency
pairs. This will also be a great exercise for you to practice all that youve learned
about EA testing and optimization. Also remember to maintain a certain degree of
coarseness in your optimizations. Using very fine tuning (like optimizing a TP or
SL with a step of 1) can lead to over-optimized settings and overestimated profit
and underestimated draw down targets.
the explanation of the programming of these traits outside of the ebook but they
will be included as optional advanced videos for those who are interested in
the development of more advanced expert advisors from a programming point
of view. The Watukushay No.2 expert advisor final version is available in both
formats. The version which includes functional decomposition and UI (named
WA2_EURUSD_UI) will be the version used in live testing because of its improved reliability and flexibility from a technical perspective (although both versions have the exact same logic). In the future all expert advisors final versions
will be coded in this way to account for a better user experience. The use of functional decomposition also allows for the interchangeable use of parts between
different systems, an advantage when using mixed strategies.
130
131
There have only been a few expert advisors which I have found meet the necessary criteria to be tested on a demo account. One of the only ones I actually
found worth buying and testing is the DTS-1 or Dreambuilder FX trading system
which has been forward tested for a little bit more than 4 months with good results
that accurately match backtesting results. It is worth noting that even though the
DTS-1 EA is said to have a small draw down by the author with a market exposure of about 1/6 of yearly profits, several people have expressed that this value
is much closer to 1/3 so beware that using the DTS-1 on its most conservative
settings would produce a maximum draw down of even 50%. As I said earlier,
profitable trading systems seem to have similar market exposures and this proves
to be the case. If you want to start using this system, please FOLLOW the authors instructions regarding risk and money management and do NOT increase
your risk until you have traded this EA for at least a year. DTS-1 does not show
back/live testing consistency with live testing results falling behind in profitability
to a great extent when compared with back testing. This further points out to the
fact that the profit/risk targets made by the author are overestimated. Profit targets
are more in line with 20-30% per year with a 50% maximum draw down. However
since a subscription is charged for the use of the EA it becomes an unattractive
132
investment since most profits would be invested on VPS and EA service fees for
small account holders.
133
14 CONCLUSIONS
14 Conclusions
It is with great pleasure that I finish this ebook on automated trading for the forex
market. It has always been my intention to help people who are new as well as
experienced traders succeed in the world of forex automated trading and I really
feel that I am contributing my grain of sand with this ebook. I want you all to know
that I have done my greatest effort to communicate my experience to you as a
successful user of automated trading systems in my forex journey. Hopefully after
going through all my ebook and diligently following my advice you will be able to
start to see some substantial profits from your automated trading ventures. There
is still a LOT to say about automated trading systems, a reason why this ebook
should be updated regularly, with at least 3 or 4 updates during the year. I would
like to end this ebook wishing you all the greatest success in your automated
trading careers. Thank you all very much for all your purchases !
134