forex software

Create and Test Forex Strategies

forex software

eas-guide:strategies-and-expert-advisors

Strategies and Expert Advisors

Manual Trading

MetaTrader

MetaTrader is a trading platform. Normally you will receive 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 it. There is also another version of it - MetaTrader 5. It is the latest version. However it is not as popular.

The main purpose of the trading platform is 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 to 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 Navigator box from the Navigator to the chart.

For our example we will use one of the most popular indicators - MACD or “Moving Average Convergence Divergence”. Adding the indicator displays an 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 formula. Through this you can change how the indicator is drawn out.

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

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

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

We could say if you see the gray 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. 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 more of an abstract term. If you need to execute your trading strategy in MetaTrader for example you will need to code it in MQL as an Expert Advisor file.

Expert Advisors are programs written in the MQL programming language. The language is named “MetaQuotes Language” after the company that develops MetaTrader.

MQL is not easy to write. It is actually harder than normal programming because outside of 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
  • how how the indicators work

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

Backtesting in MetaTrader

Backtesting is the process of executing your trading strategy (or in other words 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.

MetaTrader comes with a tool called Strategy Tester. MetaTrader also provides programs which include different indicators and trading rules so you can automate the trading process. You are most probably familiar with those programs. They are called Expert Advisors.

Since MetaTrader downloads historical data from the broker you can test the Expert Advisors' performance on that data.

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 for generating, testing and analyzing strategies. It also lets you easily export those strategies as Expert Advisors so you can autotrade them in MetaTrader.

Strategy Overview

Expert Advisor Studio also allows you to specify the strategy logic manually.

In the image above you can see the strategy editor page of EA Studio. In the middle column You can see colored 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).

Below are the entry rules. Each entry rule is based on an indicator behavior. For example in our case Force Index should change it's direction to downward for us to enter a long position.

If you click on the entry rule you can see even 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. If you click on each you can specify it's logic.

As soon as one of the Exit Rules is met the strategy will exit the position.

You can also add and remove Entry and Exit rules easily by using the X buttons to remove them and by using the “add new” buttons to add a new one.