34
Getting Started in Forex Robots By Rob Booker and Wes Walton Version 1.0, August 29, 2016 WARNING Trading involves substantial risks. Forex trading is risky, and most traders lose money. Past performance is not necessarily indicative of future results. DOUBLE WARNING If you are not good with computers, robots are not a good idea for you. If you are a beginner with basic computer tasks, such as opening programs, installing programs, opening files and folders, downloading files then robots are NOT a good fit for you . We love you and we do not want you to have a bad experience. If you are a beginner with computers take a quick class on computer basics and then come back to the robots. TRIPLE WARNING!!! Run these robots on a demo account first. Run the robots in an account that is COMPLETELY separate from your discretionary trading. Run the robots with a TINY TRADE SIZE at first, because something can go wrong, and you do not want to have huge losses. There is plenty of time to increase trade size later. RETURN TO TABLE OF CONTENTS | RobBooker.com Page 1

Getting Started in Forex Robots - Amazon S3 · Getting Started in Forex Robots By Rob Booker and Wes Walton Version 1.0, August 29, 2016 ... Then the robot “hands” the management

Embed Size (px)

Citation preview

Getting Started in Forex Robots By Rob Booker and Wes Walton Version 1.0, August 29, 2016 WARNING Trading involves substantial risks. Forex trading is risky, and most traders lose money. Past performance is not necessarily indicative of future results. DOUBLE WARNING If you are not good with computers, robots are not a good idea for you. If you are a beginner with basic computer tasks, such as opening programs, installing programs, opening files and folders, downloading files ­ then robots are NOT a good fit for you . We love you ­ and we do not want you to have a bad experience. If you are a beginner with computers ­ take a quick class on computer basics and then come back to the robots. TRIPLE WARNING!!! Run these robots on a demo account first. Run the robots in an account that is COMPLETELY separate from your discretionary trading. Run the robots with a TINY TRADE SIZE at first, because something can go wrong, and you do not want to have huge losses. There is plenty of time to increase trade size later.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 1

TABLE OF CONTENTS Click a link to jump to a section. THE BASICS What is a trading robot? Why trade robots with forex? Is that dangerous? Why would I use a robot? How is a robot made? Is it hard to learn? THE EQUIPMENT What is Metatrader 4? What is a Virtual Private Server? How to set up a VPS at Amazon How to get a free VPS from your broker How to login to your VPS with Remote Desktop Connection HOW TO INSTALL A ROBOT Installing a robot Loading a robot onto your chart How to make sure it is “active” and looking for trades Playing around with robot settings HOW TO TEST A ROBOT The MT4 Strategy Tester Data: the Heart and Soul of backtesting How to run a simple test Reading Test Results

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 2

Using the visual mode Optimization Common backtesting problems TROUBLESHOOTING ROBOT PROBLEMS My MT4 closed ­ now what? My server crashed My MT4 froze My robot is not taking any trades

THE BASICS What is a trading robot? A trading robot is a software program. Once the program is installed into your trading platform, it can take trades automatically. You can be asleep, working, or spending time with your family and it can take a trade. Robots as “Complete Trading Solutions” Some traders use robots to do ALL of their trading. That’s what I do. I let the robots run 24/7 and I rarely touch them or intervene. These robots open trades, manage the open trade, take profit, stop out ­ everything. I don’t have to touch the computer at all. Robots as “Trading Assistants”

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 3

Some traders use robots as “trading assistants.” For example, you might know that you want to buy the EUR/USD currency pair, but you need to go to work right now. Work is awful. But you need to go to work, because your family likes to eat food and live in a house with a roof. How can you trade the EUR/USD AND go to work? You could use a robot, like our “Trendline Robot.” You just draw a trendline on the chart, and tell the robot to take a buy trade if price breaks beyond that trendline. The robot can even send you an email alert that it took the trade. Then the robot “hands” the management of the trade back to you. Why trade robots with forex? Is that dangerous? All trading is risky. Not just forex. Every kind of trading carries substantial risk. Forex is no different. Forex trading is not a get rich quick scheme. It can be, however, a “get poor quick” scheme. Many people lose money trading forex. In fact, most traders who trade forex lose money ­ all of their first account, usually within just a few months. With that said, robots do the following things to help reduce that risk:

1) They stop out of trades when they are supposed to (instead of holding onto a loss forever);

2) They do not get worried when they have a few losses in a row;

3) They do not skip trades because they “see something on the chart that makes them doubt the trade”;

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 4

4) They take profit when they are supposed to;

