• Home
  • Free MQL4 Course
  • MQL4 Forums
Forex Mentor Pro
  • Free MQL4 Course
  • MQL4 Made Easy
  • MQL4 Programming
  • Expert Advisors
  • Articles

Improved Input Settings in MQL4 – Part 2

mql4 has easier inputs

In my last article about improved input settings in mql4 I told you about enumerations and how they allow you to utilize drop down menus in your EA's settings. That was certainly a great improvement to the way settings are handled in MQL4 but there's another feature that you should be using.

If you're familiar with the original style of MQL4 coding you've probably used 'extern' variables to facilitate input from users. Since build 600 of MetaTrader 4 there's a new kid on the block.

Input variables or settings can now be declared as either 'extern' or 'input' and the difference between the two is pretty straight forward.

If you intend to change the values of the variable within your code you would declare them as 'extern' just as you did before.

If you intend to change the values of the variable within your code you would declare them as 'extern' just as you did before. Changing the user settings within your code is not really a good idea and could potentially introduce bugs and errors that you didn't account for and are hard to track down.

That's why MetaTrader have introduced the 'input' storage class which is the preferred way to handle external settings. With these types of variables you can not change the values from within your code. This is a better way of handling user settings as it limits them to what they are actually intended for.

If you wanted to change their values from within you code you would have to assign them to other variables that you would then manipulate. This is 'good practice' as it clearly states your intentions within the code and reduces the chance of introducing bugs.

Using the 'extern' storage class won't break your code but if you don't intend to change the values within the code - which you shouldn't really - then consider changing them to the 'input' storage class.

Here's another neat benefit that's been introduced since build 600.

Naming of variables is a whole other topic and one that I'll discuss in another article but there was a glaring issue in the previous version of MT4. Whatever you decided to call your variables would be exactly what the end user would see in their EA settings.

Now depending on how you named your variables this could cause some confusion and the fact that you're not able to include spaces in variable names meant having to seperate them with a dash or underscore.

In the new version you can declare 'friendly names' for the variables in comments immediately after the variable. It's these 'friendly names' that will appear in the EA settings and makes it much simpler for the user.

Here's an example of what I mean...

//| MyFirstEA.mq4 |
//| Copyright 2014, Automated Trading Software |
//| http://automatedtradingsoftware.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Automated Trading Software"
#property link "http://automatedtradingsoftware.co.uk"
#property version "1.00"
#property strict

input double dLots = 0.1;// Size of Lots
input int iTakeProfit = 200;// Take Profit
input int iTrailingStop = 0;// Trailing Stop
input int iStopLoss = 30;// Stop Loss
input int iMagicNumber = 12444;// Magic Number

And here's what the end user sees when they look at their EA settings...

friendly variable names in mql4

This works for all external inputs including 'extern', 'input' and 'enum'.

The new build of MetaTrader 4 is a great improvement on what was already a pretty great coding language. MQL4 is perfect for novice coders and the new additions to the language and programming environment are just the 'icing on the cake'.

If you're interested in learning more about MQL4 then be sure to check out my free MQL4 programming course or my MQL4 Complete Programming Video Training.

Jul 28, 2014Steve Fleming

Steve Fleming

Steve Fleming has been a professional programmer for over 20 years and has programmed in MQL4 almost exclusively since 2007. He has coded 100's of EA's and indicators for his growing list of satisfied clients and has helped 1000's of people learn how to code their own EA's.

If you would like to have your strategy coded by Steve Fleming or receive one-on-one training, then please send an email to [email protected] .

More Posts



