Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | Alpha Engine: Intrinsic-Time Coastline Trader | MetaTrader Tool

Discover expert developed MetaTrader tools that can complement professional solutions.

Overview

Abstract units become lots through the InpLotPerUnit input, and InpMaxUnits caps each agent's inventory. The cap is a piece of risk control the paper leaves out: once it is reached, the agent cancels its resting entry and adds nothing more, while the open take-profits keep working.


Recommended Setup

Setting
Recommended value
Notes
Symbol
EURUSD
The development and test instrument, and the one the paper's scaling laws were verified on. The thresholds are relative (percent of price), so other liquid FX pairs work without rescaling.
Timeframe
Any
The EA is driven tick by tick in intrinsic time, so the chart timeframe has no effect on its decisions.
Account type
Hedging
Required. Each cascade step must be its own position, so on a netting account the EA prints a message and returns INIT_FAILED by design.
Tester model
Every tick based on real ticks
Intrinsic events are defined on the tick stream, so bar-based models misrepresent both the events and the limit fills. The tester inherits the margin mode of the account you are logged into, so log into a hedging account before testing.
InpLotPerUnit
0.02 (shipped), up to 0.4
With a 0.01-lot step, the half and quarter units and the liquidity haircut only survive as distinct sizes when a unit is around 0.4 lots. Below that, the smaller adds are raised to the minimum lot. The threshold skew lives in the runners and is unaffected.
Important: removing the EA from the chart cancels its resting entry orders only. Open positions are left in place with their take-profits attached, so they keep unwinding on their own. Close them manually if you want the account flat.


Grid trading done right – try the robust Grid Expert Advisor for controlled risk. Details here.

Backtest Results

EURUSD, Every tick based on real ticks, 2 February to 31 July 2026, 10,000 starting deposit on a hedging account, shipped defaults (InpLotPerUnit = 0.02, InpMaxUnits = 30) with all eight agents enabled. The thresholds, sizing rules and take-profit are the paper's, not tuned to this symbol or period.

Image for Alpha Engine: Intrinsic-Time Coastline Trader

The Strategy Tester report for the six-month EURUSD run.

The run returned +10.68% with a profit factor of 2.21 and a 10.10% maximum equity drawdown over 318 positions. The net figure hides two very different streams, and splitting it by how each position closed is more instructive than the total:

Component of the six-month result
Amount
294 positions closed at their take-profit
+1,934.14
24 positions closed by the tester at the end of the run
-823.55
Commission charged on entries
-42.14
Net profit
+1,068.45

Both closing lines already include swap, which came to -620.38, far more than commission. For a model that can hold a cascade for weeks, financing rather than the spread is the dominant cost. The 24 positions the tester closed are cascades that never recovered: in live trading they would still be open.

Image for Alpha Engine: Intrinsic-Time Coastline Trader

The balance (blue) steps up as take-profits fire. The equity (green) carries the open cascades and meets the balance only when the tester closes them on the last day.

This is one pair over one six-month window, so it shows a working mechanism, not a headline performance number. Any strategy that closes winners and holds losers produces a rising balance, which is why the equity line and the forced close are the parts worth studying.


Input Parameters

Parameter
Default
Description
InpLotPerUnit
0.02
Lots per one abstract unit of the paper's sizing. Raise it toward 0.4 to keep the fractional sizing exact on a 0.01-lot symbol, or lower it to trade smaller.
InpMaxUnits
30
Per-agent inventory cap, in units. Once reached, no new adds are placed and the open take-profits are left to unwind the position. The deepest skew tier engages only past 30 units, so at the default cap it is never reached.
InpMagicBase
990000
Base magic number. The eight agents take InpMagicBase to InpMagicBase + 7, so change it if another EA on the account uses that range.
InpTradeLong
true
Run the four long-only agents.
InpTradeShort
true
Run the four short-only agents. With both enabled the ensemble is the paper's full symmetric setup.


Using the Classes in Your Own Code

One agent is a self-contained class, CAeLiveTrader. It knows nothing about the other agents, so an EA can run a single agent, a different set of thresholds, or several symbols by creating as many instances as it needs:

#include <IntrinsicTime\AeLiveTrader.mqh>

CAeLiveTrader agent;

//--- in OnInit: a long-only agent at delta 0.5%, 0.02 lots per unit, 30-unit cap
agent.Init(_Symbol,990100,1,0.005,0.02,30.0);

//--- in OnTick
MqlTick t;
if(SymbolInfoTick(_Symbol,t))
   agent.OnTickUpdate(t.bid,t.ask,t.time);

