forex software

Create and Test Forex Strategies

forex software

eas-guide:strategies-and-expert-advisors

This is an old revision of the document!


Expert Advisors

Manual Trading

MetaTrader

MetaTrader is a trading platform. Normally you will get it from your broker for free. MetaTrader is developed by a company called MetaQuotes. Currently, MetaTrader 4 is the most popular trading platform among traders. Almost all brokers offer MetaTrader 4. There is also another version - MetaTrader 5. MetaTrader 5 is the latest version however, it is not as popular.

The main purposes of the trading platform are to deliver data from the broker to your screen and to allow you to trade. MetaTrader allows you to trade manually as well as automatically.

What you see on the picture below is the price chart of the EURUSD market. You can trade manually - buy and sell on the market. You can also see the current (latest) price in the right end of the chart. As you will notice the price is constantly moving and it is not easy to decide whether you should buy or sell and what point in time you should act. Of course, you want to trade in the proper direction since you want to make a profit.

Indicators

To allow you to make a better decision MetaTrader has options to add indicators on the chart. Indicators are shown as lines or bars that will run along the price chart. Indicators are mathematically based on price history and other market parameters.

You can add an indicator to the chart very easily. For our example, we will use one of the most popular indicators - MACD (“Moving Average Convergence Divergence”). You can just drag and drop the indicator from the MetaTrader Navigator box to the chart. (if you don't see the navigator go to View > Navigator to enable it)

For our example we will use one of the most popular indicators - MACD (Moving Average Convergence Divergence). Adding the indicator displays the Options window. Since indicators are based on mathematical formulas we can choose the Inputs tab and choose values for some of the variables in the mathematical formula of the indicator. Through this, you can change how the indicator is drawn out on the chart.

As soon as you drop the indicator on the chart you will see red lines appear on the chart. You will also notice bars appear below the chart. (If the indicator opens a dialog window, just press OK.)

The grey bars here show the MACD line and the red line is called a “signal line”. When the market changes this indicator's line changes and the bars also change.

You can use these changes as they appear as signals for what direction to choose for trading, when to open and when to close a position. Those signals define your trading strategy. When to buy, when to sell and in what direction.

We could say if you see the grey MACD bars go above the red line this might be a good signal for entering in a long position. However, how do we know if this is a good idea or not? We can test it on a demo account but it will take lots of time.

Automatic Trading

Indicators are great for guiding us in manual trading. However, if we want to automate trading and leave MetaTrader trade on its own while we do other things we cannot do that with simply using indicators. MetaTrader Indicators contain no trading logic. Here come Expert Advisors.

Expert Advisors

If you are going to go for automatic trading you need a trading strategy. More specifically in automated trading, your trading strategy is the rules when to open a position and when to close a position and in what direction.

Trading strategies are “only rules” compared to Expert Advisors. Expert Advisors are the implementation of the rules in code that MetaTrader can understand and execute - MQL (MetaQuotes Language) code. This is why with our software you can export your trading strategy as an Expert Advisor.

MQL is not easy to write. It is actually harder than normal programming because besides programming you need to know how MetaTrader works internally.

Writing Expert Advisors

To program Experts, you need to know how MetaTrader works but things do not end here. You need several other things to create a potentially profitable Expert Advisor. You need to know how the market works and how the indicators work.

After you are done programming you will want to test your Expert Advisor. Then if you are not happy with the results you need go back, change the code and test it again until you are happy with the EA's performance on historical data. This is the most tedious part and many people get stuck on it because it takes a ton of time.

Backtesting in MetaTrader

Backtesting is the process of executing your trading strategy (or your Expert Advisor) on the historical data from your broker. Then you can see how it would have performed if it was trading on this market.

To backtest your strategy you can use MetaTrader's Strategy Tester. Since MetaTrader downloads historical data from the broker you can use the data and the Strategy Tester to test your Expert Advisors.

However, there is a better way.

Automatically Creating Expert Adivsors

There are tools that allow you to generate Expert Advisors without coding. Here is where we can actually help you a real lot. Instead of spending countless hours on coding, testing, changing and optimizing your Expert Advisors we can offer you a tool that does that for you.

Expert Advisor Studio is designed to help you analyze, generate and test strategies. It also lets you easily export those strategies as Expert Advisors so you can autotrade them in MetaTrader.

Strategy Overview

In Expert Advisor Studio you can specify the strategy logic manually as well.

In the image above you can see EA Studio's Strategy Editor. In the middle column, there are some coloured boxes. The box at the top is the Strategy Properties. If you click on it you can set the entry lots for the strategy as well as the protections such as Stop Los and Take Profit (see below).

The boxes below the Strategy Properties box are the Entry Rules. Each entry rule is based on an indicator behaviour. For example in our case when Force Index changes its direction to downward we will enter a long position.

If you click on an Entry Rule box you can see more data and specify different logical conditions for when to act.

For the strategy to enter a position all of the Entry Rules must be met at the same moment.

Below the Entry Rules are the Exit Rules. Similar to Entry Rules if you click on an Exit Rule you can specify the logic for when to act on each indicator.

Exit Rules behave differently from Entry Rules. As soon as only one of the Exit Rules is met the strategy will exit the position.

To remove a rule use the X button on its box.

To add a rule use the Add new… boxes