Intermediate Trading Tutorial | ProRealTime ProBuilder indicators
Two candles can have the same body-to-range percentage even when one spans a fraction of a point and the other spans a substantial price interval. Giving both candles exactly the same influence may be appropriate when the research question concerns the typical candle, but it is less suitable when the objective is to understand how much of the aggregate traded price range is represented by candle bodies. This tutorial develops a free ProRealTime indicator that calculates the total absolute body length divided by the total high-low range over a window of completed candles. The result is a range-weighted body share, expressed as a percentage, rather than an average of individual candle percentages.
Define the statistic before implementing it
For a candle with opening price O, high H, low L, and closing price C, define its absolute body length as the absolute value of C minus O. Define its range as H minus L. Under valid OHLC data, the body cannot exceed the range. Sum both quantities separately across the last N completed candles. Divide the body sum by the range sum and multiply by 100. The result is bounded between zero and 100 when the denominator is positive.
This calculation gives wider candles proportionally greater influence. It can also be written as a weighted average of each nonflat candle's body-to-range fraction, using its range divided by the total range as its weight. A doji with a positive range contributes zero to the numerator but increases the denominator. A flat candle with no range contributes zero to both sums. When every candle has zero range, the result is undefined rather than zero. This distinction prevents the absence of measurable price movement from being confused with genuine wick dominance.
Five-bar example: why aggregation order matters
Consider five hypothetical completed candles. The table lists their absolute bodies and full ranges in the same price units. These values are constructed for instruction and are not historical market observations.
| Bar | Absolute body | Range | Individual share |
|---|---|---|---|
| 1 | 1 | 4 | 25% |
| 2 | 6 | 8 | 75% |
| 3 | 0 | 3 | 0% |
| 4 | 5 | 10 | 50% |
| 5 | 3 | 5 | 60% |

The body sum is 1 + 6 + 0 + 5 + 3 = 15. The range sum is 4 + 8 + 3 + 10 + 5 = 30. Therefore the proposed indicator reads 50%. The unweighted mean of the five individual percentages is (25 + 75 + 0 + 50 + 60) / 5 = 42%. Both figures are mathematically correct, but they answer different questions. The unweighted statistic describes the average candle proportion, whereas the weighted statistic describes the fraction of aggregate range represented by bodies.
If the next completed bar has a body length of 2 and a range of 12, the oldest pair, 1 and 4, leaves the rolling window. The updated body total becomes 16 and the range total becomes 38, giving approximately 42.11%. The decline is primarily driven by the new bar's large range and small body. This illustrates why the weighted version can respond strongly to unusually wide, wick-heavy bars.
Complete ProBuilder source
// PatternSmart - Range Weighted Body Share
// Change the period here; use an integer from 1 to 500.
n = 5
bodySize = ABS(close - open)
rangeSize = MAX(0, high - low)
score = Undefined
// Use only completed candles before the calculation bar.
IF BarIndex >= n THEN
bodyTotal = 0
rangeTotal = 0
FOR j = 1 TO n DO
bodyTotal = bodyTotal + bodySize[j]
rangeTotal = rangeTotal + rangeSize[j]
NEXT
IF rangeTotal > 0 THEN
score = 100 * bodyTotal / rangeTotal
ENDIF
ENDIF
RETURN score COLOURED(50,95,190) AS "Weighted Body Share"
Historical indexing and publication timing
ProBuilder uses square-bracket offsets to access earlier observations. The loop begins at offset one and ends at offset N, deliberately excluding the currently forming candle. The first potentially valid output occurs at BarIndex N, since BarIndex begins at zero. The guard prevents an attempt to use unavailable history. Undefined suppresses unavailable output both during the initial lookback and when the entire window is flat.
Although an indicator may be recalculated during the current bar, its inputs remain the earlier completed candles. The value is displayed at the calculation bar following the newest input candle. This alignment is intentional. Do not move historical plots one bar into the past to make a signal appear available before it actually was. If a strategy reads the result at bar close rather than at the next opening, its effective decision timing may be later; test the integration rather than inferring execution timing from the chart.
The loop uses O(N) operations per calculation. It is transparent and sufficient for normal research lengths. A rolling-sum implementation can be more efficient for larger windows, but it must preserve the same history guard, closed-bar offset and zero-denominator treatment. Changing the implementation should not silently change the mathematical statistic.
Installation in ProRealTime
- Open the indicator creation or management window and create a new personal ProBuilder indicator named Range Weighted Body Share.
- Paste the complete source and save it. The variable n is explicitly assigned a default of five; change the assignment to another positive integer if desired.
- Apply the indicator in a separate chart panel. A scale of zero to 100 is useful for interpretation.
- Choose a completed sequence of five candles, record their OHLC values, and calculate the absolute body and range sums manually.
- Compare your result with the plot on the following candle. Observe the forming candle and confirm that its changing prices do not alter the statistic.
The source is intended for the native ProBuilder indicator language. It has not been compiled or run in an actual ProRealTime installation for this article; verify syntax and display behavior in your installed version before using it operationally.
Parameter choices and practical limitations
A short window emphasizes the latest candle geometry, while a longer window mixes more observations and can be dominated by wide bars that remain in the sample. Compare periods such as five, ten and twenty on the intended instrument and aggregation. The example's 50% is not an optimized threshold. The indicator is invariant to common positive scaling of all prices and to adding a common constant, but changing timeframes changes the underlying OHLC construction. Values from range bars and time bars are not necessarily comparable.
Because the numerator is absolute, this is not a bullish or bearish oscillator. A market dominated by large bearish bodies can have the same reading as one dominated by bullish bodies. The calculation also does not measure volume, actual intrabar traversal, or the sequence of individual transactions. A high reading merely indicates that bodies account for a large share of the sum of candle ranges. If direction is important, a separately defined signed measure would answer a different question.
Validation checklist
Test candles with open equal to close, candles with bodies spanning the entire range, mixed widths, and a window consisting entirely of flat candles. Check that the first valid plot occurs only when N previous bars are present. Verify the 50% worked example and the rolling replacement example. Compare historical and live calculations using unchanged chart data. Data revisions, session templates and nonstandard bar construction can affect historical inputs; closed-bar calculations do not protect against such changes. Evaluate any trading hypothesis independently with execution costs and out-of-sample observations.
If you would like a directional variant, volatility filters, custom alerts or integration into other ProRealTime studies, contact us for Custom ProRealTime indicator Development Services.
Risk disclosure: This tutorial is educational and does not constitute investment advice. Hypothetical calculations do not demonstrate profitability. Trading involves risk of loss.