Blog for Building Expert Advisors for Metatrader 4, MQL4 Programming, Forex

EXPERT ADVISOR POSITION SIZING OPTIMIZATION

 

 

An essential key in Forex Programming is position sizing optimization. Position sizing is the process of determining the number of shares or contracts to trade. Two of the more popular methods are fixed fractional and fixed ratio position sizing. Both of these methods have an adjustable parameter that determines how quickly contracts or shares are added as the account equity grows or trading profits accumulate. A suitable value for the position sizing parameter -- for example, the delta of fixed ratio position sizing -- isn't always obvious. Position sizing optimization is a way to find the optimal settings for any position sizing method.

Optimization involves goals or objectives, constraints, and parameters. The purpose of the optimization is to find the value of the parameter that minimizes or maximizes the objective without violating the constraints. The result of this process is the optimal value of the parameter. A search method is used to find the optimal parameter value. view more



EXPERT ADVISOR EQUITY CURVE TRADING

 

 

Any forex programmer will confirm that basic mechanical trading systems are cyclical. The reason for that is that systems are designed in statistical observations that mostly take advantage of trending markets or sideways markets. Considering the cyclical nature of markets which fluctuate with volatility, systems performance are subject to market conditions. Usually at high volatility levels trending systems perform quite well, and sideways systems tend to fail. Likewise, at low volatility scenarios, range systems perform whereas trending systems lag. Therefore, regardless of the nature of the system, the equity curve will experience drawdown periods. In the process traders require a technique to reduce drawdowns and even turn loosing periods into winning periods. Here we will show an example of a mechanical trading system results and show how equity trading can not only identify changes from congestion periods to trending periods and vice versa, but also how to capitalize on it. view more



EXPERT ADVISOR POSITION SIZING

 

 

An experienced MQL4 Programmer will agree that money management is one of the most critical aspects of trading. Position sizing -- also known as trade sizing, bet sizing or betting strategy -- is one of the key elements of money management. Whatever you call it, it's the process of determining how much to trade. Position sizing can be used to increase returns, reduce risk, improve the risk/return ratio, and smooth the equity curve, among other goals.


Position sizing is particularly important when leverage is involved. If you trade too many Forex lots, a string of losses could force you to stop trading. In fact, with the built-in leverage of Forex, you could lose more money than you have in your account. On the other hand, if you trade too few contracts, much of your account equity will sit idle, which will hurt your performance. Finding the right balance is a key element of risk management. view more



USING FIXED RATIO POSITION SIZING ON EXPERT ADVISORS

 

 

This money management feature has become a standard variable for sophisticated EA programmers using low drawdown trading systems.

In fixed ratio position sizing the key parameter is the delta. This is the dollar amount of profit per contract to increase the number of contracts by one. A delta of $3,000, for example, means that if you're currently trading one contract, you need to increase your account equity by $3,000 to start trading two contracts. Once you get to two contracts, you need an additional profit of $6,000 to start trading three contracts. At three contracts, you would need an additional profit of $9,000 to start trading four contracts, and so on. For stock trading, a "contract" can be interpreted as a fixed number of shares, such as 100 shares.

It's possible to derive the following equation for the number of contracts in fixed ratio position sizing:

EA Programming Math

The equation for calculating fixed ratio trading proportions. view more



BUILDING EXPERT ADVISORS FOR METATRADER 4

 

 

Traders with some experience are aware of the importance of including systematic methods to take advantage of markets. A systematic approach involves conceptualizing, defining, writing and testing rules for entering and exiting trades, then consistently trading by those rules going forward. This approach is structured after understanding that varying discretion or emotion eventually affects their trading performance, and that discipline and acute precision in decision making and execution is necessary to accomplish consistent profits systematically.

As traders become systematic, they write rules that are robust enough to accommodate unseen market scenarios. The building of such trading rules requires statistical verification and understanding of the market logic behind the action taken in the specific market. By measuring system performance, risk can be determined.

In the other hand, Trading with a system implies one will always take the same actions under the same circumstances, which requires the risk tolerance that allows withstanding the risk exposure of the system. Once emotion is controlled, experts say, consistency can follow. view more



TOOLS TO BUILD EXPERT ADVISORS

 

 

Many traders have adopted Expert Advisors (EAs) in recent years. EAs help remove the emotion from trading and enable trading strategies to be automated so that the buy and sell signals can be executed automatically without manual intervention.

The Metatrader 4 Trading platform. The MT4 platform can be provided by a brokerage, as an enticement to use the broker's services. The latter usually connect to a variety of data sources and brokerages. The key features of MT4 besides order entry and charting, is to offer capabilities more aligned with systematic traders, such as the scripting language (MQL) and strategy back-testing. The instruments used on this platform include CFDs (contracts for difference) and Forex (foreign exchange), which provide a wide array of markets to trade.

The MQL4 Scripting language. Expert Advisors are essentially software programs and, as such, are based on the MQL programming language. The MQL4 language is tailored to market trading and it is available together with the MT4 application. The MQL4 is a general purpose trading system that allows the MT4 Programmer editing, code testing, and some historical simulation. view more



TOP TEN EXPERT ADVISOR CLASSES

 

 

Systematic trading methods are the basis for EA programming (EA or Expert Advisors- also known as MT4 Robots). They consist of technical indicators or other mathematical methods that are used to generate objective buy and sell signals in the financial markets. Some of the most popular methods have been in use since before the advent of computers, while other methods are more recent. Here we classify ten of the most popular systematic methods found in Expert Advisors Logic:

