Skip to main content

How to Debug Your Bot and Understand Error Codes

Debug your EA by understanding Builder errors, MT5 Journal messages, runtime issues, permissions, invalid stops, stack overflow, missing data, and Visual Mode testing. Learn what each error means and how to fix it.

Summary

If your bot is not trading, your backtest fails, or you see an error message, start with the Journal and identify where the problem happens.

Most issues fall into one of three categories:

  1. Builder/project errors
    Something is wrong inside your project setup, for example an invalid variable name, missing value, duplicate input, or incomplete block.

  2. MT5 runtime errors
    The EA exported correctly, but MT5 cannot execute something during the backtest, demo, or live run.

  3. Account, permission, or environment issues
    The bot may be correct, but MT5, the broker, the account type, Algo Trading permissions, or VPS setup prevents it from running.

This guide helps you find the issue, understand the error, and fix it step by step.

Also known as: bot not trading, MT5 error, EA not working, backtest error, Journal error, compile error, runtime error, invalid stops, stack overflow, project error code.


First: where is the error happening?

Before fixing anything, identify where the issue appears.

If the error appears inside the Builder

This is usually a project configuration error.

Common examples:

  • Invalid variable or input name

  • Duplicate variable name

  • Empty Formula block

  • Empty Modify Variables block

  • Wrong value type, for example text inside a number field

  • Variable renamed but old references still used

These issues must be fixed inside the project before exporting again.


If the error appears after export in MT5

This is usually an MT5 runtime error.

The EA may have exported correctly, but MT5 cannot place or manage a trade because of:

  • Not enough margin

  • Invalid stop loss or take profit

  • Market closed

  • Trading disabled

  • Invalid lot size

  • Missing indicator data

  • Broker restrictions

  • Too much test data

  • Logic loop or stack overflow

These issues are found in the MT5 Journal.


If the bot works in demo but not live, or live but not demo

This is usually a permission, account, or broker environment issue.

Check:

  • Algo Trading is enabled globally in MT5

  • Trading is enabled on the chart

  • The EA has permission to trade

  • The symbol exists on the account

  • The broker allows trading on that account

  • The account has enough margin

  • The EA is running on the correct MT5 installation or VPS

  • You exported and loaded the latest EA version

If you use a Profectus VPS and the issue is server/software-related, contact ForexVPS support.


Where to find the MT5 Journal

The Journal is the first place to check. It logs trade attempts, warnings, errors, and execution messages.

Live or demo trading

Go to:

Toolbox → Journal

Shortcut:

Ctrl + T

This Journal logs actions from EAs running on live or demo charts.

If a trade fails because of “not enough money”, “trade disabled”, or similar errors, it usually appears here.


Backtesting

Go to:

Strategy Tester → Journal

Shortcut:

Ctrl + R

This Journal logs what happens during a backtest.

Use it to check whether:

  • The EA tried to open a trade

  • The trade request failed

  • Spread was too high

  • Stops were invalid

  • Market data was missing

  • The tester ran out of disk space


Visual Mode

When using Visual Mode, the Journal appears next to the chart.

This is usually the best debugging setup because you can see:

  • Price action

  • Trades

  • Candles

  • Entry logic

  • Journal messages

  • Visual objects drawn by the EA

Use Visual Mode when you need to understand what the bot is doing, not just whether the final result looks good.


Common reason: trading is not enabled

If the bot does not trade at all, check permissions before changing the strategy.

1. Check the EA icon on the chart

The EA icon in the upper-right corner of the chart should be active/blue.

If it is gray:

  1. Double-click the EA on the chart

  2. Open the Common tab

  3. Enable:

    • Allow Algo Trading

    • Allow Live Trading

  4. Click OK

2. Check the global Algo Trading button

In the MT5 top toolbar, make sure Algo Trading is turned on.

If this is disabled, EAs cannot trade even if the project logic is correct.


Builder/project error codes

These errors usually appear before or during export because the project contains an invalid configuration.

Naming errors

Error 149 — Unexpected token

This usually means a reserved or not-allowed name was used for a variable or input.