5) They take the entry on the trade when they are supposed to;

6) They add to winners if they are supposed to … and so on. In other words, a good robot is reliable. It sticks to the trading plan. Most traders who lose money do NOT stick to their trading plan. In fact, they trade like deranged monkeys. I love robots because I can trust them to follow the plan. I cannot always trust myself to follow my plan ­ so robots are really good for me. Why would I use a robot? I think I answered this above, but to make sure we’re clear: If you have a full time job and cannot watch the charts, the robots are a good idea. If you have a busy life and do not want to sit in front of the computer, the robots are a good idea. If you have been losing money ­ and trying to make your own discretionary trades ­ then robots might be a good idea. If you find that you have a few good trades in a row, and then you take a big loss (over and over), then robots might be a good idea.

How is a robot made? Is it hard to learn? The robots we talk about here are “Metatrader Robots.” They are written in a language called “Metaquotes,” or “MQL” for short.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 5

A robot built with the Metaquotes language is often called an “Expert Advisor.” I have no idea who created that name but I would like to punch that guy in the face. There is no reason they should have called it an “Expert Advisor.” It’s a trading robot. Here is an example of what the code looks like: // Preliminary processing

if(Bars < Period_MA_2) // Not enough bars

Alert("Not enough bars in the window. EA doesn't work.");

return; // Exit start()

if(Work==false) // Critical error

Alert("Critical error. EA doesn't work.");

return; // Exit start()

//­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

I don’t expect you to learn MQL. I don’t know how to program using it. If you want to learn more, here is an online book about the language: https://book.mql4.com/ There are thousands and thousands of metaquotes programmers in the world. The program language is similar to C. I just overheard someone say that at a cocktail party, and I don’t even know if it’s true. Why do we use Metaquotes? Metaquotes is a hugely popular programming language. It has been used to build millions of indicators and robots. It is reasonably easy to debug. It

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 6

does not require a huge investment of time and money. It does not require expensive charts. So we use Metaquotes. You might hear people say that “successful traders don’t use Metaquotes,” and then they will tell you that you should be trading with a Python program, or Easy Language, or whatever. Tell them to go fly a kite. You and over 1 million other traders around the world are doing just fine with Metaquotes.

THE EQUIPMENT What is Metatrader 4? Why do we use it? Metatrader 4 is the world’s most popular forex trading software MT4 (for short) is free. It is easy to learn and use. It is not the world’s best trading software. But it is good. It is stable. It works. It is not perfect but it works. Every forex broker in the world offers the Metatrader (MT4) platform for trading. It is easy to load a robot into this software. It is easy to test a robot’s historical performance with this software. Here is what MT4 looks like:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 7

I don’t know why I included that picture. I mean, you could have just googled, “What does MT4 look like?” How to Install MT4 Ask your broker for a download link for Metatrader 4. (Not Metatrader 5 ­ that is the newest version of Metatrader and we do not use it for about 100 reasons that do not matter right now). You install Metatrader on a Windows computer. You cannot run Metatrader on a Mac. If you have a Mac, you will want to use a Virtual Private Server (see more in the next section) to access your Metatrader trading platform. There is a MT4 phone app. Can you use that? Yes, you can use that to monitor your trades. But you cannot use that to load robots or test robots. What if you do not like MT4?

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 8

Then you should stop reading this book. Where can you get more information on how to use MT4? YouTube is FILLED with lessons (for free) on how to use MT4. I suggest you start with this guide: http://www.investopedia.com/university/meta­trader­guide­intro/ And then watch some videos on YouTube. DO NOT INSTALL A GENERIC MT4 PLATFORM!!! You might be tempted to download MT4 from a different broker than your own, or the MT4 website. DO NOT DO THIS. Download MT4 from the broker where you are going to do your trading, so that you are familiar with the way your broker has set up MT4 ­ this is important, because every broker will have a slightly different way of handling open orders, running robots, and so forth. What is a Virtual Private Server? Why should I use one? A Virtual Private Server (VPS for short) is a Windows computer. It is always on, it is managed to protect it from viruses, and you can turn off your home computer ­ and the VPS stays on. This is great because in order to run a robot on MT4, the computer needs to be on all the time. And a VPS can stay on day and night, all the time, and only needs to be rebooted once a month (if even that). A VPS is just going to run robots. It is not going to be used for games, or homework, or web browsing, and all that garbage.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 9