Keltner Pro
How to Install MQL4 Experts Advisors, Indicators and ScriptsDoes The Perfect EA Really Exist?
Comments: 6
  1. Beatrice Lafferty
    August 7, 2014 at 1:17 am

    I’ve read both your articles about the new input settings and I have to agree. I think this new version of mql4 is pretty good and can’t really see what people are complaining about. Keep up the good work.

    ReplyCancel
    • Steve Fleming
      August 7, 2014 at 7:33 am

      Thanks for your comment Beatrice and I’m glad you’re having success with MQL4. – Steve –

      ReplyCancel
  2. Frank K
    August 7, 2014 at 8:55 pm

    Having looked at both mql4 and mql5 I have to say that mql4 is MUCH easier for me to learn. I’m totally new to coding and have nevver done anything like it before. I was a bit scared at first but with the help of your tutorials I soon got used to it.

    Frank K

    ReplyCancel
  3. Linoel Ellsworth
    August 10, 2014 at 7:03 am

    If I send you my strategy can you code it for me Steve? If so how much would it cost me?

    ReplyCancel
    • Steve Fleming
      August 13, 2014 at 3:01 pm

      Linoel – Sorry for the late reply. Yes I can code your strategy for you. All you need to do is send me an email outlining the details of your system and exactly what you’d like the EA to do.

      You can email me at steve(AT)automatedtradingsoftware.co.uk

      Look forward to hearing from you soon.

      Steve

      ReplyCancel
  4. Dulcy Tsosie
    August 11, 2014 at 8:37 am

    Great article Steve and exactly what I was looking for!

    ReplyCancel

Leave a Reply Cancel reply

July 28, 2014 6 Comments MQL4 Programming build 600, extern, input, mql42,741
Forex Mentor Pro
Start Learning MQL4 Today!
Recent Posts
  • Instantly Save Yourself $200
  • How to Create a Simple Toggle Button in MQL4
  • Does The Perfect EA Really Exist?
  • Improved Input Settings in MQL4 – Part 2
  • How to Install MQL4 Experts Advisors, Indicators and Scripts
Recent Comments
  • Steve Fleming on Free Tool to Help With Pair Trading
  • Pedro Paredinha on Free Tool to Help With Pair Trading
  • shelton colds jr on R.E.A.D – A Simple Template Approach to Coding in MQL4
  • Steve Fleming on Improved Input Settings in MQL4 – Part 2
  • Dulcy Tsosie on Improved Input Settings in MQL4 – Part 2
Tags
mql4expert advisorsbuild 600metatraderforexexpert advisorindicatorsscriptsinputautomated trading software
GPS Forex Robot
MQL4 Programming

Learning to code in MQL4 can seem difficult at first but once you get the hang of it you'll find it quite easy. The best way to get started is with a free course and you'll find a great one [...]

| 6 Comments Learn More
Testimonials
Working with Steve has really cleared the fog for me as it relates to writing my own EA’s. I had no prior code writing experience. Prior to working with Steve, I had bought every book available on MQL, read lots of blogs and downloaded pdf lessons. But, none of these resources could answer any of my questions. Working with Steve has given me a much broader understanding of how to write code. He not only teaches you how to write an EA, but explains the best coding practices so you are writing cod… Read more
MichaelIdaho
I came to Steve with the aim of learning how to write expert advisors. With his great teaching style and structured course I have been able to learn an enormous amount and have been able to write a number of expert advisors myself. As I develop various systems and sometimes come across issues Steve is always a great source of help. I look forward to developing more expert advisors and using Steve as a mentor as and when required.
AlanSingapore
After extensively researching around for a coach to fast-track my ability to code Expert Advisors, I came across Steve Fleming. Right from the beginning I found Steve to be very helpful and motivating, within five weeks of coaching I am coding my first EA. Programming is just like any other skill in life, it takes time to learn and I know without a coach like Steve, it would have taken me months to learn MQL. Most importantly what I found in Steve is someone who wants to see you succeed as a … Read more
DeonBrisbane
Market Hours
© Automated Trading Software  2008 - 
Contact |  Sitemap |  Risk Warning |  Privacy |  T & C

Free MQL4 Course

Enter your best email address in the box below and get my 5 day MQL4 course immediately!

Arrow