Beginner Trading Tutorial — Candle Body Share in NinjaTrader 8
Candlestick charts summarize four prices: open, high, low and close. A large candle range does not necessarily mean that price finished far from its opening level. A candle can travel substantially in both directions and still close near its open. This tutorial builds a simple native NinjaScript indicator to quantify the fraction of each candle's range occupied by its real body. The indicator is a useful first exercise in reading OHLC data, handling undefined calculations and plotting a normalized measurement in a separate panel.
What the indicator measures
The real body is the absolute difference between close and open. The range is high minus low. Divide the body by the range and multiply by 100 to obtain a percentage. For ordinary valid OHLC data, the result lies between zero and 100. A reading of 60 means the distance between open and close occupies 60 percent of the high-low interval. It does not mean that price increased by 60 percent, or that 60 percent of trades were buys. The absolute value deliberately removes direction, so bullish and bearish candles of identical body and range produce the same reading.

Calculate the values by hand
Consider a candle with open 102, high 110, low 100 and close 108. Its body is six points and its range is ten points, so the body share is 60%. A second candle opens at 106 and closes at 104 with the same high and low. Its absolute body is two points, yielding 20%. A third opens and closes at 105 while retaining the same high and low. Its body is zero, so its reading is zero. These examples are independent hypothetical candles rather than a continuous market sequence.
A candle opening at its low of 100 and closing at its high of 110 produces 100%. The reverse candle also produces 100%. When all four prices equal 105, however, the denominator is zero and the ratio is undefined. This distinction is important: a zero body with a positive range describes a real observation, while a zero range provides no basis for calculating the fraction. The source resets the plot in the latter case rather than assigning a misleading zero.
Complete native NinjaScript indicator
using System;
using System.Windows.Media;
using NinjaTrader.NinjaScript;
namespace NinjaTrader.NinjaScript.Indicators
{
public class CandleBodyShare : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "CandleBodyShare";
Description = "Absolute candle body divided by range.";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
BarsRequiredToPlot = 0;
AddPlot(Brushes.DodgerBlue, "BodyShare");
AddLine(Brushes.Gray, 50, "HalfRange");
}
}
protected override void OnBarUpdate()
{
// Use the completed primary candle.
double range = High[0] - Low[0];
if (range <= 0.0)
{
// Undefined ratio, not a genuine zero.
Value.Reset();
return;
}
double body = Math.Abs(Close[0] - Open[0]);
Value[0] = 100.0 * body / range;
}
}
}
Understanding the implementation
The indicator inherits from the standard NinjaScript Indicator class. OnStateChange provides a place to define its default behavior. In State.SetDefaults, Name and Description identify the study, Calculate.OnBarClose selects completed-bar calculations, and IsOverlay=false places the output in a separate panel. BarsRequiredToPlot is zero because this calculation needs only one candle and does not require a moving average warm-up. AddPlot creates the primary series, and AddLine creates a fixed 50 reference line. That line is a visual guide, not a tested entry threshold.
OnBarUpdate reads the current calculation bar using offset zero. The range is evaluated first so that division by zero can be avoided. Math.Abs converts the signed close-minus-open difference into a nonnegative body size. Value[0] stores the calculated percentage. The calculation uses constant work and no persistent counter, so its cost does not increase with chart history. The same formula is applied to every bar. There is no need to round prices before calculating the ratio; display precision can be configured separately.
Installation and chart setup
In NinjaTrader 8, open the NinjaScript Editor from the Control Center and create a new indicator named CandleBodyShare. Replace the editable class with the supplied source, retaining any platform-generated wrapper region. Compile the script and add the indicator through the chart Indicators dialog. Use an ordinary time-based candle chart for the first test. Open the Data Box to inspect individual bar values. The blue line represents body share and the gray line marks 50. This source has not been compiled or executed in NinjaTrader here; verify it in your installed version before using it in a live workflow.
Closed-bar timing and repainting
The default standalone indicator calculates at the close of each bar. During a developing candle, its high, low and close may change, so an intrabar body share could fluctuate significantly. Waiting for the completed bar makes the observation stable under ordinary subsequent price updates. The source uses no future bars, centered windows or forward-looking confirmations and does not intentionally repaint completed values. If hosted by a strategy or another NinjaScript object, the parent calculation mode can govern the frequency; a host using intrabar calculations should explicitly enforce the intended closed-bar timing. Historical corrections and bar types that rebuild their history may still change previously calculated values.
Practical testing and interpretation
Begin with the three illustrated examples and compare the arithmetic with the Data Box on comparable candles. Check a full-body candle, a doji with positive range and a flat candle. Confirm that the full-body reading is 100, the doji is zero and the flat candle has no valid plotted value. Observe a forming candle and verify that the standalone study only updates on completion. Reload the chart using the same data and session settings and compare completed values. If a strategy reads the indicator, log both the bar timestamp and the value to avoid confusing a forming bar with a completed one.
A high body share indicates that the open-to-close distance is large relative to the observed range. A low reading indicates that the body occupies a smaller part of the interval. Neither reading identifies trend direction, volume, liquidity or the sequence in which the high and low occurred. A one-tick full-body candle and a much larger full-body candle both produce 100%. Combining the ratio with a separately measured range can help distinguish magnitude from shape, but such an extension requires independent validation. The indicator is not a standalone trading signal and does not model transaction costs or execution quality.
For configurable body thresholds, alerts or strategy integration, contact our Custom NinjaTrader indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not establish profitability.