//--- in OnDeinit: cancels the resting entry, positions keep their take-profits
agent.Shutdown();

The intrinsic-time runner is usable on its own too. CAeRunner takes separate up and down thresholds in log-price, returns an event code on every quote (plus or minus 1 for a directional change, plus or minus 2 for an overshoot step, 0 otherwise), and always knows the exact prices at which the next events would fire, which is what makes it a natural source of limit-order levels for other strategies:

#include <IntrinsicTime\AeRunner.mqh>

CAeRunner runner;
runner.Init(0.005,0.005,0.005,0.005);  // delta up/down, overshoot up/down

int ev=runner.Run(AeTick(t.bid,t.ask,t.time));
if(ev==AE_EVENT_DC_DOWN)
   Print("downturn confirmed, next level below: ",runner.ExpectedLowerIE());

The liquidity indicator, CAeLocalLiquidity, follows the same pattern: initialise it with a threshold, feed it every quote through Computation, and read the current value of L with Liq.


Limitations

Worth knowing before attaching it to anything but a demo account.

  • There is no whole-position exit. The paper's reference trader closes an agent's entire position once its total return, realised plus open, reaches delta. The live agent does not reproduce it. A cascade that runs adverse and never recovers is halted by InpMaxUnits but not closed, and its take-profits stay resting. This is the single largest risk in the design, and the forced close in the backtest above is what it costs.
  • Swap dominates the costs. Cascades can stay open for weeks, so overnight financing weighs far more than spread or commission. Check your broker's swap on both sides before running it.
  • At the shipped lot size the sizing is simplified. At 0.02 lots per unit a full add is 0.02 lots and every smaller add is raised to the 0.01-lot minimum, so the paper's sizing ladder collapses to two steps. Raising InpLotPerUnit toward 0.4 restores it, at a much larger position size.
  • Realised profit is not an edge. On a driftless random walk the engine's realised profit is always positive while its total profit is zero in expectation. One pair and one test window cannot establish an edge either way.
  • The runners pause outside trading sessions. The EA returns early from OnTick when the symbol's session is closed, which keeps the journal clean and the backtest fast. It only matters on a feed that keeps quoting while trading is shut.


File Structure

One Expert Advisor and four headers. The headers are included as <IntrinsicTime\...>, so they must sit in an IntrinsicTime subfolder under Include.

File
Role
Description
Experts\IntrinsicTime\AlphaEngine.mq5
The EA
Enforces a hedging account, builds the eight-agent ensemble at the paper's four thresholds, gates on the trading session, and drives every agent with the latest quote.
Include\IntrinsicTime\AeLiveTrader.mqh
Live agent
CAeLiveTrader, one coastline agent trading real limit orders: runner selection by inventory, fractional and liquidity sizing, lot normalisation, and the single resting entry with its de-cascade take-profit.
Include\IntrinsicTime\AeRunner.mqh
Intrinsic-time runner
CAeRunner, the log-threshold directional-change runner with separate up and down thresholds, emitting directional-change and overshoot events and the price levels where the next ones would fire.
Include\IntrinsicTime\AeLiquidity.mqh
Liquidity indicator
CAeLocalLiquidity, the information-theoretic indicator L that scales each add, with its own runner and the reference's normal distribution function.
Include\IntrinsicTime\AeTypes.mqh
Shared types
The bid/ask tick structure and the intrinsic-event codes that the runner, the indicator and the agent all exchange.


Research Basis

The implementation follows:

  • Anton Golub, James B. Glattfelder and Richard B. Olsen, The Alpha Engine: Designing an Automated Trading Algorithm, 2017, SSRN 2951348.
  • James B. Glattfelder, Alexandre Dupuis and Richard B. Olsen, Patterns in high-frequency FX data: discovery of 12 empirical scaling laws, Quantitative Finance, 2011.
  • The authors' reference Java implementation, available on GitHub. The port keeps its quirks rather than silently correcting them.
This program is intended for educational purposes only. Trading carries a high level of risk, and past performance, especially on historical data, is not indicative of future results. Always test thoroughly on a demo account before risking real capital.

A companion article builds the directional-change operator, reproduces the scaling laws on 17.8 million real EURUSD ticks against a volatility-matched random walk, walks through the Alpha Engine port class by class, and tests its random-walk profit claim: Intrinsic Time: From the Directional-Change Scaling Laws to the Alpha Engine.

Thanks for reading. Discover premium MetaTrader solutions at RobotFX.

77871

Best MetaTrader Indicators + Profitable Expert Advisors