You will be able to access your VPS through a software program named “Remote Desktop Connection” ­ or other programs that do the same thing. These programs allow you to open a window on your home computer ­ and then look at the VPS computer’s desktop. And then you can move your mouse around, you can type ­ anything ­ and you will be using the VPS as if it were right there in front of you. A VPS is another computer, just sitting somewhere else, that you manage and operate from your home computer. WES COULD MAKE A VIDEO HERE SHOWING A VPS It is “Virtual” because it’s not in your house. It’s a computer sitting in a big room, in a company’s server room, somewhere else. It’s “private” because it’s just yours. And it’s called a “server” because it usually runs a version of Windows used for Servers. How to set up a VPS at Amazon https://www.youtube.com/watch?v=zqORpKde29Q ^ This video supposedly shows you how to get Metatrader set up on a free VPS at Amazon. How to get a free VPS from your broker Many brokers will offer a free virtual private server when you open an account. You can also just call and say, “Do you offer a VPS for clients?”

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 10

Another option is to contact Justin Hertzberg at Forest Park FX. He knows the details on free VPS options at almost every forex broker. You can contact Justin here: http://forestparkfx.com How to login to your VPS [write instructions for using Remote Desktop, since it works on Macs and Windows] Some important settings for your VPS ­ turning off updates, getting a browser installed

HOW TO INSTALL A ROBOT Installing a robot Download the robot to your computer. Remember where you’ve placed the file. Open Metatrader 4. At the top of the left of the menu screen, you should see the world “File”. Click on that.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 11

Click on the item “Open Data Folder”. Now open the folder called “MQL4”.

Now open the folder called “Experts”.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 12

Once the “experts” folder is open, drag the robot file you downloaded ­ and put it into the “experts” folder. Now your robot is “installed” into MT4. To get the robot to “show up” in your MT4, you must now do the following steps: Go to your “Navigator” panel in MT4. Right­click on “Expert Advisors”. Click “Refresh”. Your robot will now show up in MT4.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 13

Loading a robot onto your chart To load a robot onto your chart, drag the robot from the “Navigator” panel onto your chart. To drag the file, hover over it with your mouse, click the left mouse button, and then drag your mouse onto your chart.

After you drag the robot onto your chart, a “settings” window pops up. Close that window for now ­ we will play around with the settings later. Once the robot is on your chart, you will see the name of the robot in the upper right area of the chart. See where it says “Ultimate Finch of Doom v1.03” at the top right of the chart? That means we loaded the Ultimate Finch of Doom robot onto our chart. But that doesn’t mean the robot is running or taking trades.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 14

How to make sure it is “active” and looking for trades You’ll know your robot is running if you see the “smiley face” on your upper right hand area of the chart. It looks like this:

If you do not see that smiley face, then you need to check two things:

1) Check the “Auto Trading” button at the top of your MT4 menu, and make sure it’s green:

2) Left­click on the smiley face (or frowny face) on your chart next to the name of the robot. Your robot settings will pop up. Now click on the “common” tab. Make sure that “allow live trading” is checked.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 15

If your robot still has a frowny face after you do these two things, call your broker. Ask your broker if they allow you to trade with robots (expert advisors) on your account. If they say “yes,” tell them your platform is giving you a frowny face no matter what. Playing around with robot settings/inputs Every robot has “settings”. These are also called “inputs”. These settings control when it opens trades, the trade size, the profit target, and more. WARNING: Before you start playing with new settings, keep a note of (or save) your favorite settings that you are using right now. To view the settings window, left­click on the smiley (or frowny) face on your chart. Here is what the “settings/inputs” window looks like.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 16

These inputs control what the robot does, and when the robot does it. Don’t get caught up in each of the settings above ­ I only want to mention a few of them that are universal to all of our robots:

1) WARNING: Robot trading carries risks. Most traders lose money (even with robots). Run all robots on a demo account first.

2) “Magic”: This is the robot’s “magic number”. You will probably never need to change this. This number simply helps the robot remember which trades it took, and can distinguish between its own trades and your discretionary trades. But I still want to warn you ­ you should separate your robot and discretionary trading into two accounts.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 17

3) “Slippage”: This tells the robot to NOT take a trade if price is slipping in a fast­moving market.

4) “Max Spread”: This tells the robot not to take trades if the spread widens too far (for example, during news).

You can learn about the other settings/inputs when you learn about each of the individual robots. For now, just play around with changing the numbers in the settings. NOTE: If your robot is running on your chart, with an open trade, and you open the settings/inputs window and make changes, your robot will now start to manage the trade with the new settings.