Do not use system keywords such as:

float bool double string

Fix:

Rename the variable or input using a unique name that is not a system keyword.

Better examples:

Risk_Per_Trade London_High Buy_Gate ATR_Stop_Size

Avoid names like:

double string my-variable

Error 196 — Identifier expected

This means the system expected a valid variable or input name, but the name is missing or invalid.

Common causes:

  • Empty name field

  • Invalid characters

  • Name starts with an unsupported format

  • Incomplete input or variable setup

Fix:

Check all required name fields and make sure every input and variable has a valid name.


Error 158/ 228 / 152: invalid suffix / invalid number

This usually means one of your input or variable names is not valid after export to MQL5. Common causes are names starting with a number, spaces inside the name, hyphens, or special characters.

Bad examples:
2endsession
end session
start-session
session #1

Good examples:
endSession2
startSession1
session_1_start
session_2_end

Fix:

Rename the input/variable in Inputs & Variables, then reselect it inside the relevant blocks and export again.


Error 256 — Undeclared identifier

This means a variable or input is being used, but the system cannot find its definition.

Common causes:

  • The variable was never created

  • The input was deleted

  • The item was renamed in Inputs & Variables, but blocks still use the old name

  • A Formula or Trade Rule references a missing variable

Fix:

  1. Go to Inputs & Variables

  2. Confirm the variable/input exists

  3. Check the exact spelling

  4. Update all blocks that reference the old name


Error 125 — Variable already defined

This means the same variable is defined more than once.

Common causes:

  • Duplicate variable names

  • Same variable created multiple times

  • Variable defined in multiple places instead of reused correctly

Fix:

Use each variable name only once. Check in the 'Inputs & Variables' section if you go duplicated variables. Reuse the existing variable in blocks instead of creating a duplicate.


Error 129 — Struct member “...” already defined

This means a variable or input name already exists inside the project structure.

Fix:

Rename one of the duplicate variables or inputs.


Error 410 — Ambiguous access, can be one of

This means the system finds multiple variables or inputs with the same name and does not know which one to use.

Fix:

Assign unique names to all variables and inputs.

Bad:

High High High

Better:

London_High Asian_High Previous_Day_High

Syntax and formatting errors

Error 154 — Semicolon expected

This is usually caused by invalid formatting or unsupported characters in a name or value.

Common cause:

Using a hyphen in a variable or input name.

Bad:

buy-gate risk-per-trade

Better:

Buy_Gate Risk_Per_Trade

Fix:

Remove special characters and use clean naming.


Error 177 — I-value required

This can also happen when unsupported characters or invalid formatting are used.

Fix:

Check variable names, input names, and Formula/Modify Variable blocks for invalid characters or incomplete values.


Data type and value errors

Failed to parse value “...” of type Double

This means a field expects a number, but the value is not a valid number.

Common causes:

  • Text entered into a number field

  • Empty number field

  • Comma formatting issue

  • Wrong data type selected

Fix:

Use a valid numeric value.

Examples:

1 0.5 2.25 100

Avoid:

one risk 1,5

Use 1.5 instead of 1,5.


Could not parse value of variable “...”

This means an input or variable is empty or contains an invalid value.

Fix:

  1. Open Inputs & Variables

  2. Check the variable mentioned in the error

  3. Make sure it has a valid default value

  4. Make sure the value matches the selected data type


Block configuration errors

Empty Formula or Modify Variable block

This happens when a Formula or Modify Variables block is incomplete.

Common causes:

  • No variable selected

  • No formula added

  • No value assigned

  • Formula result has nowhere to be stored

Fix:

Open the highlighted block and complete the missing field.

For a Formula block, make sure:

Formula exists Target variable selected Valid output value

For a Modify Variables block, make sure:

Variable selected New value assigned

Variable to be changed is not selected

This means a Modify Variables block does not know which variable to update.

Fix:

Open the Modify Variables block and choose the correct target variable.


How to prevent Builder errors

