Entry Trigger Library
Most published entry-trigger code hardwires one specific condition straight into an EA's OnTick, which means comparing two trigger styles means maintaining two near-duplicate EAs. This library separates "what counts as an entry" from "what the EA does with an entry" by putting every trigger behind one fixed-shape struct (SEntryTrigger) and one evaluation function (EvaluateEntryTrigger). MQL4 has no function pointers, so this is not a callback table - it is enum-dispatch. Every trigger's configuration AND running state (an armed breakout level for a retest trigger, a tracked swing extreme for a pullback trigger) live directly on the SEntryTrigger instance the caller owns, and EvaluateEntryTrigger() switches on the instance's Type field to run the matching check. Six trigger kinds ship: two crosses (fast/slow series), two breakouts (rolling N-bar high/low), a retest (arms on breakout, fires on the return-and-hold) and a pullback (requires a minimum adverse excursion before the resumption counts, so it does not fire on every minor wiggle in the trend's favour). The retest and pullback triggers are the two that genuinely need memory between calls - a retest has to remember it already broke out and is now watching for the return, and a pullback has to remember how far price has already retraced. Because MQL4 gives no other natural home for per- instance state without a class hierarchy the language cannot express either (no virtual dispatch through function pointers), that state sits as plain fields on the same struct the caller already passes by reference every call - ResetTriggerState() clears it once a signal has been acted on. Notes and limitations - Every trigger evaluates against already-closed bars (signalShift >= 1 in the usual case) - none of them repaint, but a caller passing shift 0 is evaluating against the still-forming current bar, which will change its own answer as the bar completes. Pass shift 1 or higher for a stable signal. - The cross trigger takes fast/slow series values as plain doubles - it does not compute any indicator itself, so it works identically whether the caller feeds it two moving averages, an oscillator against its signal line, or two arbitrary price series. - RETEST and PULLBACK both hold state on the struct instance itself. Reusing the same instance for a different symbol/timeframe without calling ResetTriggerState() first carries over stale armed/extreme values from whatever it was previously tracking. - The retest trigger's "hold" check only looks at the closing price within tolerance of the broken level - a long wick through the level that closes back on the correct side still counts as holding, which matches how most discretionary retest reads work but is a deliberate simplification versus requiring the whole bar's range stay inside tolerance.
Script · MT4 · v1.0 · Free
About Entry Trigger Library
Entry Trigger Library is a script for MetaTrader 4 based on Moving Average. It has 5 settings, such as Scan bars, Breakout lookback and Retest tolerance points. MQL source code included.
Files in the download: EntryTriggerLibrary.mqh, EntryTriggerLibrary.txt, EntryTriggerLibraryDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Scan bars | 200 | Bars to scan, oldest to newest |
| Breakout lookback | 20 | Lookback window for breakout/retest triggers |
| Retest tolerance points | 30 | How close price must return to the broken level |
| Pullback lookback | 8 | Bars back used as the pullback trigger's reference bar |
| Min pullback points | 80 | Minimum adverse excursion required before resume counts |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Breakout · Moving Average · MT4 Script · MQL4 Source Code