Limit Order Fill Odds Study
"Wait for a better price" is a habit most traders never actually measure. This script tests it directly: for every closed bar in the lookback window, it pretends a limit order was placed a fixed pip distance from that bar's close - a buy limit below, a sell limit above, or both - and then checks the following bars to see whether price actually traded back far enough to fill it, and how many bars that took. The signal bar's own range is never counted as a fill, even if it happens to touch the limit price - the order is only placed once the bar has closed, so the earliest possible fill is the bar after it. This avoids the common mistake of testing whether a bar touched its own future price. Results are reported as a fill percentage, an average bars-to-fill, and the fastest and slowest fill observed, separately for each side tested. Notes and limitations This assumes the limit order rests at a fixed price with no expiry other than the bar-count cutoff, and ignores spread, slippage and broker fill rules - it answers "did price trade at or through this level", not "would this exact order have filled at this broker". Treat the output as a starting estimate of how often the market revisits a given distance, not a fill guarantee. Needs InpLookbackBars + InpMaxWaitBars + 1 bars of history loaded on the chart; the script checks this and refuses to run on too short a history rather than silently testing fewer signals than requested.
Script · MT4 · v1.0 · Free
About Limit Order Fill Odds Study
Limit Order Fill Odds Study is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Lookback bars, Distance pips and Max wait bars. MQL source code included.
Files in the download: LimitFillOddsStudy.mq4, LimitFillOddsStudy.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback bars | 500 | How many signal bars back to test |
| Distance pips | 10.0 | Limit distance from the signal bar's close, in pips |
| Max wait bars | 20 | How many bars to wait for a fill before giving up |
| Side | SideBoth | Which side(s) to test |
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: Pending Orders · Alerts · MT4 Script · MQL4 Source Code