Size Colored Candles
- Indicatori
- Versione: 1.2
Overview
SizeColoredCandles is a custom MetaTrader 5 indicator that automatically colors candlesticks according to their relative size. It helps traders visually identify unusually large, normal, and unusually small candles directly on the chart.
The indicator measures each candle’s range, compares it with recent market activity using a rolling statistical calculation, and assigns one of six customizable colors: tall bullish, tall bearish, normal bullish, normal bearish, small bullish, or small bearish.
As a secondary feature, SizeColoredCandles can also display candlesticks using rounded OHLC prices instead of the broker’s original price precision. This can make charts cleaner and easier to read when a broker provides an additional decimal digit.
The indicator can be used independently on a chart or integrated into an Expert Advisor through the standard MQL5 iCustom() and CopyBuffer() functions.
Main Features
1. Automatic Candle-Size Classification
The core feature of SizeColoredCandles is automatic classification and coloring of candles based on their size.
The indicator measures candle size using the full candle range:
Candle Range = High - Low
It then calculates the mean and population standard deviation of candle ranges over a configurable rolling window.
Each candle is evaluated against the preceding N candles, excluding itself. The statistical calculation uses the following formula:
Z-score = (Current Candle Range - Mean Range)/Standard Deviation
Based on the resulting Z-score, candles are classified as follows:
- Tall: Z-score is greater than or equal to the Tall Threshold.
- Normal: Z-score falls between the two thresholds.
- Small: Z-score is less than or equal to the Small Threshold.
For example, with a lookback period of 50 candles, a Tall Threshold of 1.5, and a Small Threshold of -0.5:
| Z-score | Classification |
|---|---|
| >= 1.5 | Tall |
| Between -0.5 and 1.5 | Normal |
| <=-0.5 | Small |
This approach adapts candle classification to changing market volatility rather than relying on fixed pip or point thresholds.
2. Dynamic Classification
The current forming candle is recalculated on every tick.
As its High or Low changes, its range and Z-score are updated, and its classification and color can change accordingly. For example, a candle may initially be classified as Small, then become Normal, and eventually Tall as its range expands.
Importantly, the current candle is never included in its own statistical reference window. Its classification is always compared against the preceding completed candles.
3. Customizable Candle Colors
The indicator supports six configurable colors:
- Tall Bullish
- Tall Bearish
- Normal Bullish
- Normal Bearish
- Small Bullish
- Small Bearish
This makes it easier to identify unusual market activity visually without relying on separate indicators.
4. Custom Price Rounding
As a secondary feature, the indicator can round Open, High, Low, and Close prices to a specified number of decimal digits.
Many Forex brokers quote prices with an additional decimal digit, often called a pipette. Although this provides greater price precision, it can sometimes make charts unnecessarily detailed and harder to read.
For example, with four decimal digits:
| Original price | Rounded price |
|---|---|
| 1.12643 | 1.1264 |
| 1.12648 | 1.1265 |
| 1.12687 | 1.1269 |
The rounding operation uses conventional nearest-value rounding. The number of decimal digits can be configured separately for each instrument.
Input Parameters
Price Rounding
| Parameter | Description |
|---|---|
| PriceDigits | Number of decimal digits used for rounded OHLC prices. Valid range: 0–8. |
Statistical Classification
| Parameter | Description |
|---|---|
| LookbackPeriod | Number of preceding candles used to calculate the mean and standard deviation. |
| TallThreshold | Minimum Z-score required to classify a candle as Tall. |
| SmallThreshold | Maximum Z-score allowed to classify a candle as Small. |
Candle Colors
| Parameter | Description |
|---|---|
| TallBullColor | Color of tall bullish candles. |
| TallBearColor | Color of tall bearish candles. |
| NormalBullColor | Color of normal bullish candles. |
| NormalBearColor | Color of normal bearish candles. |
| SmallBullColor | Color of small bullish candles. |
| SmallBearColor | Color of small bearish candles. |
Integration with Expert Advisors
SizeColoredCandles is designed to be used as a data provider for other MQL5 programs.
An Expert Advisor can create an indicator handle using iCustom() and retrieve its calculated values through CopyBuffer() .
The indicator exposes eight buffers:
| Buffer Index | Description |
|---|---|
| 0 | Rounded Open |
| 1 | Rounded High |
| 2 | Rounded Low |
| 3 | Rounded Close |
| 4 | Candle Color Index |
| 5 | Candle Classification |
| 6 | Candle Range |
| 7 | Candle Z-score |
Candle Classification Values
The classification buffer returns:
| Value | Meaning |
|---|---|
| +1 | Tall candle |
| 0 | Normal candle |
| -1 | Small candle |
| EMPTY_VALUE | Insufficient historical data |
Example: Creating an Indicator Handle
int handle = iCustom( _Symbol, _Period, "SizeColoredCandles",
4, // Price digits
50, // Lookback period
1.5, // Tall threshold
-0.5, // Small threshold
clrLimeGreen, // Tall bullish
clrRed, // Tall bearish
clrDodgerBlue, // Normal bullish
clrOrangeRed, // Normal bearish
clrSilver, // Small bullish
clrMagenta // Small bearish
);
Example: Reading Rounded OHLC
double open[], high[], low[], close[]; CopyBuffer(handle, 0, 0, 10, open); CopyBuffer(handle, 1, 0, 10, high); CopyBuffer(handle, 2, 0, 10, low); CopyBuffer(handle, 3, 0, 10, close);
The EA can also retrieve candle classification, range, and Z-score using buffers 5, 6, and 7.
Updating Parameters from an EA
MQL5 does not provide a direct mechanism to modify the input parameters of an existing custom indicator handle.
To apply new settings, the EA should:
- Release the existing indicator handle using IndicatorRelease() .
- Create a new handle with the updated parameters.
- Wait until the indicator has calculated its data.
- Read the buffers using CopyBuffer() .
This allows the EA to control price precision, lookback period, and classification thresholds dynamically.
Technical Notes
- Developed exclusively for MetaTrader 5 using MQL5.
- Uses the DRAW_COLOR_CANDLES drawing style.
- Classifies candles dynamically based on their range and recent volatility.
- Uses rounded OHLC values for candle range calculations.
- Uses population standard deviation.
- The current forming candle is excluded from its statistical reference window.
- The current candle is recalculated on every tick.
- The first candles without sufficient historical reference data do not have a valid statistical classification.
- The indicator does not generate trading signals or execute trades.
Intended Use
SizeColoredCandles can be useful for:
- Traders who want to visually distinguish unusually large, normal, and unusually small candles.
- Traders who analyze candle size and relative volatility.
- Traders who prefer cleaner charts with fewer displayed decimal digits.
- Developers building custom trading systems that require standardized OHLC data.
- Expert Advisors that use candle-range statistics as part of their trading logic.
SizeColoredCandles provides a visual, volatility-aware representation of candle size while preserving access to the original broker data through the underlying MT5 price series.
