Post Tagged with: "mql course"

How to Resolve an MQL Syntax Error

How to Resolve an MQL Syntax Error

Inspect the Error message, then locate & fix the problem

The VTS output tab will show the exact MQL syntax error:

Although this shows the exact location of the error in the MQL file, this information may not be very helpful, especially with a large system.

To find out more, click the Editor button to launch the MetaEditor. Then press F7 in the MeteEditor – this will build the EA.  The same error message is shown in the MetaEditor’s Error tab:

When you double-click the error, it will bring you to the exact location of the error in the MQL file.

In this case the error is associated with the MQL Variable named Variable1

Now you can inspect that Element on your VTS drawing:

The assignment field of the Variable1 Element contains a semi-colon (;). This is not valid MQL syntax, so it causes the MQL build to fail.  Changing the semi-colon to 0 (zero), or some other value will fix the error.

Every error is a little different , but the objective is the same: find the general location of the error and then make changes to see if the error is resolved.

 

Important Note: The first time you click the Editor button in VTS, the MetaEditor is launched and the Expert Advisor for the current VTS system is  loaded into the MetaEditor.  But, and this is significant, if you make changes to your VTS drawings and rebuild by clicking the Build button, the MQL file in the MetaEditor will not be refreshed. You need to close the file in the MetaEditor and then reopen it to see the latest changes. There is simply no facility that VTS can use to instruct the MetaEditor to reload a file.  We had a sloppy work-around in a previous version of VTS, but changes were made to the MT platform (around build 400) that caused the work-around to break.

Final points:

  • This is a  handy trick:  If an Element is not connected (using a link) on the VTS drawing pad, it will not be included in the MQL code and therefore will not be built. So you can temporarily remove the links to/from an Element and re-build.  If the error is gone, then the problem was caused by the excluded Element.  Also, you can remove all links – just connect the Start Element to an End Element, and rebuild as you add each Element back to the drawing one at a time.
  •  You can get more information about the MetaEditor in this post.
  • We offer a free email MQL course. Through a series of emails, it teaches you how to program MetaTrader4 Expert Advisors. No strings attached, just a bunch of emails spaced out over a few weeks.
  • I’ve written an ebook on how to learn MQL: MQL For Traders

 

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