Case study · Trading software · Product engineering

Rebuilding Banana EA, trade-management software customers have run since 2017, for MetaTrader 5

Banana EA is the flagship of my trading-software business, iTradeAIMS: an automated expert advisor for the DAX index on 5-minute charts. Customers have run it on MetaTrader 4 since 2017. Moving it to MetaTrader 5 meant changing how a live product behaves for people who already trust it, so I didn't port the old code. I audited it, rebuilt the engine cleanly, and made every change from the old behaviour something I could name and test.

Role
Owner, product lead, developer
Timeline
MT4 product since 2017 · MT5 rebuild Sep – Oct 2026
Status
MT4 6.6 sold to customers · MT5 7.0 in demo validation
Customer reviews
iTradeAIMS: 4.8/5 from 56 on Forex Peace Army, 4.3/5 from 17 on Trustpilot (read Aug 2026)
commits in the MT5 rebuild
122
defects found by the audit, all fixed
23
assertions in the headless engine suite
1,416
written architecture decisions
4
robustness stages before any release
6

The problem

Why this needed building

Why a straight port was the wrong move

  • The MT4 engine had grown around one 3,377-line class with no behaviour tests. Porting it would have carried its bugs to MT5.
  • Some bugs only appeared after a restart: pending orders that never expired, partial closes that fired twice, risk limits that forgot the day's losses.
  • Without a way to compare the two versions decision by decision, "it trades the same" would have been a guess.

What customers and the business needed

  • An MT5 version that behaves as well as 6.6 or better, with nothing changed by accident.
  • Risk rules (daily drawdown, loss limits, lot caps) that hold on every tick and survive a restart.
  • Proof gathered on demo accounts before any customer runs it.
  • Licensing, so the MT5 build is protected like the rest of the range.

Architecture

How it fits together

Select a box to see what it does, or pick a journey and press Play to follow it step by step.

Reference & research
Engine · pure MQL5
Guards & broker
Evidence
Every development run trades demo accounts only. The scripts read the account type from MT5 itself before placing an order.
Reference & research
Engine · pure MQL5
Guards & broker
Evidence

Every development run trades demo accounts only. The scripts read the account type from MT5 itself before placing an order.

Select any box

Each box is a part of the system

Click one to read what it does and why it was built that way.

Key decisions

What I chose, and what I rejected

Each one is a written decision record in the repository.

Rebuild clean, with MT4 as the referenceArchitecture

The MT5 engine was written from scratch in modern MQL5. MT4 6.6 is the behaviour to beat, not the code to copy: a difference is fine when its cause and evidence are recorded.

Rejected: a line-by-line port, which would have carried 23 known defects and a 3,377-line untested class into the new platform.

Every divergence needs a nameVerification

Both versions write the same decision-trace format. The parity diff joins them bar by bar and fails on any difference without a named cause, or on a run that compared nothing.

Rejected: comparing end-of-test totals. Two versions can reach similar totals for different reasons, and totals can't show which decision changed.

A customer's research changed the exit designProduct

Mazi's research, backed by our own backtests across markets, showed the old ladder (partial closes at 3R, 10R and 15R) depended on rare, very large moves. The new design banks half at +1R, moves to break-even at +3R and trails the rest on ATR.

Rejected: keeping the ladder for familiarity. Parity with a fragile design isn't a goal.

No indicator handlesEngineering

The engine computes everything it needs from raw price series, and one owner computes each value.

Rejected: MT5 indicator handles. They can report 'not ready' mid-session, and in testing that stopped a break-even from firing on a valid quote.

Pre-register, then be willing to drop itMethod

A comparison of three order policies was frozen in writing before any results were read. When finishing it would have delayed the launch, I dropped it from the release and shipped the simplest policy, keeping the study as optional research.

Rejected: reading results first and picking a winner afterwards, and also quietly treating the unfinished study as evidence.

Demo accounts only, checked by the codeSafety

Any script that can place an order reads the account type from MT5 and refuses anything but demo. Compile and test runs take a terminal lock so two runs can't collide.

Rejected: trusting a config flag or the account name to say 'demo'.

In production

Defects found in the audit, and how the rebuild fixed them

Each of these was found by reading the 6.6 code and then reproduced. In the rebuild, each fix began with a test that failed.

Break-even moved by the wrong distanceTrade management

Symptom

Break-even and partial closes triggered at distances unrelated to the trade, and at zero after a restart.

Diagnosis

They read the stop size of the last signal the EA evaluated, not the position's own initial risk. After a restart that value was empty.

Fix

Break-even and partial closes read the position's own initial risk, stored against its position ID.

Lot sizes rounded down twiceRisk

Symptom

A third of tested sizes came out one step small, such as 0.3 lots becoming 0.2.

Diagnosis

The rounding function floored without a tolerance and ran twice. The same floor cut partial closes short.

Fix

One rounding step with a tolerance, covered by tests at the size boundaries.

Daily drawdown judged stale equityRisk

Symptom

The daily drawdown limit could react late in a fast market.

Diagnosis

The check used an equity snapshot up to 30 seconds old.

Fix

The limit is evaluated on every tick against current equity.

Blocked days could still tradeRisk

Symptom

Pending orders filled during a loss-streak block, cooldown or profit lock.

Diagnosis

A block stopped new orders but left orders placed earlier resting at the broker.

Fix

A block now also cancels this EA's resting pending orders, on every tick it is active.

'Close everything' could leave a position openExecution

Symptom

After the daily limit was hit, a position sometimes stayed open.

Diagnosis

Close-all sent its requests once. A single requote meant a close was lost and never retried.

Fix

Flattening is a held state: the EA keeps closing every tick until the account is flat.

Restarts made the EA forgetState

Symptom

After a restart, pending orders never expired and a partial close could fire again.

Diagnosis

Order plans, partial-close progress, loss streaks and the day's peak lived only in memory.

Fix

State is persisted per account and EA instance, and partial-close progress is keyed by the broker's position ID.

Method

How I built it

  1. 1

    I audited 6.6 before writing any MT5 code. One automated triage pass was thrown away because it scored almost every defect between 0.6 and 0.85, which ranks nothing.

  2. 2

    Important choices are written as architecture decision records, including the owner rulings that changed them, so the reasons survive the change.

  3. 3

    Validation claims name the commands and test runs behind them, and every fix links its failing and passing runs.

  4. 4

    I used AI coding agents (Claude Code, Codex) under my direction. I set the rules, rulings and acceptance tests, then reviewed and verified the work.

  5. 5

    Customer feedback is evidence too. Mazi's community guide, written with their own testing, fed straight into the architecture.

Stack

Technology

  • MQL5
  • MQL4
  • MT5 Strategy Tester
  • Python (parity diff, checkers)
  • PowerShell
  • CSV decision traces
  • Server-side licensing
  • Architecture decision records

What this means for your project

If you have an EA that has grown hard to change, or you need to move one from MT4 to MT5 without changing how it trades by accident, I can audit it, rebuild it behind tests, and show you every difference.

I also add risk guards that survive restarts, decision traces for comparing versions, and server-side licensing.

Get in touch →

This page is about software engineering. It makes no claim about trading results: backtests are not live results, past performance does not predict future results, and most retail traders lose money. iTradeAIMS provides software and education, not financial advice. Mazi's guide and research are credited with their permission. The source code is proprietary; I'm happy to walk you through it on a call.