Skip to content
← All posts

EA Source Code

EA Input Parameters in MQL5: How to Change Defaults in Source Code

EABuild Team · · 12 min read

EA Input Parameters in MQL5: How to Change Defaults in Source Code – EABuild

Every expert advisor exposes a list of settings, and EA input parameters are the part of an MQL5 program that you can change without touching its trading logic. This post explains how those parameters are declared in the source file, what the keywords input and sinput mean, and how to edit a default value, recompile and test the result. It also covers the habits that keep an edit reversible: a backup, one change at a time, and a record of what you altered.

What EA input parameters are in an MQL5 program

When you attach an expert advisor (EA, a program that places trades automatically) to a chart, MetaTrader 5 opens a window with an Inputs tab. Each row in that tab is one input parameter: a name, a value and sometimes a drop-down list. Those rows come from lines near the top of the source file that start with the keyword input.

A line such as input double LotSize = 0.10; declares a variable named LotSize, of type double (a number with decimals), whose default value is 0.10. The default is what you see in the window the first time you attach the EA, and what you get back when you press Reset. Inside the program the variable is read-only: the code can use LotSize but cannot assign a new value to it while it runs. That is why inputs are the intended place for settings.

Default value versus the value you actually run

The default in the source and the value on your chart are two different things. If you type 0.05 into the Inputs tab, the chart runs with 0.05 while the source file still says 0.10. MetaTrader stores your typed value with the chart, not in the code. Editing the source changes only the starting value that the next fresh attachment shows.

This matters when you change a default and see no difference. A chart that already carries the EA keeps the values it was given, so you have to remove the EA and attach the rebuilt one, or load the values again from a set file (a saved list of input settings you load in MetaTrader).

Reading the input block: types, comments and groups

Open any MQL5 EA and you will usually find a block of input lines before the first function. Reading it carefully tells you most of what you need before you change anything.