Use these rules:

  • Use unique, descriptive names

  • Avoid reserved keywords

  • Avoid special characters

  • Use underscores instead of hyphens

  • Keep names consistent across all blocks

  • Do not rename variables without updating references

  • Fill in all required fields

  • Match values to the correct data type

  • Keep Formula and Modify Variables blocks complete

If the error mentions a highlighted block, start there. The highlighted block usually shows where the issue originates.


Common MT5 runtime errors

These errors happen after export, when MT5 tries to run, backtest, or trade with the EA.

Not Enough Money

Meaning:

The account balance or free margin is too low to open the trade.

Common causes:

  • Lot size too high

  • Risk too high

  • Account balance too small

  • Leverage too low

  • Other positions already using margin

Fix:

  • Reduce lot size

  • Reduce risk per trade

  • Close other positions

  • Increase demo balance

  • Check broker leverage

  • Test with smaller position sizing


Leverage Too Low

Meaning:

The requested position size exceeds what the broker allows for the account.

Fix:

  • Use smaller lot size

  • Reduce risk %

  • Check symbol margin requirements

  • Contact the broker if leverage is lower than expected


Market Closed

Meaning:

The EA tried to trade outside active market hours.

Common causes:

  • Weekend

  • Holiday

  • Broker maintenance

  • Symbol not tradable at that time

  • Session filter missing

Fix:

Use a session filter.

Example:

Run in Session → Trade logic

Only allow the EA to trade during active market hours.


Invalid Stops

Meaning:

The stop loss or take profit is invalid.

Common causes:

  • SL/TP too close to current price

  • Stop loss on the wrong side

  • Take profit on the wrong side

  • Broker minimum stop distance not respected

  • Points/pips conversion error

  • Negative or zero stop distance

Fix:

  • Widen SL/TP

  • Check whether SL is below entry for buys and above entry for sells

  • Check broker minimum stop distance

  • Verify pips/points conversion

  • Use Visual Mode to inspect the calculated SL/TP


Trade Context Busy

Meaning:

The EA sent multiple trade requests too quickly or simultaneously.

Common causes:

  • Run per Tick triggers too often

  • Multiple execution branches fire at once

  • Missing Count Trades filter

  • Duplicate Buy Now/Sell Now paths

  • Several EAs trade the same symbol at the same time

Fix:

  • Use Run per Candle when possible

  • Add Count Trades before execution

  • Avoid duplicate execution paths

  • Process one trade request at a time

  • Simplify the logic and retest


Price Changed / Off Quotes

Meaning:

The market price changed while the order was being executed, or the broker server did not respond in time.

Common causes:

  • Fast-moving market

  • High spread

  • Low liquidity

  • Broker execution delay

  • Max deviation too strict

Fix:

  • Allow reasonable max deviation/slippage

  • Avoid trading during unstable periods

  • Add a spread filter

  • Retest under realistic conditions


No disk space

Meaning:

MT5 could not write more tick data to disk.

This usually means the test is too heavy, not that your strategy logic is wrong.

Common causes:

  • Very long tick backtest

  • Too many optimization passes

  • High-quality tick generation over many years

  • Limited disk space on local machine or VPS

Fix:

  • Shorten the test range

  • Test 3–6 months first

  • Use “1-minute OHLC” for lighter tests

  • Reduce optimization combinations

  • Free disk space

  • Restart MT5 and retest


Invalid Volume

Meaning:

The lot size is invalid for the symbol.

Common causes:

  • Lot size below broker minimum

  • Lot size above broker maximum

  • Lot size does not match allowed lot step

  • Risk formula creates an invalid volume

Fix:

  • Check the symbol’s minimum lot size

  • Check the allowed lot step

  • Reduce risk

  • Use valid volume increments

Example:

If the broker allows steps of 0.01, then 0.03 may be valid, but 0.035 may not be.


Stack Overflow / Recursive Loop

Meaning:

The EA logic keeps calling itself or looping until MT5 runs out of memory stack.

This is usually an advanced logic issue.

Common causes:

  • Recursive loop

  • Logic path that never exits

  • Advanced blocks connected in a circular way

  • Repeated condition triggering itself

