Back to library
Library term·Algorithmic trading

Event-Driven News EA Architecture on MetaTrader 5

OnTimer vs OnTick, calendar APIs, debounced state machines, slippage-aware flattening and kill-switch patterns.

Authored by·Editorially reviewed
Onur Erkan Yıldız
Founder, Financial Engineer · CMB-licensed

Why OnTimer usually leads

Calendar-driven logic should not depend on random tick arrival density. A base 1s or 250ms timer keeps pre-news flatten windows deterministic relative to server time sync.

State machine sketch

States: IDLE → PREARM (T−Δ) → HALT (freeze new entries) → POST_RELEASE (cooldown). Transitions guard against clock skew by referencing TimeTradeServer with explicit tolerance.

Execution realism

News windows explode spread and slippage. Flatten routines should prefer reduce-only semantics and respect minimum stop distance anomalies.

Kill-switch

Hard global variable or file semaphore accessible from support operators — if external risk system trips, EA must block new risk within one timer cycle.

Finvestopia context

Our macro calendar surfaces high-impact events; align PREARM windows with the same event taxonomy to avoid fighting the house risk policy.

Related entries

Educational content authored by our team — informational only, not investment advice.