Skip to main content

How to Debug Your Trading Bot

Debugging bots and figuring out errors is part of the process — start with the Journal, change one thing at a time and keep it simple.. If your bot isn’t trading, backtests fail, or errors appear, this guide helps you find and fix MetaTrader issues fast.

Updated over a month ago

When your bot doesn’t behave as expected — whether in a live account, demo, or backtest — don’t panic.
Debugging is part of the building process. Understanding where to look and how to test systematically will save you hours of guessing.
This guide shows you exactly how to self-debug before reaching out to the community or the Profectus team.


Where to Find the Journal

The Journal is where MetaTrader 5 logs everything your bot does — every trade attempt, every error, every warning.
It’s your first stop whenever something seems off.

You’ll find a Journal in three key places:

📍 Toolbox → Journal (Live Trading)

Open the Toolbox (Ctrl + T).

In the same window where you see open trades, account balance, and history, there’s a tab called Journal.


It records all real-time actions of your trading bots running on live or demo charts.
If something fails (for example “not enough money” or “trade disabled”), it appears here — usually marked with a red exclamation mark.


📍 Strategy Tester → Journal (Backtesting)

Open the Toolbox (Ctrl + R).

When running a backtest through the Strategy Tester, you’ll find a Journal tab at the bottom of the tester window.
It logs every action your bot takes during the backtest.
Errors here tell you whether a trade failed to execute, spreads were too large, or trading conditions weren’t met.
(Attach screenshot 2 – Strategy Tester → Journal)


📍 Visual Backtester → Journal (Visual Mode)

If you’re using Visual Mode while backtesting, a small Journal window appears next to the chart.
This lets you see trades, price action, and log messages all at once — the best way to spot what your bot is doing behind the scenes.


Common Reasons a Bot Isn’t Trading

If your bot trades on a real account but not on a demo, or vice versa, check the basics first:

  1. Is trading enabled on the chart?
    The small Expert Advisor (EA) icon in the upper-right corner of your chart must be blue. If it’s gray, double-click it → open the Common tab → tick both checkboxes (Allow Algo Trading, Allow Live Trading) → OK.

  2. Is Algo Trading turned on globally?
    In the MT5 top toolbar, ensure the Algo Trading button is active (red icon visible).


Check the Journal for clues

👉 Always run your bot in Visual Backtest Mode with the Journal open to see exactly what happens behind the scenes.

Error Message / Code

What It Means & When It Happens

Quick Fix / What to Check

Not Enough Money

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

Reduce lot size, close other positions, or increase balance/ leverage.

Leverage Too Low

Your requested position size exceeds the maximum exposure allowed by your broker.

Use smaller lot size or contact broker to raise leverage.

Market Closed

The bot tried to trade outside market hours or during weekend maintenance.

Limit trading to active sessions (e.g., via Run in Session block).

Invalid Stops

Stop loss / take-profit too close to price or reversed.

Widen SL/TP or check broker minimum distance.

Trade Context Busy

EA sent multiple trade requests simultaneously.

Add small delays or use queued orders (one request at a time).

Price Changed / Off Quotes

Price moved while the order was executing or server didn’t respond in time.

Allow slippage (“Max Deviation”), or retry after a short delay.

No disk space

The error means MT5 couldn’t write more tick data to disk, not that your code is wrong.

Shorten the testing range (e.g., last 3–6 months instead of several years).

Or switch to “1-minute OHLC” mode to reduce tick generation volume.

If you’re optimizing, lower the number of passes (fewer input combinations).

Invalid Volume

Lot size is below minimum or not a valid multiple of the step size.

Use SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_STEP to normalize volume.

Stack Overflow / Recursive Loop

Your algorithm calls itself endlessly — advanced logic error.

Review loops or conditional blocks; reach out on Discord if unsure (quant-level issue).

Indicator / Data Not Found (4806)

EA tried to fetch indicator values that aren’t loaded or available.

Make sure indicators are compiled and attached; use correct timeframe and buffer index.


Change One Thing at a Time

If your system behaves unexpectedly:

  1. Start from the default version of your bot.

  2. Change one single parameter — e.g., stop-loss size or risk %.

  3. Export, run a backtest, observe.

  4. If it works → build on it.
    If it breaks → revert and isolate the cause.

Changing multiple components at once makes it impossible to track what caused the issue.


Visualizing With Objects

One of the fastest ways to understand why a bot isn’t triggering trades as expected is by visualizing what happens inside the decision tree. In Profectus.AI, this is done using the Draw on Chart block. This block lets you place visual markers directly on the chart during backtesting, showing where your logic passes or fails specific conditions. Here’s how to use it effectively:

  1. Add a Draw on Chart block to your decision tree — ideally right after a Trade Rule block or anywhere you suspect the logic might be stopping.

  2. Use candle IDs to define placement. The arrow will always appear on top of that candle, making it easy to trace where the logic runs.

  3. Color-code your arrows to identify which conditions were (or weren’t) met.

    • Example: A red arrow if the first condition fails, a black arrow if the second fails, and a green one when all pass.

  4. Use the horizontal line option to confirm if a specific price level was correctly detected or calculated. This is especially useful for debugging formulas and range-based logic.

By adding these simple visual cues, you can instantly see on the chart where your bot’s logic stops flowing — helping you pinpoint which specific block or rule is causing the interruption.

For example, in a simple test system:

  • Candle ID 1 must be bullish.

  • Candle ID 2 must be bearish.

  • Then a Buy Now block triggers.

If trades aren’t firing, attach Draw on Chart blocks after each condition.
You’ll see exactly where the logic stops — no guessing required.


KISS — Keep It Sophisticated Simple

Complex doesn’t mean better. Every algorithm is built from a few simple parts:

  • Entry rules

  • Exit rules

  • Risk management

  • Optional trade management

Small, simple rules can create powerful systems when combined.
Start basic, then iterate.


Think in Systems, Not Results

Every EA is a chain of steps:
1 → 2 → 3 → 4 = Result

Focus on the left side (the process), not just the right side (the profit).
Managing each step makes your results predictable — ignoring them makes them random.


Build a Consistent Workflow

A workflow protects you from guesswork and bias.
Follow this rhythm:

Build → Test → Measure → Repeat

Each time you add a feature — entry, exit, or management — test it independently before combining.


The Raincheck & Monkey Test (Advanced Builders)

Profectus AI follows the Raincheck method, a streamlined institutional backtesting framework that helps you confirm whether your bot has a real edge or random luck.

Key ideas:

  • Train on one data range (e.g., 2010–2015) and validate on another (e.g., 2016–2020).

  • Don’t optimize more than 2 variables at once.

  • Keep at least 30–120 trades per variable for statistical relevance.

  • Test your entries against randomness (the “Monkey Test”).

These checks prevent overfitting and give confidence your bot will work forward in time — not just backward.


When to Ask for Help

If you’ve done all of the following:

  • Checked the Journal

  • Verified Algo Trading and chart permissions

  • Tested in visual mode

  • Changed only one parameter at a time

  • Followed the workflow

…and the issue persists (e.g., stack overflow, unexplained logic errors) — that’s the right time to contact the Profectus community or support team.
Share your Journal logs and a screen recording so others can help faster.


Did this answer your question?