Tuesday, May 30, 2006

Strategy Testing in MetaTrader 4

I am sure anyone who is reading this document knows MetaTrader has a feature which allows you to back test your strategies. This is called the Strategy Tester, it can be accessed via the view menu or by the keyboard shortcut CTRL+R. Below is a screenshot showing the Strategy Tester interface:

Interface

This article is focused on improving the reliability of this tool. It does not however go into any detail about optimization. Firstly we will run a back test using a simple Expert Advisor with the standard default settings in MetaTrader the data centre being used is the InterBankFX data server. We will then import Alpari data and compare the results.

Standard Data

For the first test we set up with the Currency to be tested the AUD/USD. The period we use is daily and the model we use is every tick (based on all available least timeframes with fractal interpolation of every tick). The time period we will be testing is from 15/06/2004 to 28/05/2006. We use the simple MACD Expert adviser. The following summarizes the results obtained with the demo data:

Strategy Tester Report MACD Sample

Bars in test

559

Ticks modelled

4263759

Modelling quality

42.15%

Initial deposit

1000.00





Total net profit

470.00

Gross profit

635.00

Gross loss

-165.00

Profit factor

3.85

Expected payoff

26.11



Absolute drawdown

0.00

Maximal drawdown (%)

165.00 (11.1%)



Total trades

18

Short positions (won %)

12 (100.00%)

Long positions (won %)

6 (83.33%)


Profit trades (% of total)

17 (94.44%)

Loss trades (% of total)

1 (5.56%)

Largest

profit trade

50.00

loss trade

-165.00

Average

profit trade

37.35

loss trade

-165.00

Maximum

consecutive wins (profit in money)

13 (481.00)

consecutive losses (loss in money)

1 (-165.00)

Maximal

consecutive profit (count of wins)

481.00 (13)

consecutive loss (count of losses)

-165.00 (1)

Average

consecutive wins

9

consecutive losses

1



Equity Curve

Improving Modeling Quality

As we can see from our test the modeling quality was 42.15%. I for one would want to have a much better modeling quality then 42.15%. The one minute data we have from our demo feed has several gaps in it for one reason or another. These gaps reduce the quality of our modeling as the strategy tester will interpolate the areas between these gaps which may or may not trigger invalid buy or sell signals.

Gap filling (the free way)

If you want to improve modeling quality without spending vast sums of money you have come to the right place. A great free source of 1minute data for MetaTrader is alpari’s databank. Most currencies are available as well as Gold and various CFD’s.

Step By Step Setup Guide

Step One

The first step is to download the 1M currency data for the desired currency pair. You can access this data at http://www.alpari-idc.com/en/dc/databank.php. Or via the direct links below:

AUDUSD

CHFJPY

EURAUD

EURCAD

EURCHF

EURGBP

EURJPY

EURUSD

GBPCHF

GBPJPY

GBPUSD

NZDUSD

USDCAD

USDCHF

USDDKK

USDJPY

USDNOK

USDSEK

USDSGD

USDZAR

These files will be in a zip format. The first thing you will need to do is un-zip the file. You should now have a .hst file.

Step Two
We now need to prepare MetaTrader for this new data. We change the default max bars in history, in order for our modeling to be more reliable. To do this we go to the tools menu then options or use the keyboard shortcut CTRL+O. The following toolbox should popup:


Click charts tab, now in the charts tab in a field called Max bars in history change that field to 2147483647. (This is the maximum value MetaTrader will accept).


Step Three

Now we are ready to import our data. To do this we go to History Centre. This is in the tools menu or can be accessed via the keyboard shortcut F2, the History Centre screen will pop up as shown below:


Double click on the Forex button shown above this will cause the currency symbols to dropdown. The next step is to double click on the currency you have downloaded the data for. This will open a drop down menu with the different timeframes. Double click on the 1 minute timeframe. Then click on import button and then browse button to locate your .hst file then click OK (Note: If you don’t see your .hst files you need to click the file types dropdown menu in the open dialog box and select MetaQuotes files(*.hst) ). You can now close the History Centre window.