Fix:

  • Review loop logic

  • Remove advanced/loop blocks temporarily

  • Test the simplest version first

  • Add one logic branch back at a time

  • Ask support or Discord if unsure

Send the template link of the relevant block structure if you need help.


Indicator / Data Not Found (4806)

Meaning:

The EA tried to fetch indicator values that were not available.

Common causes:

  • Indicator not loaded

  • Indicator not compiled

  • Wrong timeframe

  • Wrong buffer index

  • Missing historical data

  • Custom indicator not available in MT5

  • Backtest starts before enough candles exist

Fix:

  • Confirm the indicator exists in MT5

  • Compile or reinstall the custom indicator

  • Check the timeframe

  • Check the buffer index

  • Load more historical data

  • Start the backtest later if the indicator needs warm-up candles

  • Test in Visual Mode and watch when the error appears


Compile errors vs runtime errors vs permission issues

Compile or Builder errors

These happen before the EA can run properly.

They usually mean:

The project configuration is invalid.

Examples:

  • Error 149

  • Error 196

  • Error 256

  • Error 125

  • Error 129

  • Error 410

  • Empty Formula block

  • Invalid variable value

Fix inside the Builder, then export again.


Runtime errors

These happen while MT5 runs the EA.

They usually mean:

The EA exists, but something failed during execution.

Examples:

  • Not enough money

  • Invalid stops

  • Invalid volume

  • Market closed

  • Off quotes

  • Indicator data not found

  • Stack overflow

Fix inside MT5 settings, broker/account conditions, strategy logic, or risk settings.


Permission, account, or environment issues

These happen when the bot may be built correctly, but the environment blocks it.

Common examples:

  • Algo Trading disabled globally

  • Trading disabled on the chart

  • EA permissions not enabled

  • Account does not allow live trading

  • Symbol not available on the account

  • Broker has different conditions on demo vs live

  • VPS is offline or disconnected

  • Wrong MT5 terminal or account loaded

  • Old EA version running after export

Fix:

  • Check chart permissions

  • Check global Algo Trading

  • Confirm the correct account

  • Confirm the correct symbol

  • Restart MT5 if needed

  • Reload the latest EA file

  • Check VPS connection if used


Debugging workflow

Use this workflow instead of guessing.

Step 1: Open the Journal

Start with the Journal.

Do not change the strategy before reading the actual error.


Step 2: Run in Visual Mode

Visual Mode lets you see the chart, the bot behavior, and the Journal together.

This helps you answer:

  • Did the bot try to trade?

  • Did the condition trigger?

  • Did the order fail?

  • Did the SL/TP look wrong?

  • Did the bot stop before execution?


Step 3: Change one thing at a time

If your bot behaves unexpectedly:

  1. Start from the default version

  2. Change one parameter only

  3. Export

  4. Backtest

  5. Observe

  6. Continue only if the change worked

If it breaks, revert and isolate the cause.

Do not change entry, exit, stop loss, risk, session, and management logic all at once. You will not know what caused the issue.


Step 4: Visualize the logic with Draw on Chart

Use Draw on Chart blocks to see where the decision tree passes or fails.

Good places to add Draw on Chart:

  • After an entry condition

  • After a failed Trade Rule

  • Before Buy Now or Sell Now

  • After a Formula block

  • After a variable is modified

  • At important price levels

Example:

Red arrow = first condition failed Black arrow = second condition failed Green arrow = all conditions passed Horizontal line = calculated price level

This makes debugging visible instead of guessing.


Step 5: Think in systems, not results

Every EA is a chain:

Condition 1 → Condition 2 → Risk check → Execution → Management → Result

Do not debug only the final profit result.

Debug each step.

If the final result is wrong, one step before it is usually wrong.


Step 6: Keep it sophisticatedly simple

Complex does not mean better.

Every algorithm consists of:

  • Entry rules

  • Exit rules

  • Risk management

  • Optional trade management

Start basic. Confirm the simple version works. Then add complexity.


Step 7: Build → Test → Measure → Repeat

Use a consistent workflow:

Build → Test → Measure → Adjust → Repeat

