MetaTrader4 - Expert Advisors, Indicators and Scripts
MetaTrader4 - Expert Advisors, Indicators and Scripts
This post is for those of you who wish to try out an Expert Advisor, Indicator or Script but aren't too sure where to start.
First, some background information. These are "add ons" that you can use within Metatrader4 (MT4). They are created by writing a set of rules and commands using Metatrader Query Language (MQL) which is quite similar to modern day computer languages (e.g. C++, Java). The code you write (Source Code) is stored in a file with a suffix of MQ4.
Once the code has been written it is "processed" into a format that the computer/MT4 can understand better. This is called compiling and generates a file with the suffix of EX4.
So, a simple file called MyIndicator.MQ4 would also have a MyIndicator.EX4 file.
To use the code within MT4, all you need is the EX4 file, however you will not be able to edit or look at the original source code without the MQ4 file.
(NOTE! When you get spam email from trading sites saying, "I've got this great money making scheme for only $99.97 - if you hurry", you'll almost certainly only ever get the EX4 file. Oh - and it'll probably make more money for the seller than you!)
So - what are the differences between the types of file...
Expert Advisors (EA's)
These are programs that are designed to automate the trading process by identifying where to enter trades, how many lots to buy/sell, where to place stops/targets and how it will trail any position to maximise potential profit. They generally update every time a new tick arrives.
Sounds great doesn't it.
The problem is, when a human looks at a chart, there is frequently a large amount of subjective data that the human can make sense of easily. e.g. a Human might say, enter when the fast MA crosses the slow MA and the RSI is NEAR 50. But what does NEAR actually mean? The EA likes to work with absolutes, and some of the things we lack in trading are absolutes.
Consequently, putting all the rules that you use for entering/managing a trade into an EA is not always straight forward, often produces unexpected results, and can easily lead to "curve fitting" e.g. optimising the output of the EA to return as high a profit as possible but only for a specific set of circumstances.
These allow you to create variations of existing indicators or completely new ones based on whatever set of rules you wish and to display them on the charts or below in the data windows. Indicators cover such things as moving averages, histograms, plotting text above/below bars and changing bar colours based on the coded rules. These are adjusted every time a new tick arrives but depending on the nature of the data being processed may need a certain number of bars to have been posted (e.g. a 10 period MA will need at least the previous 10 bars to provide a value).
Scripts are "one hit" pieces of code - usually. The idea is that you drop a script on a chart, it does it's work and that's it. This can be altered however (e.g. the DOM is initiated via a script, but it doesn't disappear.
So - I've got these file things, where do I put them?
I'll approach this from the perspective of code that has been attached to a post in the forum, but the principal works the same if you get an Indicator/EA/Script from some other source.
So we have something to test with I've attached an indicator I have made changes to based on the MACD (For Info - it brings it into line with other packages such as TradeStation but can also display the same as the MT4 versoin).
The three types of file (Experts, Indicators, Scripts) all have their own place to "live" within the MT4 directory structure. To begin with, where does MT4 live
For those of you that have not yet installed the very latest version of MT4, you will find MT4 here... (probably - there will always be an exception :-)
(for XP, 32 bit Windows) C:\Program Files\MT4 Quant powered by Divisa Capital
(for Windows 7 64 bit) C:\Program Files (x86)\MT4 Quant powered by Divisa Capital
If you have the very latest version you will find the install directory... I'll use this as the default for the rest of this post.
C:\MT4 Quant powered by Divisa Capital
If you have an Expert Advisor (EA) you will need to place the files here...
C:\MT4 Quant powered by Divisa Capital\experts
If you have an Indicator it needs to go here...
C:\MT4 Quant powered by Divisa Capital\experts\indicators
If you have a Script it needs to go here...
C:\MT4 Quant powered by Divisa Capital\experts\scripts
For our example files we need to put them into the indicators directory.
To do this, right click on the dcm_MACD_Col.ex4 file. You will have a small pop up menu appear. One of the options will be "Save Link As" (Firefox) or "Save Target As" (Internet Explorer) (something similar for Chrome and other browsers).
Choose this option and it will present you with a dialog that allows you to navigate to the directory as specified above (i.e. ...experts\indicators).
Click on Save and the file will be saved in the correct location. Now do the exactly the same with the dcm_MACD_Col.mq4 file.
Ok - so I've Saved the file - how do I find it in MT4?
If you have MT4 already open, you will need to close it and restart it.
When restarted you should see the indicator listed under the Custom Indicators section of the Navigator Window. From there it's just a case of dragging and dropping it onto a chart.
Expert Advisors will appear under.... Expert Advisors
Scripts will appear under Scripts
Possible Problems #@!!$%!!!
Sorry - sometimes things just don't work as you expect. Possible problems are...
I'm seeing weird characters on the screen (or - I can see the code of the indicator). You most likely left clicked instead of right clicked on the file. go back one page on your browser and try again.
I can't save the file due to some permission restriction. Most likely you have Windows User Access Control (UAC) turned on or are using a machine where you do not have administrator priviliges. If you get this - put a post in the forum and myself or some other bee will help.
I can't see the (EA/Indicator/Script) - be careful where you save the file. Most likely you've put it in the Experts directory.
Any other problems - put a post in the forum.
Hope this helps - David