Blog: Building Expert Advisors for Metatrader 4, EA Programming, Forex

EXPERT ADVISOR EQUITY CURVE TRADING

 

 

By Octavio Riaño, MBA Project Manager at www.digitaltradingsystems.com

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.


Equity Curve % Stops

Moving averages can be applied to the equity curve of a trading system to determine when and how to take trades from that trading system. The calculation begins with the basic trading system. A basic trading system is the one that has no money management techniques applied to it, and that usually operates of an indicator. The basic system will provide the equity curve (EC) subject to analysis. In top of the EC we will calculate a Moving Average (MA). The equity filtered by the MA will be defined as good when it is above its moving average and poor when bellow.


Equity Curve trading using Moving Averages

As an example, suppose we want to maximize the rate of return in fixed ratio position sizing without exceeding a worst-case drawdown of 30%. Our objective is the rate of return. The constraint is the limit on the worst-case drawdown to no more than 30%. The optimization parameter is the delta of the fixed ratio method. The search method simulates trading using different delta values, searching for the delta that generates the highest return without exceeding the drawdown constraint. The solution is the optimal delta.


With this information now we can take several approaches to trade our system:


  • Allow signals when the equity is above the MA, and, block trades when bellow.
  • Allow larger trades when the equity is above the MA, and, smaller trades when bellow.
  • Administer positions, by filtering with different moving averages.
  • Allow signals when the equity is above the MA, and, switch opposite trades when bellow.

In the example bellow, we use a trending system, that adds positions as the markets trends. After applying the system to 1 hour EURUSD charts for a period of 6 years we get a sample of 1950 trades; The equity curve goes trough peaks and valleys as market volatility cycles affect the performance of the basic system. The system only provides $300 of profits for such period. We use a 10.000 dollar account for example purposes.


CASE FOR SCALING POSITIONS IN AND OUT USING MOVING AVERAGES

For the example bellow we will compare results using the approach that administers positions, by filtering with different moving averages. Regular trading is on crossovers above the moving average; no trading on crossovers below the moving average. The basic system is filtered applying several MAs to the raw equity curve. For the example the basic system equity curve is shown in red; a 21 period moving average of the equity curve is in blue.


HERE THE RAW EQUITY CURVE OF THE BASIC SYSTEM AND THE 21MA


RAW EQUITY CURVE OF THE BASIC SYSTEM



5MA FILTERED TRADE RESULTS


RAW EQUITY CURVE OF THE BASIC SYSTEM



13MA FILTERED TRADE RESULTS


RAW EQUITY CURVE OF THE BASIC SYSTEM



34MA FILTERED TRADE RESULTS


RAW EQUITY CURVE OF THE BASIC SYSTEM



The case for scaling in and scaling out of the system using moving averages, as the 5MA, the 13 MA and the 34 MA filters provide different levels above the equity line for taking entries and exits. The combined results of 5MA filter+13MA +34MA filters with lot sizes of 33% each produces the equity curve shown below:


RAW EQUITY CURVE OF THE BASIC SYSTEM



On every case shown above not only does MA filtering produce a rising equity curve with more profit and a lower drawdown, but it does so with fewer trades. Profits increased from $300 to an average of $20.000, using the same lot sizes, and the same trading system signals on the same underlying instrument, over the same period of time, without any additional money management rule.


CASE FOR SWITHCHING TO OPPOSITE TRADES WHEN BELLOW THE EQUITY LINE


Another method for implementing equity curve trading is also possible. Instead of starting and stopping trading on crossovers of the equity curve, you can switch the position to do the opposite on moving average crossovers. To illustrate, consider the trading results shown below. The equity curve is shown in blue; a 10 period moving average of the equity curve is in purple.


RAW EQUITY CURVE OF THE BASIC SYSTEM



Applying switching to opposite trades for the trade series shown above produces the equity curve shown below.


Regular trading is on crossovers above the moving average; opposite trading resumes on crossovers below the moving average, this change produces a rising equity curve with more profit and a lower drawdown. Profits increased from $300 to $35.000, using the same lot sizes, and the same trading system signals on the same underlying instrument, over the same period of time, without any additional money management rule.


Changing market conditions can become a window of opportunity instead of an originator of system draw downs. Applying a different approach to trading such as money management using equity curve trading can prove beneficial not only to control drawdowns, but also to maximize trading profits.


RAW EQUITY CURVE OF THE BASIC SYSTEM


For more information in fixed ratio position sizing:


"Portfolio Management Formulas" by Ralph Vince (John Wiley & Sons, New York, 1990.)
"The Trading Game" by Ryan Jones (John Wiley & Sons, New York, 1999.)
"Trade Your Way to Financial Freedom" By Van K. Tharp (2nd ed., McGraw-Hill, New York, 2007)