Test each component independently before combining everything.

For example:

  1. Test entry only

  2. Add stop loss

  3. Add take profit

  4. Add session filter

  5. Add management logic

  6. Add risk protection


Advanced checks: Raincheck and Monkey Test

Once the bot technically works, the next question is whether the result is meaningful.

Use these checks to avoid overfitting.

Train and validate on different periods

Example:

Build/test on: 2010–2015 Validate on: 2016–2020

Do not judge the bot only on the period where it was created or optimized.


Do not optimize too many variables

As a rule of thumb:

Do not optimize more than 2 variables at once.

The more variables you optimize, the easier it is to fit noise instead of finding a real edge.


Keep enough trades per variable

A rough rule:

30–120 trades per optimized variable

If your backtest has too few trades, the result may be random.


Compare entries against randomness

The Monkey Test checks whether your entry logic adds value compared to random entries.

If random entries with similar exits perform similarly, your entry logic may not have a real edge.


When to ask for help

Ask for help after you have checked the basics.

Before contacting support or Discord, do this:

  • Check the Journal

  • Verify chart permissions

  • Verify global Algo Trading

  • Run the bot in Visual Mode

  • Change only one thing at a time

  • Use Draw on Chart to locate where logic stops

  • Confirm whether the issue is Builder, MT5, account, broker, or VPS related

When asking for help, send:

  • Screenshot of the Journal error

  • Screenshot or screen recording of Visual Mode

  • Symbol

  • Timeframe

  • Date range

  • Account type: demo, live, or prop firm

  • Whether it happens in backtest, demo, live, or VPS

  • What you changed before the issue appeared

This makes it much easier to find the actual problem.


Quick error decoder table

Error / issue

Where it appears

Meaning

What to check first

Error 149

Builder/project

Reserved or invalid variable/input name

Rename variable/input

Error 196

Builder/project

Missing or invalid identifier

Check empty or invalid name fields

Error 256

Builder/project

Variable/input used but not defined

Check if it exists and names match

Error 125

Builder/project

Variable already defined

Remove duplicate variable

Error 129

Builder/project

Struct member already defined

Rename duplicate variable/input

Error 410

Builder/project

Ambiguous duplicate names

Use unique names

Error 154

Builder/project

Formatting/syntax issue

Remove unsupported characters

Error 177

Builder/project

Invalid formatting or assignment

Check names and block values

Failed to parse Double

Builder/project

Number field contains invalid value

Use valid numeric value

Could not parse variable

Builder/project

Variable/input empty or invalid

Fill in valid default value

Empty Formula block

Builder/project

Missing formula or target variable

Complete Formula block

Empty Modify Variables block

Builder/project

No variable/value selected

Select target variable and value

Not Enough Money

MT5 Journal

Balance/free margin too low

Reduce lot/risk

Leverage Too Low

MT5 Journal

Broker exposure limit exceeded

Reduce position size

Market Closed

MT5 Journal

Trading outside market hours

Add session filter

Invalid Stops

MT5 Journal

SL/TP invalid or too close

Check SL/TP logic

Trade Context Busy

MT5 Journal

Too many trade requests

Add Count Trades / simplify

Price Changed / Off Quotes

MT5 Journal

Execution price changed/server issue

Check spread/slippage

No disk space

MT5 Journal/tester

Too much test data for disk

Shorten test or reduce optimization

Invalid Volume

MT5 Journal

Lot size invalid

Check min lot and lot step

Stack Overflow

MT5 Journal/tester

Recursive or looping logic issue

Review loop/advanced blocks

Indicator/Data Not Found 4806

MT5 Journal/tester

Indicator or data unavailable

Check indicator, timeframe, buffer, history


Conclusion

Do not debug randomly.

Use this order:

Find where the error happens → Read the Journal → Identify the error type → Fix one issue → Export again → Test in MT5 Visual Mode → Change one thing at a time

Most bot issues are not mysterious. They are usually caused by an incomplete project setup, wrong variable naming, invalid MT5 trade conditions, missing permissions, or logic that needs to be visualized step by step.

Did this answer your question?