Intermediate Trading Tutorial — Confirmed Upper Range Breach Failure Rate in ProRealTime
A candle that trades above a recent high does not necessarily finish above it. Counting every intrabar excursion as a successful breakout can therefore obscure an important distinction between reaching a new price and maintaining that price through the close. This tutorial builds a ProBuilder indicator that measures the proportion of upper range breaches which fail to close above their own reference level. Instead of predicting whether the next breakout will work, the indicator summarizes completed historical observations using a consistent, auditable definition.
Define the reference and the event
For each evaluated candle, calculate the maximum high of the preceding R candles. This reference must exclude the candle being evaluated. Otherwise, its own high would influence the level against which it is compared, making a strict breach condition impossible. Define a breach when the candle high is strictly greater than the reference. Define a failure when a breach occurs but the candle close is less than or equal to the reference. A high that merely touches the reference is not a breach. A breached candle closing exactly at the reference is classified as a failure. These are explicit design choices; they are not universal definitions of technical breakouts.
Use a second independent window of S completed candles to count breaches B and failures F. The failure rate is 100 multiplied by F divided by B. Every failure must also be a breach, so the result is bounded between zero and one hundred percent. A zero event count is not a zero failure rate. The source requires a minimum number of breaches before publishing a rate. It also exposes the event count so that users can distinguish a percentage derived from two observations from the same percentage derived from twenty observations.

Work through the calculation
Consider three independent hypothetical classifications, each with a prior high of 105. Candle A has open 104, high 107, low 102 and close 103. It breaches the level and fails to retain it at the close. Candle B has open 104, high 108, low 103 and close 106. It breaches and closes above the reference, so it is not a failure. Candle C has open 103, high 105, low 102 and close 104. It touches but does not exceed the level. The breach flags are 1, 1 and 0; the failure flags are 1, 0 and 0. If a sample contains these three event classifications and the minimum breach count is two, the rate equals 100 times one divided by two, or 50%.
These are independent examples rather than consecutive candles with a fixed reference: the real reference is recalculated for each candle from its own preceding R bars. Consider a larger sample with eight breaches, three failures and twenty-two non-breach candles. The rate is 37.5%, not 10%. Dividing by all thirty candles would answer a different question: how frequently failures occur per candle rather than how frequently breaches fail. With the default minimum of five breaches, a sample containing only two breaches remains blank regardless of its failure count.
Complete ProBuilder indicator source
// PatternSmart: confirmed upper breach failure rate
// Edit the three positive integer settings as needed.
rangePeriod = 20
samplePeriod = 30
minBreaches = 5
// Reference excludes the candle being classified.
priorHigh = Highest[rangePeriod](high[1])
breach = 0
failure = 0
IF BarIndex >= rangePeriod THEN
IF high > priorHigh THEN
breach = 1
IF close <= priorHigh THEN
failure = 1
ENDIF
ENDIF
ENDIF
// Count only previously completed candles.
breachCount = Summation[samplePeriod](breach[1])
failureCount = Summation[samplePeriod](failure[1])
// Suppress output until every observation is eligible.
rate = Undefined
countPlot = Undefined
IF BarIndex >= rangePeriod + samplePeriod THEN
countPlot = breachCount
IF breachCount >= MAX(1,minBreaches) THEN
rate = 100 * failureCount / breachCount
ENDIF
ENDIF
RETURN rate COLOURED(45,105,190) AS "Failure rate %", countPlot COLOURED(36,145,100) AS "Breach count"
Implementation and window alignment
The three settings at the top are editable constants. rangePeriod controls the reference horizon, samplePeriod controls the number of classified candles included in the statistic, and minBreaches controls the minimum evidence requirement. Set all three to positive integers and keep minBreaches no greater than samplePeriod if a visible rate is desired. Highest applied to high[1] constructs a rolling maximum that excludes the evaluated bar. The two binary flags are initialized to zero on every calculation, then updated according to the observed high and close. This ensures that a failure cannot enter the count without a corresponding breach.
The Summation expressions use breach[1] and failure[1], rather than the current flags. As a result, the displayed statistics at bar t include classified bars t−S through t−1. Each classified bar uses a reference calculated from its own earlier observations. The BarIndex condition suppresses output until the oldest classified bar has enough reference history. With the defaults of twenty reference bars and thirty sample bars, the first eligible display index is fifty, counting the first loaded bar as zero. A rate may remain undefined after this index when the minimum breach count is not met.
Undefined represents unavailable output, rather than a valid numerical zero. A valid zero indicates that the sample contained enough breaches and none failed. The count series shares the indicator panel with the percentage series but has different units. For sample periods greater than one hundred, the count may extend beyond the percentage range and affect automatic scaling. Interpret the two series separately or hide the count line through display settings where supported.
Installation and parameter selection
In ProRealTime, open the indicator management interface, create a new ProBuilder indicator, paste the complete source and save it under a descriptive name. Add it to a price chart in a separate panel. Adjust the constants in the editor to test alternative settings. Use enough loaded history to satisfy both window lengths. A shorter reference may classify more local excursions, whereas a longer reference can produce fewer events. Increasing the sampling window may stabilize the descriptive rate but also makes it slower to reflect changes in the observed environment. These are trade-offs rather than optimal parameter recommendations. The source has not been compiled or executed in ProRealTime here.
Closed-bar behavior and repainting
The live candle's own high and close can change repeatedly, so its preliminary breach or failure flags may change. However, those current flags are excluded from the displayed count and percentage. Once the platform recognizes the next candle, the completed classification enters the rolling statistics. The reading is deliberately plotted on the following bar, not backdated to imply that the completed result was available earlier. No future bar is used. Under unchanged historical data, finalized observations should remain consistent; data corrections and reconstructed bars can change the inputs legitimately. During a market closure, the newest completed candle may not be included until a new bar appears.
Validation and limitations
Independently calculate prior highs and event flags in a spreadsheet. Test a strict touch, a breach closing exactly at the level, a breach closing above it, zero breaches, and a sample with fewer than the minimum required events. Check the first eligible index and confirm that the plotted rate remains unchanged while the current candle forms. Compare historical and replay observations under identical session settings. Verify that failures never exceed breaches. The statistic does not measure breakout distance, subsequent returns, execution prices, or whether price crossed a level before or after another intrabar event. Overlapping windows are statistically dependent, and a high historical failure rate is not a reliable forecast of the next event without independent validation.
For downside breach statistics, configurable tick buffers, alerts or integration into a larger ProBuilder study, contact our Custom ProRealTime indicator Development Services.
Risk disclosure: this tutorial is educational. Trading involves risk of loss. Hypothetical calculations do not establish trading profitability.