Investment Trends CFD survey results

March 5th, 2010

Investment Trends recently carried out an online survey where they questioned 3236 people from the United Kingdom about their CFD and spread betting habits.

They asked the participants about how trading fits into their overall investment strategy, how they decide on what trades to place, and how they have done in the volatile previous 12 months amongst other questions.

They have released some highlights from their survey in a PDF which you can view from here.

Bookmark and Share

MQL4 helper functions for calculating bar sizes

February 21st, 2010

Here are some more MQL4 helper functions for MetaTrader. You can use them in your expert advisors and custom indicators. The three functions will allow you to quickly get the size of the upper and lower wicks of the candle stick, and also the size of the candle stick body. To use them you will also need some of the code I gave you in my simple MetaTrader MQL4 helper functions post.

If you use these functions in your code please give a reference to this blog post.

double UpperWickSize(int bar)
   {
   if (UpBar(bar))
      {
      return (High[bar]-Close[bar]);
      }
   if (DownBar(bar))
      {
      return (High[bar]-Open[bar]);
      }
   return (0);
   }

double LowerWickSize(int bar)
   {
   if (UpBar(bar))
      {
      return (Open[bar]-Low[bar]);
      }
   if (DownBar(bar))
      {
      return (Close[bar]-Low[bar]);
      }
   return (0);
   }

double BarBodySize(int bar)
  {
  if (UpBar(bar))
    {
    return (Close[bar]-Open[bar]);
    }
  if (DownBar(bar))
    {
    return (Open[bar]-Close[bar]);
    }
  return (0);
  }
Bookmark and Share

Simple MetaTrader MQL4 helper functions

January 30th, 2010

Here are some simple functions that you can use in your forex expert advisors and custom indicators written in MQL4 for MetaTrader.

If you split out commonly used functionality into separate functions with logical names (as I’ve done here) then you should find that your MQL4 code becomes more readable.

If you use these functions in your own code please reference this blog.

// returns the value of the top of the bar
double TopOfBar(int bar)
   {
   return (MathMax(Open[bar], Close[bar]));
   }

// returns the value of the bottom of the bar
double BottomOfBar(int bar)
   {
   return (MathMin(Open[bar], Close[bar]));
   }

// true if this is a down bar
bool DownBar(int bar)
  {
  return (Close[bar]<Open[bar]);
  }

// true if this is an up bar
bool UpBar(int bar)
  {
  return (Close[bar]>Open[bar]);
  }

// size of whole bar including the wicks
double HighLowSpread(int bar)
   {
   return (High[bar]-Low[bar]);
   }

// gives you the result of subtracting the lowest input value from the highest
double HighMinusLow(double value1, double value2)
   {
   double high = MathMax(value1, value2);
   double low = MathMin(value1, value2);
   return (high-low);
   }

Hope you find these useful.

Bookmark and Share

Disadvantages of expert advisors

January 15th, 2010

Following on from my advantages of expert advisors post here are some disadvantages of trying to write and use expert advisors.

Curve fitting

Because it is easy to backtest expert advisors many times with different parameters it is very easy for them to suffer from curve fitting.

Curve fitting means that the EAs are highly optimised for the specific period of time for which they have been tested against, but may turn out to be loss making if run on actual live data.

A good expert advisor will not need to be micro-optimised in order to make a profit. There may well be certain values that perform better than others, but a range of values around the optimal ones should also be profitable to prove that the expert advisor isn’t just working because of some very specific circumstances that are unlikely to occur again in future.

As well as curve fitting the parameters it is very tempting to add new code branches into the expert advisor to filter out bad trades and allow though good trades. Again this is likely to produce an expert advisor which is highly optimised only for the historic data on which you are testing it.

Curve fitting over-optimisation is a very easy trap to fall into when writing expert advisors. It is a waste of time, as you won’t end up with a profitable expert advisor. Spend that time on writing quality expert advisors which can handle whatever data you throw at them.

Unrealistic backtests

Many pieces of trading software that allow you to backtest EAs do not allow you do it in a way that realistically simulates the real market. Doing so would be very difficult because there is a lot more information you need to know other than the price. E.g. you need to know about the spread, execution delay, slippage, and liquidity.

Backtesting data does not tend to give you access to this kind of information. In addition the granularity of backtest data is often much less fine than what you would get if you were trading live.

Most backtesting data is only available for 1 minute and above timeframes. This means that you miss out on the tick-level information that could be essential, especially if your trading strategy works on shorter timeframes.

Many backtesting software packages compensate for this by ‘filling in the gaps’, and create simulated ticks. This can be dangerous, as the algorithm used may well not generate ticks in a way that is realistic enough for your strategy.

It is quite possible (in fact easy) to create an expert advisor that works brilliantly on historical data using a backtest but consistently loses when used for real.

Difficult to write

Translating a working strategy from your brain into an expert advisor can be very difficult.

When you trade manually you can interpret huge amounts of data and news in a way which can be very difficult for a computer program to do. Interpreting simple facts such as the value of an indicator is easy for an EA to do. However interpreting something such as the current economic climate or the latest news that has just been released is extremely difficult.

Getting EAs to recognise complex chart shapes and patterns can be very difficult. It is all to easy to program the EA to recognise specific patterns that occurred in the past rather than getting it to understand the meaning of the chart patterns in the way that your brain will.

Expert advisor bugs

All software beyond trivial code snippets will contain bugs. For most pieces of software the consequences won’t be too bad. Maybe the program will crash, get stuck, or if you are unlucky perhaps you will lose some work.

Expert advisors for forex and CFDs are somewhat different as they have the power to make decisions that affect your bank balance! If your EA has a bug then it could make the wrong decision resulting in a loss of money. If the bug is bad then maybe you’ll lose a lot of money!

Would you trust a piece of computer software to buy and sell on your behalf? Even if you have done large amounts of testing how can you be sure that your EA won’t trip up when it is left to run by itself?

As EAs are often left to trade by themselves, any bug or defect in the code could be very costly. You might not spot that anything is wrong until you find your account has been emptied of all its money.

Think carefully before you let an EA lose on your live account. Make sure it is well tested, and keep a careful eye on what it is doing. To avoid it losing too much in the event that it doesn’t work as expected make its trade sizes small to start with and don’t keep to much money in your account.

Conclusions

Before you spend time creating an expert advisor make sure you don’t fall into any of the problems listed above. Doing so could cost you serious money.

Bookmark and Share

Forex New Year’s resolutions for 2010

December 24th, 2009

1. Write down my plan for each trade before pressing the buy/sell button. The plan will include the reason for why I am doing the trade, the expected profit, the initial stop loss and the expected duration of the trade.

2. Double-check the order quantity before executing the trade. It is too easy to lose money by buying or selling the wrong amount of currency.

3. Ensure that all trades have an explicit stop loss added to them.

4. Spend more time working on my expert advisor framework in MetaTrader MQL4.

5. Contribute more to the forums at Trade2Win and babypips.

6. Spend less time reading trivial financial news – it does not help! But be more aware of major currency related announcements.

7. Read more quality trading books and review them here.

8. Add more content to this blog – http://www.tradingdiary.co.uk/. Will be adding more posts about writing expert advisors using MetaTrader MQL4, more on risk management, and more general trading advice.

Do you have any forex New Year’s resolutions? If you do, let me know by using the comment box below.

Merry Christmas and a Happy New Year!

Bookmark and Share