Whipsaw Cluster Detector
A crossover system's account statement usually tells the story a raw chart does not: long quiet stretches of small losses clustered where price whipsawed back and forth across the moving average. This indicator finds those stretches directly. It counts how many times a Close-vs-SMA crossing rule changes direction inside a trailing window of InpWindowBars bars, and whenever that count reaches InpMinCrossings, the underlying bars are shaded as a background rectangle - a whipsaw zone. Zones are rebuilt from scratch once per new closed bar rather than incrementally, since a zone's true start and end can only be known in hindsight as later bars confirm whether the chop continued or price finally broke out - the scan is bounded to InpZoneLookbackBars so this stays cheap. Individual crossing points are also marked with a small arrow, so a trader can see both the raw signal and which stretches of it the cluster filter would flag as unreliable. The Close-vs-SMA rule is a simple, self-contained stand-in; the clustering and zone-drawing logic applies to any rule that produces a directional flip. Notes and limitations - Non-repainting in the sense that a zone, once its end bar has closed and confirmed the chop ended, does not move again - but the currently forming zone at the right edge of the chart can still extend forward as new bars arrive, which is the expected behaviour of a hindsight-confirmed zone, not a bug. - All zone objects are prefixed and removed cleanly in OnDeinit, so removing the indicator leaves no leftover drawings. - The crossing rule and window are fixed parameters, not adaptive to volatility - a naturally choppier symbol may need a larger InpMinCrossings to avoid flagging its normal behaviour as a whipsaw zone.
Indicator · MT4 · v1.0 · Free
About Whipsaw Cluster Detector
Whipsaw Cluster Detector is an indicator for MetaTrader 4 based on Moving Average. It draws buy and sell arrows on the chart. It has 5 settings, such as Ma period, Window bars and Min crossings. MQL source code included.
Files in the download: WhipsawClusterDetector.mq4, WhipsawClusterDetector.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Ma period | 20 | SMA period the base rule crosses against |
| Window bars | 20 | Trailing bar window a crossing count is measured over |
| Min crossings | 4 | Crossings inside the window needed to call it a whipsaw zone |
| Zone lookback bars | 1500 | How many recent bars are rescanned for zones (performance cap) |
| Zone color | clrLavender | Background fill colour for a detected zone |
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 → Indicators.
- 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 indicator from the Navigator onto a chart and adjust the settings.
Tags: Moving Average · Buy/Sell Arrows · Trend · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code