Beginner Trading Tutorial — Confirmed Candle Body Midpoint Change in MT5
Most introductory momentum indicators begin with the difference between two closing prices. That is useful, but it is not the only way to summarize the movement of consecutive candles. The midpoint of a candle body provides another reference: it lies halfway between the opening and closing price, regardless of whether the candle is bullish or bearish. By comparing consecutive body midpoints, we can build a small indicator that describes the displacement of candle bodies without allowing the high or low to dominate the calculation. This tutorial introduces a native MetaTrader 5 implementation, explains its indexing, and provides a method for checking the output independently.
What the indicator measures
For each completed candle, calculate its body midpoint M as (Open + Close) / 2. The indicator is the current midpoint minus the preceding midpoint. Positive values indicate that the center of the body has moved upward; negative values indicate downward displacement. Zero means that the two bodies have the same midpoint, even if their lengths and colors differ. This is not the midpoint of the entire high-low range, nor is it a volume-weighted average price. It does not establish where the majority of transactions occurred.
The source offers two output units. In price mode, it reports the difference in the instrument's quoted price. In points mode, it divides that difference by the MQL5 symbol property _Point. This distinction is important for comparing the display with the terminal's price precision. A point is not necessarily a pip, a minimum executable tick, or a fixed amount of money. The midpoint itself can fall between quoted price increments, so a fractional point result is legitimate and does not imply that a trade could be executed at that midpoint.

Calculate the sample sequence
Use four consecutive candles with open, high, low and close values of (100,106,98,104), (104,110,102,108), (108,110,98,100) and (103,107,101,105). Their body midpoints are 102, 106, 104 and 104. With ExpressInPoints disabled, the second bar gives 106 − 102 = +4; the third gives 104 − 106 = −2; the fourth gives 104 − 104 = 0. The first loaded bar has no predecessor, so no change can be calculated for it.
The third candle has a much larger bearish body than the second bullish body. Its closing price is eight price units below the preceding close, but the body midpoint has moved only two units downward. This difference is expected: midpoint change describes the movement of both endpoints of the body, not just one. The fourth candle closes higher than the third yet produces zero midpoint change. In points mode, if the hypothetical symbol has _Point equal to 0.01, the same valid observations become +400, −200 and 0 points.
Complete MQL5 source
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "Body midpoint change"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrSteelBlue
#property indicator_width1 2
#property indicator_level1 0
input bool ExpressInPoints = true;
double MidpointChange[];
int OnInit()
{
// Bind first, then choose reverse series indexing.
if(!SetIndexBuffer(0, MidpointChange, INDICATOR_DATA))
return(INIT_FAILED);
ArraySetAsSeries(MidpointChange, true);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
IndicatorSetInteger(INDICATOR_DIGITS,
ExpressInPoints ? 2 : _Digits + 1);
IndicatorSetString(INDICATOR_SHORTNAME,
ExpressInPoints ? "Body Midpoint Change (points)"
: "Body Midpoint Change (price)");
if(ExpressInPoints && _Point <= 0.0)
return(INIT_FAILED);
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ArraySetAsSeries(open, true);
ArraySetAsSeries(close, true);
bool reset = prev_calculated <= 0 ||
prev_calculated > rates_total;
if(reset || rates_total < 3)
ArrayInitialize(MidpointChange, EMPTY_VALUE);
if(rates_total < 3)
return(0);
// Need both an evaluated bar and an older reference.
int oldest = rates_total - 2;
int start = oldest;
if(!reset)
start = (int)MathMin(oldest,
rates_total - prev_calculated + 1);
// The forming candle and oldest candle are unavailable.
MidpointChange[0] = EMPTY_VALUE;
MidpointChange[rates_total - 1] = EMPTY_VALUE;
for(int i = start; i >= 1; --i)
{
double current = 0.5 * open[i] + 0.5 * close[i];
double previous = 0.5 * open[i+1] + 0.5 * close[i+1];
double delta = current - previous;
if(!MathIsValidNumber(delta))
{
MidpointChange[i] = EMPTY_VALUE;
continue;
}
MidpointChange[i] = ExpressInPoints
? delta / _Point : delta;
}
return(rates_total);
}
How the program handles historical data
The indicator declares one output buffer and one histogram plot in a separate window. OnInit binds the buffer, sets its series indexing direction, registers EMPTY_VALUE as the missing-value marker, and selects a display precision appropriate to the output units. The additional digit in price mode makes half-point midpoints easier to inspect. This formatting does not round the internal calculation. The zero reference level helps distinguish positive from negative observations.
OnCalculate explicitly applies series indexing to the open and close arrays. This means index zero identifies the newest, currently forming candle; index one is the most recent completed candle; increasing indices identify older data. Each calculation at index i needs index i+1, so the oldest loaded bar has no valid output. At least three loaded bars are required to evaluate one completed bar with a predecessor while excluding the forming bar. When history is insufficient, the buffer is initialized to EMPTY_VALUE.
On a full calculation, the code clears all output and processes the eligible history. On subsequent calls, it uses prev_calculated to limit recalculation to the recent affected section, including the preceding completed candle when the chart advances. If the terminal requests a reset, the full history is processed again. Each bar requires a fixed number of operations, with no external indicator handle or rolling state. Using half of each endpoint before addition also avoids unnecessarily summing two potentially large price values.
Installation and verification
Open MetaEditor from MetaTrader 5, create a custom indicator named ConfirmedBodyMidpointChange, and replace its generated content with the complete source. Save it under MQL5/Indicators and compile. Review any compiler messages in the installed terminal before proceeding. Refresh Navigator if necessary, attach the indicator to a standard candlestick chart and inspect its separate panel. Switch ExpressInPoints off for the hand-calculation exercise. Open the Data Window to check numerical values rather than estimating histogram height visually. The code has not been compiled or executed in MT5 here.
Confirmation, repainting and external consumers
The current candle's opening price is normally fixed, but its close changes with live quotes. The midpoint of that body is therefore provisional until the bar ends. The implementation keeps buffer index zero empty and calculates the previous bar once a new bar is recognized. It draws the result at the completed candle's historical position, which must not be confused with availability during that candle. No future prices enter the calculation. Under unchanged historical prices and chart settings, the formula does not intentionally repaint completed observations. Broker corrections, chart reconstruction and input changes can nevertheless alter the displayed history.
An Expert Advisor can create an iCustom handle for the compiled indicator and obtain the most recent confirmed observation with CopyBuffer from buffer zero at shift one. Check the number of copied values and EMPTY_VALUE before interpreting the output. A true zero is a valid observation, not a missing result. Release the indicator handle when it is no longer required.
Testing and practical limitations
Test the supplied four-bar sequence, identical midpoints with different body lengths, a doji, consecutive increasing midpoints and declining midpoints. Inspect the first tick of a new candle, insufficient history, and a full chart reload. Verify the point conversion against the actual symbol property rather than assuming that every instrument uses two or five decimal places. Compare the output against a spreadsheet containing the same opening and closing prices. A midpoint change ignores intrabar extremes, volume, spread, liquidity and volatility. A positive displacement is not a reliable prediction of further gains. Study proposed filters on independent data and include transaction costs in any subsequent strategy evaluation.
For configurable smoothing, color thresholds, multi-timeframe calculations or EA integration, contact our Custom MT5 indicator Development Services.
Risk disclosure: this tutorial is educational, not investment advice. Trading involves risk of loss. Hypothetical examples do not establish profitability.