# IntrinsicTime The directional-change operator, the intrinsic-time scaling laws, and the Alpha Engine coastline trader, implemented in MQL5. Companion code for the MQL5 article: https://www.mql5.com/en/articles/23814 ## What it does Physical time is an arbitrary clock for a market. Intrinsic time replaces it: the clock only ticks when price reverses by a fixed threshold, so quiet periods compress and active ones stretch. `DcOperator.mqh` is that clock: an online operator that dissects a tick stream into directional-change and overshoot legs, one price at a time, with no look-ahead. That reframing comes with published scaling laws, which are empirical regularities relating threshold size to event counts and move lengths. `DcOS_ScalingLaws.mq5` measures them on your own broker's ticks and fits the same laws on a Gaussian random walk as a control. On 17.8 million EUR/USD ticks the market's exponents match the paper's closely (count law -1.944 against the paper's -1.908, coastline -0.978 against -0.940). The control is the important part. A walk sized to the market, one step per price change with the market's own step volatility, reproduces the same exponents (-1.974 and -0.969). At these scales the laws hold for pure noise too, so they do not by themselves reveal market structure. A walk built with the paper's much coarser fixed step gives shallower slopes and a false-looking gap, which is why the script's defaults size the walk to EUR/USD. The Alpha Engine is the trading side: a counter-trend coastline trader that adds to a position at each adverse intrinsic event and trims each add at a profit of delta, with inventory-skewed thresholds and a liquidity indicator around it. `Ae_RandomWalk.mq5` runs the reference engine on 200 seeded random walks. Its realised profit is positive on all 200, but its total profit, with the open cascade marked at the last price, averages zero (+0.22, standard error 0.36): the method turns noise into many small closed wins and a few large open losses, not into an edge. `AlphaEngine.mq5` is the Expert Advisor, eight limit-order agents on a hedging account. On EUR/USD from 2 February to 31 July 2026 at the default inputs it returned 10.68% with a 10.10% equity drawdown. That is +1,934 from take-profits, -824 when the tester closed 24 leftover positions at the end of the run, and -42 commission, with swap (-620 in total) already inside the first two figures. The live agent has no whole-position exit, so a cascade that never recovers is only halted, not closed. ## Layout ``` Include/IntrinsicTime/DcTypes.mqh directional-change enums and event record Include/IntrinsicTime/DcOperator.mqh CDcOS, the directional-change/overshoot operator Include/IntrinsicTime/ScalingLaws.mqh operator bank, log-log fit, random-walk control Include/IntrinsicTime/AeTypes.mqh tick structure and intrinsic-event codes Include/IntrinsicTime/AeRunner.mqh CAeRunner, the log-threshold event runner Include/IntrinsicTime/AeLiquidity.mqh CAeLocalLiquidity, the liquidity indicator L Include/IntrinsicTime/AeLimitOrder.mqh reference limit order with de-cascade accounting Include/IntrinsicTime/AeCoastlineTrader.mqh the offline reference coastline trader Include/IntrinsicTime/AeAlphaEngine.mqh the eight-agent ensemble, offline reference form Include/IntrinsicTime/AeLiveTrader.mqh CAeLiveTrader, one live agent on real limit orders Experts/IntrinsicTime/AlphaEngine.mq5 the Expert Advisor (hedging account required) Scripts/IntrinsicTime/DcOS_SelfTest.mq5 known-answer tests for the operator Scripts/IntrinsicTime/DcOS_ScalingLaws.mq5 scaling laws on live ticks against the control Scripts/IntrinsicTime/Ae_SelfTest.mq5 known-answer tests for the trading model Scripts/IntrinsicTime/Ae_RandomWalk.mq5 realised and total profit on random walks ``` Run the two self-tests first, then the scaling-law script on a fully synced EUR/USD chart. For another symbol, set the walk's length, starting level and per-step sigma to that symbol's own tick data before comparing exponents. ## Disclaimer Educational code. The random-walk results show that the engine's closed-trade profit is not evidence of an edge, and the backtest covers one pair over one six-month window, so it demonstrates a working program rather than a strategy with proven expectancy. Past behaviour of any model or dataset says nothing about future results. Test on your own data and broker conditions before drawing conclusions.