Moving average crossovers. EAs based on the crossover of two moving averages of different lengths are perhaps the most common systematic trading method. This method also includes triple moving average crossovers, as well as the moving average convergence divergence (MACD) indicator, which is the difference between two exponential moving averages. The moving averages themselves can be calculated in a variety of ways, such as simple, exponential, weighted, etc.

Channel breakouts. In this method, a price channel is defined by the highest high and lowest low over some past number of bars. A trade is signaled when the market breaks out above or below the channel. This is also known as a Donchian channel, which traditionally uses a look-back length of 20 days. The famed "turtle" system was purportedly based on channel breakouts. view more



ELEMENTS OF A PROFITABLE EXPERT ADVISOR

 

 

Expert Advisors (Robots built through MQL4 Programming) use a predefined set of trading rules to generate objective buy and sell signals. While the variety of EAs (Expert Advisors) is almost limitless, most profitable EAs have certain elements in common. Whether you build your own EA or purchase one, EAs with these characteristics will maximize your chances of success. Most profitable EAs have the right level of complexity in their trading logic. These goldilocks strategies are not too simple and not too complex. The financial markets are certainly complex. An overly simple strategy is unlikely to respond adequately to the market's complexity. On the other hand, if the strategy is overly complex, it may be over-fit to the market. An over-fit strategy is one that doesn't generalize well to data other than that on which it was based. Complex strategies tend to be over-sensitive to changes in the market and need constant adjustment and modification.

A profitable EA needs to have realistic entries and exits. For example, it's easy to specify limit orders for a trade entry. In practice, a limit order may not be filled, depending on the liquidity of the market and how many traders have orders in front of yours. Similarly, it may be possible to specify a market-on-close exit, but if the order is placed exactly at the market's close, there will be no opportunity to fill it. The simulation results, on the other hand, may not take this into account. view more



SYSTEMATIC TRADING USING EXPERT ADVISORS: RISKS AND BENEFITS

 

 

Systematic trading refers to buying and selling financial instruments, such as Forex, using a predefined trading strategy called a trading system. Most trading systems are coded in a so-called scripting language that allows them to be executed on a broker's trading platform. The alternative to systematic trading is called discretionary trading, in which the trader makes buy and sell decisions on a trade-by-trade basis. It's often said that the job of a systematic trader is to follow his/her system, whereas the discretionary trader may alter his/her strategy depending on how the market evolves.

One of the most significant benefits of systematic trading is that it helps to remove emotional decision making from the trading process. When real money is at risk in the markets, the emotions of fear and greed can easily overwhelm rational decision making. This can be mitigated to a large extent by having a trading strategy that makes the decisions for you. view more



MT4 STRATEGY TESTER REPORT PERFORMANCE ANALYSIS

 

 

Evaluating an Expert Advisor by testing it on historical data is essentially the same as simulating how that system will perform when it's traded. It follows, then, that the more accurate the simulation, the better the system can be evaluated. An important aspect of trading is the number of lots to take for each trade; Including position sizing in a trading simulation makes it much easier to determine (1) the minimum account size needed to trade the system or method, (2) the initial position size for a given account size, (3) the expected return on account equity, and (4) the likely risk or Risk/Reward ratio.

While including position sizing in a trading simulation can enhance the simulation, the performance summaries available in Metatrader 4, are generally based on fixed contract trading; e.g., one lot per trade. It's usually possible to change the number of contracts for each trade (for example, using Metatrader programming); view more



METATRADER PROGRAMMING FOR RULE IMPLEMENTATION

 

 

Whether you have the discipline to stick to a defined set of rules is an important consideration if you are going to trade systematically, whether you buy or build. Expert Advisors require following all rules religiously. Successful system traders avoid the temptation of bypassing the rules, whether that comes in the form of holding a loser too long or being too quick to take profits. The beauty of trading systematically is that you have made those exit decisions beforehand based on strong research and statistical evidence, not in the heat of a fast market.

The Expert Advisor developer should have good experience actually trading his or her target markets. The developer needs to have a good background in technical analysis, and this includes knowing what technical methods have been tried in the past so that previous systems are not simply recreated. view more



REASONS FOR EXPERT ADVISOR PROGRAMMING

 

 

Traders with some experience are aware of the importance of including systematic methods to take advantage of markets. A systematic approach involves conceptualizing, defining, writing and testing rules for entering and exiting trades, then consistently trading by those rules going forward. This approach is structured after understanding that varying discretion or emotion eventually affects their trading performance, and that discipline and acute precision in decision making and execution is necessary to accomplish consistent profits systematically.

As traders become systematic, they write rules that are robust enough to accommodate unseen market scenarios. The building of such trading rules requires statistical verification and understanding of the market logic behind the action taken in the specific market. By measuring system performance, risk can be determined. view more



MT4 PROGRAMMING FOR SYSTEMATIC FOREX OPERATIONS

 

 

Traders with some experience are aware of the importance of including systematic methods to take advantage of markets. A systematic approach involves conceptualizing, defining, writing and testing rules for entering and exiting trades, then consistently trading by those rules going forward. This approach is structured after understanding that varying discretion or emotion eventually affects their trading performance, and that discipline and acute precision in decision making and execution is necessary to accomplish consistent profits systematically.

As traders become systematic, they write rules that are robust enough to accommodate unseen market scenarios. The building of such trading rules requires statistical verification and understanding of the market logic behind the action taken in the specific market. By measuring system performance, risk can be determined. view more