Step Four
Now we have our data imported we need to open it as an offline chart. To do this we go to the file menu and click open offline. This will open a new window click on the one minute timeframe for the currency and then click open. This will then open a new chart as shown below.
One Minute AUD/USDStep Five
The next step is to convert the period using period converter script. To do this with the offline chart shown above, Double click on the period converter script. This will bring up a new window like the one shown below:
Period conversion

You need to click the inputs tab shown above and then in the values field insert the number of minutes you wish to convert the data to, and then click Ok. Do this for the following values 5, 15, 30, 240 and 1440.

Note: There will be no visible change to chart window, however in the log file of the terminal window you can confirm that the records have been successfully written. When you run the period converter script for the second and subsequent times a dialog box will appear asking if you want to replace the current period converter script you need to click yes to convert the next timeframe, make sure the previous period converter script has already finished.

Step Six

Congratulations you got this far preferably without tearing your hair out. Now we have reached our final step testing our new data. We rerun Strategy Tester with our original settings (Make sure the recalculate textbox is highlighted or you will just be using old data). Now sit back with your beverage of choice as Strategy Tester go to work. Remember to always make sure the model you use is every tick (based on all available least timeframes with fractal interpolation of every tick).

Step Seven
Repeat steps 1 to 6 for every currency you wish to test.

Conclusions

As a point of comparison I ran strategy tester with exactly the same settings with Demo data as shown page 2 and the Alpri data shown on the following page. As you can see there is a 30% increase in modeling quality with the Alpri data, this is still only 72.4% modeling quality. This of course is not optimal however it is better then the alternative. In dollar terms using the Alpari data a historical profit of USD$385 was recorded. In contrast using the demo data a profit of USD$470 was recorded. This may seem like a small amount however if the tests were extended to longer timeframes it would be much more significant. A final note back testing is better then no testing however it should be used with caution even with 99.999% model quality and a profitable EA it is no guarantee that your strategy will perform well LIVE. It is always a good idea to forward test with a mini account.

Strategy Tester Report MACD Sample (Alpari)

Bars in test

511

Ticks modelled

994306

Modelling quality

72.41%


Initial deposit

1000.00





Total net profit

387.00

Gross profit

583.00

Gross loss

-196.00

Profit factor

2.97

Expected payoff

21.50



Absolute drawdown

0.00

Maximal drawdown (%)

196.00 (13.5%)




Total trades

18

Short positions (won %)

10 (100.00%)

Long positions (won %)

8 (87.50%)


Profit trades (% of total)

17 (94.44%)

Loss trades (% of total)

1 (5.56%)

Largest

profit trade

50.00

loss trade

-196.00

Average

profit trade

34.29

loss trade

-196.00

Maximum

consecutive wins (profit in money)

13 (452.00)

consecutive losses (loss in money)

1 (-196.00)

Maximal

consecutive profit (count of wins)

452.00 (13)

consecutive loss (count of losses)

-196.00 (1)

Average

consecutive wins

9

consecutive losses

1




Equity curve Alpari

Disclaimer: Forex trading is risky. The high degree of volatility within the Forex market largely within the intraday market, coupled with ability to leverage your positions means that losses can be greater then your initial investment. This article is for educational purposes only and does not constitute financial advice.


Realtime Candle Stick Charting

The following currencies and indexes can be viewed in 1 minute, 5 minute, 15 minute, 30 minute, 1 hour, 4 hour, 1 day timeframes :
AUD/USD, USD/CAD, USD/CHF, EUR/USD, USD/JPY, GBP/USD, GBP/JPY, EUR/JPY, EUR/GBP, INDU, NASDC and S&P500.






Tuesday, May 23, 2006

Monday, May 22, 2006

Learning to trade the EUR/USD

The next six trades I will summarize as one as the are all related. I entered into an initial long position the EUR/USD of 5 lots at 1.2733 20 minutes latter I bought another 5 lots for 1.2736 then three minutes latter I bought two lots at 1.2723 then a minute latter I bought 1 more lot this time for 1.2720 finally ten minutes latter I bought three more lots at 1.2706. Now I have the sum total of 16 lots invested or 1.6 Million USD. Why so many lots you ask? I had extremely strong buy signals backed up by fundamentals. Below shows you the chart:
EUR/USD 1 MillionI scaled out of my positions at the following levels:
  1. 10 lots at 1.2745 or 21 pips
  2. 3 lots at 1.2739 or 51 pips
  3. 3 lots at 1.2730 or 24 pips