HOW TO TEST A ROBOT The MT4 Strategy Tester Metatrader 4 (MT4) has one of the easiest to use, automated back testing programs available, and it is free with the platform. This back testing program is called “Strategy Tester”. Here is what it looks like:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 18

Data: the Heart and Soul of backtesting Having accurate and reliable historical data is critical to back testing. If you do not have good historical data, your tests can be inaccurate or give highly skewed results. MT4 makes getting historical data easy, and they even give you an accuracy score to let you know you are testing with good data. First, you will need to download the data, which you can do by clicking on Tools at the top menu of your platform, then click on History Center:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 19

You should see something like this pop up:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 20

Double­Click on the currency pair of your choosing, then double­click on the 1 Minute timeframe and press “Download” at the bottom of the window. Once the Download is complete, press “Close” and you are ready to test! It is usually best to run your tests in a demo­trading platform from your broker, which is SEPARATE from your live trading account. How to run a simple test Once you have downloaded data, you are ready to start testing! Open Strategy Tester (See “The MT4 Strategy Tester” section above) Step 1: Choose the robot you plan to test:

Step 2: Select the Symbol for the test:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 21

Step 3: Select “Every tick” in the “Mode” dropdown menu:

Step 4: Select your date range and use the Check Box to ensure you use those dates:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 22

Step 5: Decide whether or not to use “Visual Mode” (See “Using the Visual Mode” section below) but for now leave it un­checked:

Step 6: Choose your timeframe (Period):

Step 7: Spread ­ This step is important. The Spread is the difference between the “Bid” and the “Ask” price. For more information about what the “Spread” is, head over to GettingStartedInForex.com, or CLICK HERE. The tester automatically selects “Current” as the default, but you don’t want that. If your broker has 5 decimal places on price (for example, 1.12345) then you will want to select 30 (for 3 pip spread) or 50 (for 5 pip spread). If your

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 23

broker uses 4 decimal places (for example, 1.1234) then you will want to set 3 (for 3 pip spread) or 5 (for 5 pip spread).

Step 8: Expert Properties. These are the inputs that you can change when you use the robot. You can change them around to find the best settings. NOTE: See Optimization for more information about optimizing your robot, ignore it for now.

The Expert Properties window should look something like this:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 24

Step 9: Start Test ­ Just press the “Start Button”

Step 10: Wait for the test to finish up. When the green bar reaches the end, the test is complete:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 25

Step 11: Look at the results (See “Reading Test Results” for more information). The Report tab is where you find your test results data:

Step 12: Change some settings around in the Expert Properties and try it again. Reading Test Results Testing is one of the most useful (and necessary) things you can do when starting out with robotic trading. It helps you get a “feel” for how your robot reacts in certain situations, during certain periods of time, and what settings you should use for your live trading. But what do the results mean?

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 26

This section will take you through the “Report” that shows up AFTER you complete a test. These are the 4 MOST important things to look at. NOTE: Good results in testing do NOT guarantee the same results in live trading, but it should give you a good idea of how the robot performs. Here is the “Report” page:

1) Total Net Profit: This is how much you made total after you subtract your losing trades from your winning trades. Gross profit (all of your profitable trades combined) minus the Gross loss (all of your negative trades combined) equals Total Net Profit.

2) Total Trades: This is the total number of trades your robot took during the time period you selected.

3) Maximal Drawdown: This is the most important drawdown to look at. This is the total amount of drawdown you got from all trades open at the same time. If you have 1 trade open that is ­$100 and you have a $1,000 account, that is a 10% drawdown. If you have 2 trades open and one is ­$100 and the second is ­$50, that is a combined open position of ­$150, which would be a 15% drawdown.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 27

a) This is important because you need to know how much your robot can draw down while trades are open. If it draws down by 20%, that might seem acceptable on paper, but think about how it would feel to see those negative positions in real time, happening to your real money, and waiting weeks, months, years for them to close. Reality is harsh sometimes.

4) Modeling Quality: You don’t want anything below 90%. If you have less than 90% modeling quality, or “n/a” as your modeling quality, go back and re­download your data for that pair, and make sure to download the 1 minute timeframe.

a) NOTE: Testing on the 1 minute chart is fun sometimes...but it is useless and does not give accurate, realistic information about how the robot performs. Always use 5 minute or higher.

WARNING (AGAIN): If you are testing a robot on the 1 minute chart ­ because you want your robot to take 7 million trades a day or something ­ your results are probably useless. It is very hard to get reliable data on that short time frame of a chart. Using the Visual Mode Visual Mode is a way to see the chart and watch the robot place trades as it goes through Strategy Tester. It is much slower and should really only be used in a handful of situations:

