Loading…

Highlight Bars Matching Condition

Manually scanning a chart for every inside bar or every wide range bar does not scale past a screen or two of history, and it is easy to miss one buried between more obvious candles. This script tests the whole visible history against one chosen rule and paints a translucent rectangle behind every bar that qualifies, turning a pattern search into something the eye can do instantly instead of one candle at a time. Six rules are available, one active per run: inside bar, outside bar, a wide range bar, a narrow range bar, a gap up, and a gap down. Switching rules is one input change and a re-run, so scanning for several patterns in sequence takes seconds each. The naive version of "wide range" and "narrow range" uses a fixed pip or point threshold, which breaks the moment you switch from a five-digit forex pair to an index or a metal. This script measures range against ATR instead, scaled by a multiplier you set, so the same input setting is meaningful on any instrument without retuning it per symbol. Highlight rectangles are drawn behind the candles rather than replacing them, so the wick and body of every matched bar stay fully visible on top of the shading. Notes and limitations - This is a one-off scan, not a running indicator - it does not update as new bars form. Re-run the script to refresh the highlighted set. - Only one rule is tested per run. Comparing two rules at once means running the script twice with InpCleanupFirst turned off and different highlight colours, or reviewing them one at a time. - The gap tests compare a bar directly against the one immediately before it and do not account for weekend or session gaps specifically - any gap meeting the price condition is marked, regardless of cause. - On MQL5, if the ATR indicator handle has not finished calculating by the time the scan starts (a fresh handle needs a moment to populate), the script waits briefly and then proceeds with whatever is available, logging a note if the buffer came back short.

Script · MT4 · v1.0 · Free

About Highlight Bars Matching Condition

Highlight Bars Matching Condition is a script for MetaTrader 4 based on ATR. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Condition, Lookback bars and Atr period. MQL source code included.

Files in the download: HighlightBarsMatchingCondition.ex4, HighlightBarsMatchingCondition.mq4, HighlightBarsMatchingCondition.txt.

Settings

SettingDefaultWhat it does
ConditionCondInsideBarRule to test every bar against
Lookback bars300How many recent bars to scan
Atr period14ATR period backing the wide/narrow range test
Range multiplier1.5Multiplier used by the wide/narrow range test
Highlight colorclrYellowHighlight colour
Cleanup firsttrueDelete this script's previous highlights first

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Candlestick Patterns · Alerts · ATR · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria