Skip to content

Repository files navigation

IlanTrio

Ilan-Trio is a martingale grid Expert Advisor for MetaTrader, originally written in MQL4 around 2011. This repository holds the original and two derived versions.

File What it is
ilan_trio_v147.mq4 The original MQL4 expert advisor. Unmodified.
ilan_trio_v147.mq5 A faithful MQL5 port. Same behaviour as the MQL4 original, quirks and all.
ilan_trio_cent100.mq5 The MQL5 port plus a capital-protection layer, intended for a small (~$100) cent account.
presets/ilan_trio_cent100.set Ready-made settings for the above.

Read this before risking money. None of these files has been compiled or run on a live terminal by their author in this repository's history. They are verified by static analysis only. Compile them yourself and backtest before use.


How the strategy works

It is a martingale grid. It opens a position, and if price moves against it, it opens another one that is larger, then larger again. All open positions share a single take profit placed at their volume-weighted average price plus TakeProfit points, so a small retracement closes the whole basket in profit.

That is why it wins most of the time. It is also why, when it loses, it loses everything at once: the losing streak that fills the grid is the same event that makes the position enormous.

There are actually three independent grids in this EA — Hilo, 1.5 and 1.6, each with its own magic number. They trade the same symbol with correlated entry rules, so running all three is not diversification, it is roughly triple the position size on one bet.


Why ilan_trio_cent100.mq5 exists

The original has essentially no working risk management. This is not an opinion, it is what the code does:

  • No stop loss anywhere. Every one of the twelve order-entry calls passes a stop loss of 0. The Stoploss_Hilo / Stoploss_15 / Stoploss_16 inputs are used to compute variables that are then never read again — despite one of them being labelled "These parameters DO work!!" in the source. They do not.
  • Every protection switch is hardcoded off and is not even exposed as an input, so you cannot turn them on from the terminal.
  • The equity "high-water mark" tracked current equity instead of the peak, so the equity stop measured risk against a target that fell as you lost, and could never fire.
  • Positions could be orphaned. If the take-profit write failed ten times, the code cleared its "needs a take profit" flag anyway and never retried. Combined with the missing stop loss, that leaves a live position with no exit at all.
  • All of the risk logic sits below a once-per-bar gate, so it could only react at the open of a new bar — once an hour on an H1 chart. Meanwhile the take profit is written onto the position and executed by the broker, tick-accurate.

That last point is the heart of it:

The profit side is precise and always on. The risk side was coarse and switched off.

ilan_trio_cent100.mq5 keeps the trading logic identical and adds a risk layer on top. Every addition is marked //=== RISK === in the source so you can audit exactly what changed.


Requirements

  1. A hedging account. The EA holds several positions on one symbol at the same time. On a netting account MetaTrader merges them into a single net position and the averaging logic breaks. The EA refuses to start on a netting account.
  2. A cent account, if you are funding this with ~$100. This matters more than any setting below — see the next section.
  3. MetaTrader 5. Compile with MetaEditor (F7) or metaeditor64.exe /compile:ilan_trio_cent100.mq5 /log.

Why a cent account is not optional at $100

On a cent account a $100 deposit is shown as 10,000 cent-units and each lot is worth 1/100 of a standard lot, so you get 100× the granularity. The smallest lot a broker will accept is 0.01 either way, and that is the binding constraint:

Account type One grid at the 0.01 minimum
Standard, $100 Wiped out by a 28 pip move against you. Margin also fails first — at 1:500, $100 supports 0.5 lots total, but the grid needs 1.6.
Cent, $100 A full ten-step grid costs about 2.5% of the account.

The EA will refuse to start on a standard $100 account rather than let you find this out the expensive way.


Install

  1. Copy ilan_trio_cent100.mq5 into <MT5 data folder>/MQL5/Experts/. Find the data folder via File → Open Data Folder in MetaTrader.
  2. Open it in MetaEditor and press F7 to compile. There must be 0 errors.
  3. Restart MetaTrader or refresh the Navigator panel.
  4. Open a EURUSD chart, drag the EA onto it.
  5. In Inputs, click Load and choose presets/ilan_trio_cent100.set.
  6. In Common, tick Allow Algo Trading, and make sure the Algo Trading button in the main toolbar is green.

On startup the EA prints its risk projection to the Experts tab. It looks like this:

=== RISK projection === grids:[HiLo ] equity 10000.00  budget(20.0%) 2000.00
=== RISK projection === full grid: 1.24 lots, cost 251.30 (2.51% of equity)
=== RISK projection === after a full grid you hold 12.40 per pip; buffer to the basket stop = 141 pips (need >= 100)

If it refuses to start, it will tell you why. That is the EA working correctly, not a bug. Do not "fix" it by lowering MinPipBufferAfterGrid.

One case that surprises people: the projection is measured against your current equity, not your original deposit. So after a losing run the budget is smaller, the buffer shrinks, and the EA may refuse to restart on an account it happily ran on last week. That is the check doing its job — the correct response is a smaller Lots, a lower MaxLotPerTrade, fewer MaxTrades_Hilo, or more funds. Not a lower threshold.


The protections

Setting Default What it does
MaxAccountDrawdownPct 20.0 The main backstop. At 20% drawdown from the equity peak it closes every position and halts. Checked on every tick, not once per bar.
MaxDailyLossPct 10.0 Halts until the next server day after losing 10% of the day's opening balance. The baseline survives a terminal restart, so restarting mid-day does not hand the EA a fresh 10% to lose.
MaxLotPerTrade 0.20 Caps each rung of the ladder. This is what bounds the tail — see below.
MaxTotalLots 2.00 Refuses to open beyond this total volume on the symbol.
MinMarginLevelPct 300.0 Refuses to open when margin level is below this.
MaxSpreadPoints 30 Refuses to open when the spread is blown out, e.g. during news.
MinPipBufferAfterGrid 100.0 Startup check — see below.
HaltOnTrip true Keeps the halt latched until you clear it by hand.

Why MaxLotPerTrade is the important one

The grid filling is not what kills the account — that costs about 2.5% of a cent account. What kills it is the volume you are still holding once the grid is full and price keeps going:

Per-trade lot cap Cost of a full grid Held after grid is full Room before the 20% stop
none (original) 502 units (5.0%) 55.1 units/pip 27 pips
0.20 (preset) 251 units (2.5%) 12.4 units/pip 141 pips
0.10 (more cautious) 164 units (1.6%) 7.2 units/pip 255 pips

Capping each rung barely changes the cost of a full grid but transforms what happens afterwards. The startup check gates on that remaining buffer, not on the cost of the grid — because the cost alone passes both the capped and uncapped setups, including exactly the one that is dangerous.

This also means the EA will refuse to run all three grids at once on $100 (the buffer falls to ~33 pips). That is deliberate.

What happens when it trips

  1. The halt is latched first, then everything is closed. That ordering matters: the close routine sleeps, and if it were the other way round the same tick could reopen what was just closed.
  2. Nothing new is opened while halted.
  3. The chart shows *** RISK HALT *** and the reason.

To resume after a drawdown halt: remove the EA, delete the global variable ILANCENT_HALT_<SYMBOL> (Tools → Global Variables, F3), then re-attach. The EA rebases its drawdown reference to your current equity when the halt clears, so it will not immediately re-trip.

A daily halt clears by itself at the start of the next server day.

Check the Trade tab after any halt. While halted the EA returns early and does no position management at all, so if a close partially failed during the trip, a surviving position is left unmanaged — and since this EA never sets a stop loss, that position has no automatic exit. Close anything left over by hand before resuming.


Settings you might reasonably change

  • Lots — leave at 0.01. It is already the broker minimum.
  • MaxTrades_Hilo — fewer rungs means a shallower grid and a smaller tail.
  • TakeProfit — points past the basket average. Lower closes cycles sooner.
  • PipStep / MarioTurboFactor — grid spacing. Wider spacing survives bigger moves but takes longer to recover.
  • MaxAccountDrawdownPct — how much you are prepared to lose in one event.

Do not enable UseTrailingStop. It is deliberately left hardcoded off and is not an input: the code path behind it writes stop losses on live positions, sleeps a full second per position, and truncates its distance to a whole number. The basket stop replaces it.


Before you go live

  1. Compile — 0 errors.
  2. Strategy Tester on EURUSD, cent account, with the preset. Confirm only magic 11111 opens positions.
  3. Deliberately break things and confirm the guard reacts:
    • MaxAccountDrawdownPct=1 → everything closes, nothing reopens;
    • MaxSpreadPoints=1 → no entries, and a spread-veto line in the log;
    • MaxTotalLots=0.02 → the ladder stops adding;
    • MaxLotPerTrade=0 (uncapped) → the EA refuses to start;
    • restart the terminal mid-halt → it stays halted.
  4. Forward-test on demo for at least two weeks, including one high-impact news release.

Honest limitations

A martingale's edge is the absence of a stop. Adding a hard basket stop turns "wins most of the time, occasionally catastrophic" into "wins less often, loses a bounded amount regularly". This is a genuinely different strategy from the original, and it will not reproduce the original's backtest.

These controls bound the expected failure modes. They cannot bound:

  • a weekend gap straight through the grid,
  • a broker stop-out at a worse level than ours,
  • slippage during a flash move.

On a full grid at 12.4 units per pip, a 200-pip gap is roughly a 25% loss no matter what the EA intends.

Treat the deposit as money you can lose entirely.


Licence

The original carries a 2011 MetaQuotes copyright header, preserved in all files.

About

Ilan Trio FX bot

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages