Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Squeeze Duration Statistics: How Long a Low-Volatility Squeeze Lasts and How Far the Range Expands After It - indicator for MetaTrader 5

Views:
50
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Squeeze Duration Statistics: How Long a Low-Volatility Squeeze Lasts and How Far the Range Expands After It

The idea behind it

"Volatility is quiet, a big move is coming" is one of the most repeated sentences in trading. Squeeze indicators help to see when the market is quiet, but they rarely answer the two questions that matter after that: how long does the quiet usually last on my symbol, and how big is the move that follows? Without those answers a squeeze is only a feeling. This indicator measures both from the history of your own symbol, your timeframe and your broker's data.

The definitions are short:

  • Range window. The highest high minus the lowest low of the last InpRangeBars bars, ending in the bar that is judged.
  • Squeeze. A bar is in a squeeze when the range window divided by the Wilder ATR ( InpAtrPeriod , a slow baseline) is at or below InpSqueezeRatio . The range of twelve bars is normally a few times the ATR, so a low ratio means that the last bars were unusually tight.
  • Run and length. The number of bars in a row that are in a squeeze. A run of fewer than InpMinBars bars is ignored, and is not counted as a squeeze.
  • Release. The first bar after a counted squeeze that is no longer in a squeeze. The squeeze itself ended with the bar before it.
  • Box. The highest high and the lowest low of the bars of the squeeze.
  • Expansion. The range of the InpLookAhead bars that start with the release bar, measured in two ways: in ATR (the ATR of the last bar of the squeeze) and in boxes (divided by the height of the box).
  • First side. The first close in that window that is above the box (up) or below the box (down). If no close leaves the box, the squeeze is "none". This is about closes, so a wick over the box does not count.
  • Control. The range of the next InpLookAhead bars after every bar of the history, in ATR. A squeeze only means something if the expansion after it is different from this number.

The squeezes are grouped by length into five rows (under 5 bars, 5-7, 8-12, 13-20 and 21 or more), because a squeeze of three bars and a squeeze of thirty bars are not the same event. A second figure tells you how a squeeze that is running now has behaved before: of all the squeezes that reached its current length, how many went on for at least one more bar.

There is no look-ahead. A squeeze enters the table only after its look-ahead window has closed, so the statistics shown at a bar contain only what had finished before it. The newest bar is shown while it forms, but it is never counted, because its high, low and close can still change. The calculation is incremental: on every call only the new bars and the bar that was still forming are processed. The ATR is a running value, the ranges are taken over the small window only, and the squeezes that are waiting for their window to close sit in a short queue, so the history is never rescanned.

How to interpret it

  • Histogram (indicator window). One bar for every bar that is in a squeeze. Its height is the length of the squeeze so far, so it climbs by one for every bar that the squeeze goes on. Gray bars belong to squeezes that are still shorter than InpLongBars , white bars to squeezes of that length or more. Bars outside a squeeze have no histogram bar.
  • Release mark. A circle on the release bar, at the height of the length of the squeeze that has just ended. A tall circle means a long squeeze that has ended. Squeezes shorter than InpMinBars get no mark.
  • Boxes (main chart). A dashed rectangle around each of the latest finished squeezes ( InpBoxesShown ) and a dotted rectangle around the squeeze that is running now, once it has reached InpMinBars bars. They are shown on the price chart, so that you can see where the price left the box.
  • Data Window.
    • "Range / ATR": the range window divided by the ATR at each bar. A squeeze is a value at or below InpSqueezeRatio .
    • "Squeeze went on after this length before (%)": of the squeezes that had ended before this bar and had reached the length of the squeeze at this bar, the share that went on for at least one more bar. It is empty when fewer than InpMinCases squeezes reached that length, and for lengths below InpMinBars or of 100 bars or more.
  • Panel (top left of the chart).
    • Line 1: symbol, timeframe, the number of closed bars analysed and the squeeze settings in use.
    • Line 2: the number of squeezes, the share of bars that were in a squeeze, the average length and the longest squeeze.
    • Line 3: the column names. exp ATR is the average range after the release in ATR, x box is the same range in boxes, and up , down and none are the shares of squeezes by first side.
    • Lines 4-8: one row for each length group and a row "all". The column n is the number of squeezes with a closed window. A row with fewer than InpMinCases squeezes shows "--".
    • Line 9: the control. The average range of the next bars after any bar, next to the average range after a squeeze, and the ratio between them. A ratio below 1 means that, on this data, a squeeze was followed by less range than an ordinary bar was.
    • Line 10: the state now (no squeeze, building, or running with its box, and how often squeezes of this length went on).
    • Line 11: one line with symbol, timeframe, bars, the number of squeezes, the average length, the expansion ratio and the three first-side shares, ready to be copied into a comment.


Fig. 1. The last 90 bars of a simulated H1 series. Dashed boxes: two finished squeezes. In the indicator window the histogram counts the bars of each squeeze (gray while shorter than 10 bars, white from 10), and the circle marks the release at the length of the squeeze that ended. The panel counts all 6,065 closed bars, not only the visible ones. The numbers come from simulated data and say nothing about any real market. Black and white screenshot, per the Code Base image guidelines.

External variables (inputs)

