!SupportingADX
Download scriptThis technical indicator is designed to analyze and visualize market momentum, specifically focusing on the strength and direction of price movements over a defined period. By processing historical price data, it provides a smoothed representation of market activity, helping traders distinguish between active trends and stagnant periods.
Core Operational Logic
The script functions by breaking down the price action into three distinct layers:
1. Directional Movement Tracking The logic begins by examining the "True Range" of each individual price bar. It compares the distance the price moved upward against the distance it moved downward.
- If the price moved up more than it moved down, that positive value is recorded.
- If the price moved down more than it moved up, that negative value is recorded.
- If there was no movement or equal movement in both directions, it is treated as neutral (zero).
2. Volatility and Range Assessment Simultaneously, the script calculates the volatility of the market. It looks for the maximum price range covered during a period—checking the distance between the highest and lowest points, as well as the distance between the previous closing price and the current high or low. This ensures that the indicator accounts for "gaps" or sudden spikes in price that might not be captured by simple movement tracking alone.
3. Strength and Smoothing (The ADX Calculation) The final step combines these elements to determine the overall trend strength:
- Relative Strength: It compares the directional movements against the total volatility. This tells the script how much of the market's total "effort" is actually moving in a specific direction.
- Smoothing: Because raw market data can be erratic and "noisy," the script applies a weighted smoothing calculation (based on a user-defined period, defaults to 14). This filters out minor fluctuations to produce a clean, readable line.
Visual Representation
The resulting output is a smooth blue line displayed in a separate window below your main price chart.
- Trend Strength: A rising line suggests that the market is gaining momentum and establishing a stronger trend.
- Market Exhaustion: A falling line indicates that the current trend is losing steam or that the market is entering a period of consolidation (sideways movement).
- Reference Level: The script includes a horizontal reference level (set at 35.0) to help traders quickly identify when the trend strength reaches a significant threshold.
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : purebeam@gmail.com
*/
#property indicator_separate_window
#property indicator_levelcolor White
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 2
#property indicator_level1 35.0
extern double n = 14.0;
extern int NumberOfBarsToUse = 500;
double gd_88;
double gd_96;
double gda_104[];
double gda_108[];
double gda_112[];
double gda_116[];
double gda_120[];
double gda_124[];
double gda_128[];
double gda_132[];
double gda_136[];
double g_ibuf_140[];
int init() {
SetIndexBuffer(0, g_ibuf_140);
SetIndexLabel(0, "ADX");
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, Blue);
SetIndexDrawBegin(0, 0);
ArrayResize(gda_104, Bars);
ArrayResize(gda_108, Bars);
ArrayResize(gda_112, Bars);
ArrayResize(gda_116, Bars);
ArrayResize(gda_120, Bars);
ArrayResize(gda_124, Bars);
ArrayResize(gda_128, Bars);
ArrayResize(gda_132, Bars);
ArrayResize(gda_136, Bars);
return (0);
}
int start() {
int li_0;
int li_4 = IndicatorCounted();
if (li_4 < 0) return (-1);
if (li_4 > 0) li_4--;
if (NumberOfBarsToUse == 0) li_0 = Bars;
else li_0 = NumberOfBarsToUse;
for (int li_8 = li_0 - 1; li_8 > 0; li_8--) {
gd_88 = High[li_8] - (High[li_8 + 1]);
gd_96 = Low[li_8 + 1] - Low[li_8];
if ((gd_88 < 0.0 && gd_96 < 0.0) || gd_88 == gd_96) {
gda_104[li_8] = 0;
gda_108[li_8] = 0;
} else {
if (gd_88 > gd_96) {
gda_104[li_8] = gd_88;
gda_108[li_8] = 0;
} else {
if (gd_88 < gd_96) {
gda_104[li_8] = 0;
gda_108[li_8] = gd_96;
}
}
}
gda_112[li_8] = (gda_112[li_8 + 1]) * (n - 1.0) / n + gda_104[li_8] / n;
gda_116[li_8] = (gda_116[li_8 + 1]) * (n - 1.0) / n + gda_108[li_8] / n;
gda_120[li_8] = MathMax(MathAbs(High[li_8] - Low[li_8]), MathAbs(High[li_8] - (Close[li_8 + 1])));
gda_120[li_8] = MathMax(gda_120[li_8], MathAbs(Close[li_8 + 1] - Low[li_8]));
gda_124[li_8] = (gda_124[li_8 + 1]) * (n - 1.0) / n + gda_120[li_8] / n;
if (gda_124[li_8] > 0.0) {
gda_128[li_8] = 100.0 * (gda_112[li_8] / gda_124[li_8]);
gda_132[li_8] = 100.0 * (gda_116[li_8] / gda_124[li_8]);
if (gda_128[li_8] + gda_132[li_8] > 0.0) gda_136[li_8] = 100.0 * (MathAbs(gda_128[li_8] - gda_132[li_8]) / (gda_128[li_8] + gda_132[li_8]));
else gda_136[li_8] = 0;
} else gda_136[li_8] = 0;
g_ibuf_140[li_8] = (g_ibuf_140[li_8 + 1]) * (n - 1.0) / n + gda_136[li_8] / n;
}
return (0);
}
Comments