1) When diagnosing an issue with the code. 2) When you want to see specific a specific trade or set of trades that

look interesting in the trade results, like: a) A losing trade b) A profitable trade c) A trade with a large drawdown

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 28

d) Etc. 3) When you generally just like watching it place trades. 4) When you can’t get to sleep at night.

You can use Visual Mode by checking the box next to it, like this:

This brings up a couple of additional options next to it; the slider bar, play/pause button, and “Skip to” button. We are going to skip the “Skip to” button. The Slider Bar is the SPEED in which the chart moves, and the Play/Pause button is (you guessed it) how you Pause and Play the test. The “Start” button is STILL how you START the test, then the Pause/Play button allows you to pause it to look at something on the chart and continue (play) when you want it to move forward more. NOTE: There is a HUGE difference between the Speed Slider being maxed out and being just below maxed out, so be careful when starting a test. Optimization

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 29

Optimization is AWESOME, but it has its limits. Optimization is designed to test multiple robot variables against each other (set by you) to see which set of variables work the best. NOTE: You cannot run Optimization in “Visual Mode” For instance, let’s say you want to test different trade sizes, to find out which trade size makes the most money with the least drawdown. But you don’t want to sit there and watch the test, then change the variable, then watch the test, then change the variable, then watch the test, and so on and so forth. Optimization solves this problem. It can test a bunch of variables at the same time, and then tell you what worked best. To Optimize, check the “Optimization” box, then click on “Expert Properties”:

When we did a basic test (See “How to Run a Simple Test” above) we used the “Value” column to change the robot properties for the test. For Optimization, we use the “Start” “Step” and “Stop” columns shown here:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 30

Make sure you Check the box next to the variable you want to optimize. Then, set the Start (which is the variable starting place, in this case 0.01) then the Step (which is how much each pass through the tester increases the variable by, in this case 0.01) and the Stop (which is the final amount the tester will use). In the example above, the tester will run 5 over the time period you selected:

1) First_Trade_Lots = 0.01 2) First_Trade_Lots = 0.02 3) First_Trade_Lots = 0.03 4) First_Trade_Lots = 0.04 5) First_Trade_Lots = 0.05

After it runs those 5 times through the tester, it will show you the results in “Optimization Results” tab:

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 31

You can then select your favorite of the group, double­click on it, and it will pre­fill the tester Expert Properties with those values and you can continue testing. NOTE: You may be tempted to select a bunch of variables to optimize at the same time, but be careful because MT4 has limits on how much optimizing it can do in one session. If you select 5 variables to test, and you want it to test 10 different settings of each, that would be almost 10,000,000 passes (that math is probably WAY wrong). MT4 cannot do that many passes. Albert Freaking Einstein can’t do that many passes (besides, he’s dead). So you should not try to test that many variables, either. Try to keep it at 1 or 2 variables running a simple set of changes. Testing 1 variable at a time, with 6­10 steps, works best. Common backtesting problems Here are some common issues we encounter with testing:

1) No data. If you are only seeing a few trades in the “Results” tab, you might not have any data downloaded for that pair.

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 32

2) Ordersend Errors in the Journal tab. There are quite a few reasons you would receive one of these. Try these steps to see if you can fix it:

a) Check your Lot sizes to make sure your broker supports them. 0.001 is most likely not supported (although sometimes it is). If you are unsure how to check, try placing a SUPER SMALL trade on your demo account with the lot size you are trying to use. If it works, you are good there. If not, you should change it.

b) Check your stop loss and profit target. On some robots they will use a Pip amount for their exits (we usually use dollar amounts). If your pip amount is too small (sometimes less than 5 will throw an error) then it could have an error.

c) Make sure you aren’t using conflicting variables. For instance, your robot might have an option to exit at a certain dollar amount you set to true, and also to exit at a certain pip amount which you set to true. In the code, those two might conflict, but hopefully the developer put some notes about potential conflicts in the robot instructions. Always read the instructions or watch the instructional videos!

d) When you go into the Expert Properties, go to the Testing tab and look at “Positions”. It should say “Long and Short”. Unless the developer specifically tells you that you can use “Short only” or “Long only”, always use “Long and Short” because there is a strong possibility the developer did not take that into account otherwise.

TROUBLESHOOTING ROBOT PROBLEMS My MT4 closed ­ now what? My server crashed

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 33

My MT4 froze My robot is not taking any trades

RETURN TO TABLE OF CONTENTS | RobBooker.com Page 34