Input Default Purpose
InpRangeBars 12 Bars in the range window (2-100).
InpAtrPeriod 50 Period of the Wilder ATR, the slow volatility baseline (5-200). The first bars of the analysis build the ATR and are not judged.
InpSqueezeRatio 2.0 A bar is in a squeeze while range window / ATR is at or below this value (0.5-10). Lower values give fewer and tighter squeezes.
InpMinBars 3 Shortest squeeze that is counted, in bars (2-20). Shorter runs are ignored.
InpLookAhead 10 Bars measured after the release (2-50). The window starts with the release bar.
InpHistoryBars 50000 Newest bars analysed when the indicator loads or is fully recalculated. 0 analyses all bars. New bars are added as they arrive.
InpMinCases 20 Fewest cases before a row, a percentage or the control shows a number (5-500).
InpLongBars 10 Squeezes of this length or more get the second histogram color (1-100).
InpShowBoxes true Draw the boxes on the chart.
InpBoxesShown 5 Finished squeezes that keep a box (0-10). The running squeeze has its own box.
InpShowPanel true Show the statistics panel.
InpRunColor clrGray Histogram color of a short squeeze.
InpLongColor clrWhite Histogram color of a long squeeze.
InpReleaseColor clrWhite Color of the release mark.
InpBoxColor clrWhite Color of the boxes.
InpTextColor clrSilver Panel text color.
InpFontSize 8 Panel font size (Consolas). The line height follows the size.
InpPanelX , InpPanelY 8, 14 Panel offset from the upper left corner of the chart, in pixels.

Recommended use

  • Symbols and timeframes. Any symbol and any timeframe. The numbers describe one symbol on one timeframe, so the table of H1 is not the table of M15, and you need to read each one separately. Because the indicator has no session or time-of-day setting, it runs on D1 and longer as well; there are just fewer squeezes.
  • Set the squeeze for your market first. The ratio of the range window to the ATR depends on InpRangeBars and on how trending the symbol is. Look at line 2 of the panel: if more than a third of all bars are in a squeeze, the limit is too loose and a squeeze is no longer rare. If there are only a handful of squeezes, it is too tight. A squeeze that happens all the time is not a squeeze.
  • Number of cases. Long squeezes are rare. With a few thousand bars the rows for 13 bars or more can hold a few dozen squeezes at best, and their numbers jump around. Look at the column n first, load more history through InpHistoryBars , and be careful with rows of under 100 squeezes. Rows with fewer than InpMinCases show "--" on purpose.
  • Compare with the control. Many squeezes are followed by a smaller range than an ordinary bar is, because quiet bars often come in groups and the ATR is a slow average. Do not read "exp ATR" alone. The ratio in line 9 is the one that tells you whether a squeeze was followed by more range than usual.
  • Up, down and none are not a direction forecast. The first side is only the first close beyond the box inside the window. On many symbols up and down are close to equal. A real difference needs many cases, and it should hold when you look at an older and a newer part of the history (change InpHistoryBars ).
  • The look-ahead window overlaps. If a new squeeze starts before the window of the old one has closed, both are measured over the same bars. This is correct for the question that is asked, but it means that neighboring squeezes are not independent.
  • The squeeze ends when the ratio rises. A squeeze can also end because an old tight bar leaves the range window or the ATR falls, and not only because of a breakout, so the release bar is not always an expansion bar.
  • It describes the past. The table shows what was usual in the loaded history. It does not predict the next squeeze. It does not include spread, swap or slippage.
  • The data is the broker's data. Highs, lows and closes depend on the feed. Holes in the history change the range window, so a different broker can give a slightly different table.
  • Performance and memory. Each bar is processed once. Later ticks only update the newest bar and the panel. The statistics live in small fixed tables, and up to 40 squeezes can wait for their window at the same time.
  • Chart objects. The boxes (prefix SQ_B ) and the panel lines (prefix SQ_P ) are the only objects, and all of them are removed in OnDeinit() . The boxes are redrawn only when the list of squeezes changes.
  • Account types. The indicator does not trade and does not depend on netting or hedging accounts.
  • Your turn: post your numbers. Attach the indicator to a chart you trade, copy the last line of the panel and post it in the comments with the name of your broker. This is only the format, and its numbers are made up: EURUSD H1 | 50000 bars | squeezes 410 | average 9.2 bars | expansion x1.12 | up 49% down 47% none 4% . Which of your symbols have an expansion ratio above 1, and which below? Do long squeezes behave differently from short ones on your symbol?
Trading Conditions Monitor - Gold, Forex and Synthetics Trading Conditions Monitor - Gold, Forex and Synthetics

Is it a good moment to trade? One panel combines spread, session, rollover, volatility, daily range and high-impact news into a clear GOOD / CAUTION / AVOID status. Works on all symbols, tuned for gold (XAUUSD).

News Guard — news filter and slippage log for your existing EA News Guard — news filter and slippage log for your existing EA

A bolt-on module (.mqh) plus a ready integration example: a news filter that keeps your EA out of new entries around economic releases — using only the built-in MT5 calendar, no DLL and no WebRequest — and a slippage log that records, for every fill, the difference between the price you asked for and the price you got.

Pullback Depth Statistics: How Deep Do Pullbacks Go Before the Trend Resumes? Pullback Depth Statistics: How Deep Do Pullbacks Go Before the Trend Resumes?

Builds a real depth distribution for this symbol's pullbacks — how far price typically retraces before the trend resumes, and how often it doesn't resume at all.

Breakout Follow-Through Statistics: Real Break or Fakeout After a New N-Bar High or Low? Breakout Follow-Through Statistics: Real Break or Fakeout After a New N-Bar High or Low?

Every new N-bar high or low gets tagged, timed, and scored — real breakout or fakeout — so the scorecard tells you what this symbol has actually done at its own extremes, not what you assume it does.