Articles by: David Williams

What’s the difference between an Expert Advisor and an MQL Script?

Expert Advisor vs. MQL Script

What’s the difference between an Expert Advisor and a Script?  I get this question a lot.

Both are written in MQL, so they both have access to the library of MQL functions for opening and closing trades, finding indicator values and even sending emails.

One difference is that Scripts are located in their own folder underneath the “experts” folder on your computer.

Also, Scripts appear under their own menu in the MetaTrader platform.

But, the biggest difference is that a Script executes just once, while an Expert Advisor executes each time a new price value is received.

Yeah, I know that last part is a mouthful:  “executes each time a new price value is received”.

This is how it works:  Your Expert Advisor, physically located on your computer, waits for new price data to be sent from the broker’s server.

metatrader-tick

When new price data is received, your Expert Advisor executes.  If there isn’t any new price data, your EA does not execute.

You might have noticed that when the market is slow your EA does not run.  This behavior is correct!

EA’s are designed to execute their logic based on changes in price.  (Remember, a change in price will usually lead to a change in an indicator value.) If there is no change in price, there is no reason for the EA to execute.

But there’s a subtle by-product of this behavior that you should be aware of.

If your EA contains logic that is solely based on time, it may not execute exactly the way you planned.

Suppose your EA is designed to open a trade at 8:00, but the market is slow and there is no price movement at that time.  Well, it ain’t gonna happen.  Not at 8:00.

Because your EA will not even execute if there is not a change in price.

But, if your EA is written correctly,  it will execute on the next price change after 8:00.

Honestly, this is usually not a big deal.  That trade scheduled for 8:00 will normally be opened within a few seconds of 8:00.

Still, it’s good to be aware of these nuances. You should understand the behavior of your EA under any market condition.

If you’re interested in more of this kind of information, I’ve put together a free email course that spoon-feeds MQL .

You can sign up here:

http://www.iexpertadvisor.com/free-metatrader4-mql-course.html 

Really Bad Trade Entry? Find Out With This Quick Test

Test Your Trade Entry

On page 2 of the How To Test Robots PDF,  I describe a technique for testing the quality of your trade entry.

The “Entry Test” immediately tells you if your entry logic is any better than just randomly entering the market.

This test is brutal. You would not believe how many indicator-based systems use entries that are no better than random!

The technique is simple.  You replace your normal exit logic with a “bar exit”.  A “bar exit”  will close a trade after it has been open for a number of bars.

The “bar exit” does not rely on profit or loss.  It simply closes the trade.  You run this on a back-test and then count how many trades were profitable.

You don’t care about how much profit.  You’re just looking  to see if the trade was at a profit or loss when it was closed.

The more trades closed profitably, the better the entry.  At the very least, your entry should score higher than 50%.

I add the “bar test” to all of my EAs.  It’s pretty easy.  I show how in the PDF.

Note:  If you haven’t had a chance to read it yet, here is the link to the  How To Test Robots PDF

PDF