Reversal Probability Gauge
- Indicators
- Version: 1.0
- Activations: 5
# Reversal Probability Gauge - Historical frequency by analogy
*Category: Oscillators | Difficulty: advanced | Window: separate window below the chart | Markets: Universal (Forex, indices, commodities, crypto, stocks) | Suggested timeframes: M30, H1, H4, D1*
## Short description
> Searches history for bars with a state similar to the current one and counts in what percentage of those cases price then moved the opposite way. It is an observed frequency, not a forecast.
## Full description
### Overview
Instead of asserting that a reversal will happen, this indicator measures how many times, in the past and on this same instrument, a condition similar to the current one was actually followed by a reversal. It works as a search by analogy: it describes the current state with an oscillator, searches history for all past bars with a similar state within a tolerance, and counts in what percentage of those cases price moved the opposite way over the following bars. The result is a historical frequency. It must be said with maximum clarity that a past frequency is not a future probability: the value describes what happened, not what will happen, and should be used to calibrate expectation and sizing, never as a guarantee. The line showing the number of cases found exists precisely to judge how reliable the frequency is.
### How the calculation works
1. A range oscillator describes the state of every bar with a single number.
2. For every past bar the change realized within the chosen horizon is recorded.
3. The search for similar cases starts InpHorizon bars back: only those cases have a fully observed outcome.
4. This constraint is what guarantees no repaint: no future information ever enters the value of the current bar.
5. A case is similar when its state is less than InpTolerance away from the current state.
6. If fewer than InpMinCases cases are found the frequency is not shown: too small a sample is unreliable.
### How to use it
- Always look first at the gold line showing the number of cases: a frequency computed on few cases has no value.
- Use the frequency to size the position, not to decide whether to enter: a sixty per cent frequency still leaves forty per cent of contrary cases.
- Frequencies near fifty per cent mean that state has no predictive value on this instrument.
- Raise the tolerance to find more cases, knowing the cases become less similar and the frequency less specific.
- Comparing the frequency across instruments helps understand on which markets extremes carry real value.
### Who it is for and on which timeframes
It targets quantitatively minded traders who can tell an observed frequency from a forecast, a distinction essential to using it correctly. It works from M30 to D1. It requires very deep history and has the highest computational cost of the whole category, because it examines hundreds of past bars for every current bar. It is not for those seeking certainty: the greatest value of this indicator lies precisely in declaring when the data are insufficient to say anything.
### Practical example of reading a signal
On USDJPY H4 the oscillator reaches eighty eight. The indicator searches the last five hundred bars for all cases where the state was between eighty one and ninety five, finding forty three. Of these, in twenty eight cases price fell over the following five bars: the frequency is sixty five per cent and the histogram turns coloured. The correct reading is not that price will fall, but that in this specific condition, on this instrument, it fell in two cases out of three. A trader selling here can size the position knowing that roughly a third of the time they will lose, which is far more useful information than the plain assertion that overbought leads to a decline.
## Input parameters
| Parameter | Default | Description |
|---|---|---|
| `InpOscPeriod` | 14 | Period of the oscillator describing the state of every bar. |
| `InpLookback` | 500 | History searched for similar cases. The wider it is the more cases are found, but the computational cost grows. Internally capped at 3000. |
| `InpHorizon` | 5 | Bars within which the reversal is checked. It defines what counts as a reversal in time terms. |
| `InpTolerance` | 7.0 | How similar a past case must be to count as analogous. Tight tolerances give more similar but fewer cases. |
| `InpMinCases` | 12 | Minimum cases for the frequency to be shown. Below this threshold the value stays neutral. |
| `InpHighFreq` | 65.0 | Frequency beyond which the case is deemed notable and the histogram coloured. |
## Advantages / strengths
- It replaces a generic assertion with a measure verifiable on the instrument real data.
- It explicitly shows the sample size, allowing the reliability of every value to be judged.
- It refuses to produce a frequency when the cases found are insufficient, instead of showing an unfounded number.
- No repaint: the search uses only cases whose outcome is already fully observed.
## Limitations and warnings
- A historical frequency is not a future probability: the market can behave differently from how it behaved.
- It is the heaviest of the whole pack computationally: the first pass on long histories takes several seconds.
- The state is described by a single number, so two very different situations can look analogous.
- The result depends sensitively on the chosen tolerance and horizon: different values produce different frequencies.
**No repaint:** values printed on a closed bar are never modified afterwards.
**Disclaimer.** This product is a technical analysis tool, not an automated trading system, and it offers no profit guarantee whatsoever. Financial markets carry the risk of total loss of the invested capital. Past performance is not indicative of future results. Every signal must be confirmed with your own analysis, a money management plan and prior testing on a demo account. The author is not responsible for trading decisions taken on the basis of this indicator.
## Suggested tags / keywords for MQL5
`probability`, `frequency`, `analogy`, `backtest`, `oscillator`, `reversal`, `no repaint`, `statistics`