This trade ended well with a profit of USD $2280. Looking back at this trade now I think that my risk level was fairly large. My money management is something I need to think about.

The Short EUR/USD
I have included this next trade as it is related to my block of trades above. After exiting my long positions on the EUR/USD I shorted 10 lots at 1.2759 with a take profit 1.2745. This was a short time scalp taking advantage of the volatility. As can be seen in the chart below:
EUR/USD ShortThis trade made a quick 14 pips or USD$1400. The EUR/USD is a very volatile pair. I think I will stick to the AUD/USD for a while longer. So far my current P/L is at USD$4350.

Short AUD/USD Sticking to the plan(At any cost)

If you have read any of my past trades you would see that I have lacked discipline and have acted with fear. This trade I was detrimened to let run NO MATTER WHAT. I sold 3.5 lots at 0.7699. My stop loss was set 0.7710 and my take profit at 0.7694. I thought this would be a quick little scalp. The chart shown below:
scalp AUD/USDAs you can see from the chart above my quick little scalp turned into a USD$385 dollar loss. However despite this loss I am happy as I did not intervene with fear. I let the trade run it's course and even though I took a loss I stuck to my plan.

My First Trade on the EUR/USD

Well what can I say about this trade. I should have never entered it to start with. I sold 3.5 lots 1.2780 with my stoploss at 1.2790 with my take profit at 1.2770 and once again as in my previous post I lot my fear and emotion take over I exited the trade once it came into a small 3 pip gain. This is something that I need to work on. Below is my chart of this trade:
EUR/USD small stepsAs you can see my take profit would have been hit if only I didn't intervene in the trade. I exited with a profit of USD$105.

Lack of Discipline on AUDUSD Short

My Second Trade was a 3.5 lot short on the AUD/USD. I sold at 0.7728 set my stoploss at 0.7755 and my take profit at 0.7715. During this trade I decided to take a small profit early instead of risking the trade turning around on me. The chart is shown below:
AUD/USD Short
As you can see from the chart above if I had the discipline to see this trade out it would have hit my take profit. This trade ended in a profit of USD$140. My running total of profit USD$1050.

AUD Long Past Trades

As I said in my previous posts My old account was deleted. This is my new demo account using SBFX. My First trade was on the Australian dollar I went long at 0.7654. Once my trade started to go into profit I moved my stop loss to 0.7680. Below is the chart:
Australian Dollar LongMy Take profit was 0.7690. As you can see from the chart above my stoploss was hit by volatility. I had 3.5 lots invested therefore I made a profit of $910. From this trade I learnt that at certain times tight stop losses will be hit by volatility.

Friday, May 19, 2006

Removed account

Well it has been a very busy time since my last post. I was a bit annoyed as my InterbankFX demo account was deleted I have since contacted them about this issue to no avail. I have since switched to StratergyBuilderFX version of MetaTrader as they are much more reliable. They also have the spot Gold prices. Below was the last statement I saved from my since deleted account.

Here is the equity curve


Here is the P/L details:

Gross Profit: 3 050.00
Gross Loss: 921.90
Total Net Profit: 2 128.10
Profit Factor: 3.31
Expected Payoff: 106.41
Absolute Drawdown: 0.00
Maximal Drawdown (%): 460.00 (7.0%)
Total Trades: 20
Short Positions (won %): 11 (54.55%)
Long Positions (won %): 9 (100.00%)
Profit Trades (% of total): 15 (75.00%)
Loss trades (% of total): 5 (25.00%)
Largest profit trade: 680.00 loss trade: -260.00
Average profit trade: 203.33 loss trade: -184.38
consecutive wins ($): 7 (1 530.00)
consecutive losses ($): 2 (-460.00)
Maximal consecutive profit (count): 1 530.00 (7)
consecutive loss (count): -460.00 (2)
consecutive wins: 4 consecutive losses: 2

Fairly average returns but it is a learning process.