Bid Bar Ask Trigger Divergence
MetaTrader 4's bar history - every High, every Low - is built entirely from Bid. But not every order type triggers off Bid. Buy Stop and Buy Limit pending orders, and a Sell position's take-profit, all trigger when ASK reaches the level. Since Ask = Bid + spread is always at or above Bid, a price a Bid-built chart shows as never having been reached by the high of a bar can still have been reached by Ask - the chart has no way to show this, because it never recorded Ask in the first place. This script makes that gap visible for a specific hypothetical trigger level. Given a price and which side of the book would react to it, it scans bar history and, for the Ask-triggered case, estimates each bar's Ask high as Bid high + spread, then flags every bar where the estimated Ask side reached the level but the Bid chart's own high did not - a candidate false negative for "did this level get touched". For the Bid-triggered case (Sell Stop, Sell Limit, a Buy position's take-profit) the Bid-built chart is already the correct authority, so the script says plainly that no divergence is possible there, rather than manufacturing one to look symmetrical. As with the rest of this catalogue's spread-aware tools, MT4 keeps no per-bar spread history, so the Ask estimate uses a single constant spread value - the current live reading by default, or a user-supplied override - applied uniformly across the scanned window. This is a real limitation and is stated in both the log output and the CSV export. Notes and limitations - The Ask estimate uses one constant spread value across the whole scanned window, since MT4 keeps no historical per-bar spread on either side. Real spread widens intrabar around news and thins during quiet sessions; this script cannot see either effect. - A flagged bar is a candidate, not a certainty - it means the ESTIMATED Ask side would have reached the level under the assumed constant spread, which is a model, not a recorded fact. - Bid-triggered order types are not analysed for divergence, because none exists: a Bid-built chart already represents them exactly. The script states this rather than padding the output with an artificial symmetric result. - Scans whatever history is already loaded on the chart; scroll back to load more if InpBars asks for more than is available.
Script · MT4 · v1.0 · Free
About Bid Bar Ask Trigger Divergence
Bid Bar Ask Trigger Divergence is a script for MetaTrader 4 based on Divergence. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Trigger price, Trigger side and Timeframe. MQL source code included.
Files in the download: BidAskTriggerDivergence.mq4, BidAskTriggerDivergence.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Trigger price | 0.0 | Hypothetical order level to test (0 = refuse) |
| Trigger side | TriggerAskBasedUp | Which side of the book would react to it |
| Timeframe | PERIOD_CURRENT | Bar history to scan |
| Bars | 500 | Number of bars to scan |
| Assumed spread points | 0 | Override spread, points (0 = use current live spread) |
| Export csv | true | Write every divergent bar to CSV |
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: Divergence · Pending Orders · Alerts · MT4 Script · MQL4 Source Code