Downloading a free EA download is easy, but what if the stop loss is too tight? Or the lot size too large? This guide teaches compile and modify skills for any MQL4 EA. You don‘t need to write code from scratch – just learn to modify parameters and recompile.
What You Can Change in Any EA
| Parameter | Typical Line to Find | Safe Range |
|-----------|---------------------|-------------|
| Stop Loss | `StopLoss = 30` or `SL = 50` | 20-200 pips |
| Take Profit | `TakeProfit = 100` or `TP = 150` | 50-500 pips |
| Lot Size | `Lots = 0.1` or `FixedLot = 0.05` | 0.01-1.0 |
| Magic Number | `MagicNumber = 12345` | Any unique number |
| Risk Percent | `Risk = 2.0` or `RiskPercent = 1` | 0.5-3.0 |
| Time Filter | `StartHour = 8`, `EndHour = 17` | 0-23 |
Step 1: Open the EA Source Code
1. Launch MetaEditor (F4 in MT4).
2. Click File → Open or press Ctrl+O.
3. Navigate to `Experts` folder and select the `.mq4` file.
4. The source code appears – look for `input` or `extern` keywords.
Step 2: Understand Input Parameter Syntax
```cpp
// Common parameter formats you‘ll see:
input double Lots = 0.1; // Modern MQL4
extern int StopLoss = 50; // Older style (still works)
double TakeProfit = 100; // Fixed internal value (harder to change)
```
Step 3: Modify Stop Loss and Take Profit
Before modification:
```cpp
input int StopLossPips = 30; // Too tight for GBPUSD
input int TakeProfitPips = 80;
```
After modification:
```cpp
input int StopLossPips = 60; // Wider stop for less noise
input int TakeProfitPips = 160; // Larger target
```
Step 4: Modify Lot Size and Risk
Fixed lot version:
```cpp
input double FixedLotSize = 0.1; // Change to 0.05 or 0.2
```
Money management version:
```cpp
input bool UseMoneyManagement = true;
input double RiskPercent = 2.0; // Change to 1.0 for safer, 3.0 for aggressive
```
Step 5: Common Compilation Errors and Fixes
| Error Message | Cause | Fix |
|---------------|-------|-----|
| `‘variable‘ - undeclared identifier` | Typo in variable name | Check spelling matches |
| `‘OrderSend‘ - function not defined` | Missing #property strict | Add `#property strict` at top |
| `‘return‘ - parameter mismatch` | Wrong return type | `OnInit()` returns int, `OnTick()` returns void |
| `end of file found without final‘}‘` | Missing closing brace | Count opening and closing `{}` |
| `‘EMPTY‘ - can’t convert enum` | Wrong constant | Use `EMPTY_VALUE` instead of `EMPTY` |
Step 6: How to Recompile (F7)
1. After making changes, press F7 or click Compile button.
2. Watch the bottom pane for errors (red) or warnings (yellow).
3. Success message: *“Compilation successful – 0 error(s), 0 warning(s)”*
4. If errors appear, double-click them to jump to the problem line.
Step 7: Test Your Modified EA
1. In MT4, open Strategy Tester (Ctrl+R).
2. Select your EA from the dropdown.
3. Choose a pair and timeframe (e.g., EURUSD H1).
4. Click Start – watch if the EA opens trades with your new settings.
Real Example: Modifying a Moving Average EA
Original code snippet:
```cpp
input int StopLoss = 40;
input int TakeProfit = 120;
input double Lots = 0.2;
input int Magic = 999;
```
Modified version (safer for small accounts):
```cpp
input int StopLoss = 60; // Increased from 40
input int TakeProfit = 180; // Increased from 120
input double Lots = 0.05; // Reduced from 0.2
input int Magic = 1001; // Changed to avoid conflict
```
Advanced Modification: Add a Simple Filter
Find the `OnTick()` or `OnStart()` function and add:
```cpp
// Add spread filter after existing code
if(MarketInfo(Symbol(), MODE_SPREAD) > 30 * Point)
{
Print("Spread too high. Skipping trade.");
return;
}
```
Then recompile (F7).
EA Debugging Tips
This MQL4 tutorial gives you the power to modify parameters and compile and modify any EA you download. For professional-grade EAs with full source code access and premium support, subscribe to our EA Library – updated weekly with ready-to-modify strategies.
Reference: AutoCompile AI – Complete EA modification and compilation guide, 2025.