ADX with Zones – Trend Strength Classification
ADX with Zones is an enhanced Average Directional Index (ADX) indicator designed to make trend strength easier to identify and interpret through customizable zones, color-coded labels, and visual reference levels.
Rather than displaying ADX as a standalone line, this indicator classifies trend strength into four distinct zones:
- 🔴 **No Trend (ADX
describe_indicator('ADX with Zones', 'lower');
// This indicator plots the ADX line along with three
// reference levels (Lower, Middle, Upper) that you can
// use to visually classify trend strength zones. It also
// prints a text label (zone classification) repeated at
// a user defined interval of candles.
const myLength = input.number('ADX Length', 14, { min: 1, max: 200 });
const myLowerLevel = input.number('Lower Level', 20, { min: 0, max: 100 });
const myMiddleLevel = input.number('Middle Level', 40, { min: 0, max: 100 });
const myUpperLevel = input.number('Upper Level', 60, { min: 0, max: 100 });
const myLabelInterval = input.number('Label Interval (candles)', 20, { min: 1, max: 500 });
const myAdxObject = indicators.adx(myLength);
const myAdxLinePainted = paint(myAdxObject.adx, { name: 'ADX', color: '#4DA3FF', thickness: 2 });
// Opacity set to 25% as requested
paint(horizontal_line(myLowerLevel), { name: 'LowerLevel', color: 'gray', style: 'line', opacity: 0.25 });
paint(horizontal_line(myMiddleLevel), { name: 'MiddleLevel', color: 'gray', style: 'line', opacity: 0.25 });
paint(horizontal_line(myUpperLevel), { name: 'UpperLevel', color: 'gray', style: 'line', opacity: 0.25 });
// Determines the zone text and color for a given ADX value
function myZoneTextFor(_value) {
if (_value === null || _value === undefined || isNaN(_value)) {
return null;
}
if (_value < myLowerLevel) {
return { text: 'No Trend', color: 'red' };
}
if (_value < myMiddleLevel) {
return { text: 'Moderate Trend', color: '#90EE90' };
}
if (_value < myUpperLevel) {
return { text: 'Strong Trend', color: 'green' };
}
return { text: 'Extremely Strong Trend', color: 'orange' };
}
// Places labels at a fixed candle interval, since labels must be
// painted on an already existing line and label names/positions
// must be deterministic (same on every run).
for (let myIndex = 0; myIndex < myAdxObject.adx.length; myIndex += myLabelInterval) {
const myZone = myZoneTextFor(myAdxObject.adx[myIndex]);
if (myZone) {
paint_label_at_line(myAdxLinePainted, myIndex, myZone.text, {
color: myZone.color,
vertical_align: 'top'
});
}
}
register_signal(for_every(myAdxObject.adx, _v => _v > myUpperLevel), 'ADX Above Upper Level');
register_signal(for_every(myAdxObject.adx, _v => _v < myLowerLevel), 'ADX Below Lower Level');