Common types you will meet

  • int holds whole numbers, such as a count of bars or a magic number (a number that tags an EA's orders so it can find them again).
  • double holds numbers with decimals, such as lot size or a distance expressed as a price value.
  • bool is true or false and appears as a drop-down with those two choices.
  • string holds text, for example a comment attached to orders or a symbol suffix.
  • enum types show a list of named choices, such as a timeframe or a mode. The names come from an enumeration declared in the code, and you cannot type a value that is not on the list.

The comment that becomes the label

A comment written after an input line, starting with two slashes, is shown as the row's label in the Inputs tab instead of the variable name. The line input int MaxSpread = 30; // Maximum spread allowed appears as the text after the slashes. Changing only the comment changes only what the window displays, never how the program behaves. Be aware that a clear label does not always mean a clear unit: check how the code uses the number before you assume it is points, pips or money.

Groups

MQL5 lets an author gather related inputs under a heading with a line such as input group "Risk settings". The heading appears as a divider row in the window. It has no effect on trading and only organises the list.

input or sinput: what the difference changes

The keyword sinput declares a static input. It appears in the Inputs tab exactly like a normal input and can be loaded from set files, but the Strategy Tester leaves it out when you run an optimisation (a series of test runs that vary chosen inputs). An author uses sinput for values that should not be varied, such as a magic number or a comment text.

For editing defaults this has one practical consequence. If you change input to sinput on a line, or the reverse, you change whether the optimiser can vary that value, not what the value is. Leave the keywords as the author wrote them unless you have a reason and understand the effect. The MQL5 documentation describes input variables and their rules in full if you need the exact syntax.

Preparing before you change a default in MQL5 source

A small edit can look harmless and still alter how an EA trades, so prepare before you open the file. Most mistakes at this stage come from skipping the backup, not from the edit itself.

  1. Copy the unedited source to another folder. Keep that copy untouched and give it a clear name. It is your way back if an edit goes wrong.
  2. Keep the supplied set files. If the download includes set files, leave them as they are and save your own variations under new names.
  3. Work on a test copy. Edit a duplicate of the file, with a new file name, so the compiled program does not overwrite the one you already run.
  4. Note the starting values. Write down each default before you change it. A short text file with the line, the old value and the new value is enough.
  5. Know the symbol and timeframe. The values were chosen for a specific market and chart period. A distance that suits one symbol can be far too large or small for another.

If the file is a download and you are not sure what the package holds, our guide to MQ4 and MQ5 source code explains how source and compiled files relate.

Steps to change an input default and recompile in MetaEditor

These steps assume the source file sits under the MQL5 folder of your MT5 data folder, in the Experts subfolder. You reach the data folder from the terminal with File, then Open Data Folder.

  1. In MetaTrader 5 press F4 to open MetaEditor.
  2. In the Navigator panel expand MQL5, then Experts, and double-click the .mq5 file of your test copy.
  3. Scroll to the block of lines that start with input or sinput. Use Ctrl+F to search for the word if the file is long.
  4. Change only the value after the equals sign. In input double LotSize = 0.10; you would replace 0.10 and keep the semicolon, the type and the name exactly as they are.
  5. For a drop-down input, pick a value that already exists in the enumeration. Do not type a new word on the right side.
  6. Press Ctrl+S to save, then F7 to compile.
  7. Open the Errors tab at the bottom. You want zero errors; read any warnings too.
  8. Back in the terminal, refresh the Navigator (or restart MT5), remove the old EA from the chart, and attach the rebuilt one.
  9. Open the Inputs tab and check that the row now shows your new default.

If you want a fuller walk-through of the build step and its error messages, see how to compile MQ5 in MetaEditor.

When the build fails after a small edit

The usual causes are a missing semicolon, a deleted quotation mark in a text value, or a decimal typed with a comma instead of a point. MQL5 expects a point as the decimal separator. Undo with Ctrl+Z, or compare against your backup, and make the change again more slowly.

What to leave alone when you edit EA inputs

Changing a default is not the same as changing a strategy, and the line between them is worth keeping clear. A value such as the lot size, a time window or a spread limit is a setting the author expected people to adjust. Anything beyond that, such as editing the code that decides when to open or close a trade, changes the program itself.

  • Do not rename an input. A saved set file refers to inputs by name. Rename one and an old set file may fail to apply that value, leaving it at the default without telling you.
  • Do not remove an input line that the code still uses. The build will report an undeclared identifier.
  • Do not change the type from int to double or the reverse unless you check every place the variable is used, since a value can be cut or compared in unexpected ways.
  • Do not describe an edited version as the unedited product. Once you change code, the behaviour is yours to test. Nothing that a listing says about the unedited EA applies to your edited build.

Nobody can promise that an edited EA will behave as the unedited one did, and a changed default can raise or lower the exposure the EA takes. Treat each edit as a new configuration that needs its own testing.

An example: reading the inputs of Smart Gold Hunter source code

A source code download gives you a concrete file to practise reading. The Smart Gold Hunter EA Source Code (MQ5) package is a MetaTrader 5 product at version 3.5. As listed, it is designed for XAUUSD on M5 and M15, and the listing describes the strategy as scalping, news trading and hedging. The download holds one compiled file, one source file and six set files, and no DLL is used.

The set files matter for this topic. Each is a starting configuration for the EA's inputs, not a recommendation of results. Before you edit a default in the source, load one set file and look at the Inputs tab, then open the source and find the same names in the input block. That comparison shows you which values a set file overrides and which stay at their coded default.

The listing gives a recommended minimum deposit of $100 and marks the EA as built with prop-firm challenge rules in mind. If you plan to use an edited copy on a prop firm account, check the firm's rules on EAs first, since rules differ between firms and an edited build is not what the listing describes. For loading the six files, the guide to loading a set file in MT4 and MT5 covers each step.

Testing an EA after you change input parameters

A clean compile only proves that the grammar is correct. It says nothing about how the EA trades with your new value. Work through these checks before the edited build goes near real money.

  1. Confirm the default. Attach the rebuilt EA to a fresh chart and verify each changed row in the Inputs tab.
  2. Read the Experts tab. Open the Toolbox with Ctrl+T and look at the Experts tab for initialisation messages or errors.
  3. Run the Strategy Tester. Test the edited build against the unedited one on the same symbol, timeframe and period, changing only one input between runs. Tester results use stored price data and tell you nothing certain about the future.
  4. Use a demo account. Let the EA run on demo long enough to meet different spreads and fast markets, as the broker's conditions differ from the tester's.
  5. Check the settings again. Before any live use, compare lot size, spread limits and account type with your broker's contract details.

Keeping a change log

Name each build so you can tell them apart, for example the EA name plus a date or a short version note. Keep the note file next to the source. When a result surprises you, the log tells you exactly which value moved, and you can return to the backup in seconds.

Common problems when EA inputs do not behave as expected

The Inputs tab still shows the old default

Either the old compiled file is still on the chart, or you compiled a different copy from the one the terminal reads. Check the file under the data folder you opened with File, Open Data Folder, then remove and re-attach the EA.

The Inputs tab shows no rows at all

An EA with no input lines has nothing to show, and some programs declare settings with plain global variables instead. Those cannot be changed from the window and need an edit in the source.

A set file no longer applies a value

This usually follows a renamed or retyped input. Restore the earlier name and type, or save a new set file from the Inputs tab of the rebuilt EA.

The EA trades differently on another broker

Values such as stop distances and spread limits are measured in points, and brokers differ in digits, spreads and contract size. A default that suits one account can behave differently on another, so test on the account type you will use.

Practising input edits on a demo account this week

A good first exercise is small: copy a source file, change one default, compile, and compare the Inputs tab before and after. Keep the backup and the change log, and test on a demo account first. You can browse the EA source code downloads if you want more files to read, and every product in the shop is included in the membership. This shop sells digital downloads and is not the developer of the products.

Trading foreign exchange and CFDs carries a high level of risk and may not be suitable for all investors. Past performance does not guarantee future results; only trade with money you can afford to lose.

Tags: EA Source Code, MQL5, MetaEditor

← All posts

Get every EA with membership

313 products · from $16.59/month

See plans

More in EA Source Code

How to Compile MQ5 in MetaEditor and Fix Common Errors – EABuild

EA Source Code

How to Compile MQ5 in MetaEditor and Fix Common Errors

Follow the steps to compile MQ5 source code in MetaEditor, read the Errors tab, and fix the messages that stop most first builds, from missing include files to undeclared variables.

· 9 min read