Advanced Trading Tutorial — Closed-bar body pressure in MT4

A large candle is not necessarily a directional candle. A wide range may contain a small real body, indicating that price traveled substantially but finished close to its opening level. This tutorial builds a normalized signed body histogram that separates directional displacement from total intrabar range. It is a diagnostic indicator, not an entry system.

Calculation and interpretation

For each completed candle calculate (Close − Open)/(High − Low). The result lies between −1 and +1 for valid OHLC data. Positive values indicate upward displacement, negative values indicate downward displacement, and zero means the open and close coincide. A zero-range candle is assigned zero to avoid division by zero. The measure is dimensionless, so a five-point candle and a fifty-point candle can have the same reading. This is useful when comparing candle structure across instruments, but it deliberately discards absolute volatility.

Closed-Bar Body Pressure Histogram in MQL4
Five hypothetical closed candles with pressure values +0.2, +0.6, −0.4, +0.8 and −0.2.

For example, an open of 100, high of 110, low of 100 and close of 106 gives +0.6. An open of 106, high of 110, low of 100 and close of 102 gives −0.4. A reading of +0.8 represents stronger upward body displacement relative to its own range, not necessarily more buying volume. OHLC data cannot reveal the actual sequence of trades within the bar.

Native MQL4 indicator

The indicator uses one output buffer and a separate histogram window. The fixed scale makes comparisons straightforward. The buffer is bound before setting its series orientation, because binding can reset array indexing. The input price arrays are explicitly oriented as series, so index zero denotes the currently forming candle and index one denotes the latest completed candle.

#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_level1 0
double Pressure[];
int OnInit()
{
   SetIndexBuffer(0,Pressure);
   ArraySetAsSeries(Pressure,true);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   IndicatorShortName("Closed Body Pressure");
   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(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   // Never publish a value for the forming candle.
   Pressure[0]=EMPTY_VALUE;
   int limit=rates_total-1;
   if(prev_calculated>0 && prev_calculated<=rates_total)
      limit=MathMin(limit,rates_total-prev_calculated+1);
   for(int i=limit;i>=1;i--)
   {
      double range=high[i]-low[i];
      // A zero-range candle is neutral.
      Pressure[i]=(range>0)?(close[i]-open[i])/range:0.0;
   }
   return(rates_total);
}

Incremental calculation

On the first calculation the loop fills all available closed bars. Subsequent calls use prev_calculated to restrict work to newly available bars plus a small overlap. If the terminal resets prev_calculated after loading deeper history, the full calculation is repeated. The forming bar is explicitly assigned EMPTY_VALUE on every call. This prevents a partially formed candle from appearing as a confirmed reading. A new closed value becomes visible when the next bar is recognized by the terminal, usually on the next incoming tick.

Installation and practical workflow

Open MetaEditor from MT4, create a custom indicator named ClosedBodyPressure, replace the template with the source above and compile. Refresh the Navigator if needed and attach the indicator to a chart. Begin with a liquid instrument on a fifteen-minute timeframe. Compare the histogram with the candle bodies rather than treating every positive reading as a buy signal. A sequence of positive readings during a rising market may support a directional interpretation, whereas alternating signs during a narrow consolidation may suggest a lack of sustained displacement. These are hypotheses for investigation, not validated trading rules.

Testing and limitations

Manually verify the two numerical examples above. Test a doji, a zero-range candle, a large gap, a chart refresh and a timeframe change. Observe the last completed bar during several ticks of the next candle; its value should remain unchanged unless the underlying historical data is revised. No future bars are used and the implementation does not intentionally repaint completed candles. Broker corrections can nevertheless alter historical OHLC data. The indicator ignores volume, gaps between candles and absolute volatility. A high reading in an illiquid market may be less meaningful than a moderate reading in an active market. Consider an independent ATR filter when researching volatility context. This source has not been compiled or tested in MT4 here; verify it in your own terminal before use.

For additional filters or integration with an Expert Advisor, contact our Custom MT4 indicator Development Services.

Risk disclosure: educational material only. Trading involves risk of loss; hypothetical examples do not establish profitability.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.