ADX Candles
Download scriptThis tool is designed to enhance your trading chart by visually translating complex momentum and trend data into easy-to-read candle colors. Instead of forcing you to constantly monitor separate technical oscillators, this script integrates the logic of the ADX (Average Directional Index) directly into the visual price bars on your screen.
How the Logic Works
The script analyzes three specific components of market momentum to determine how your candles should be colored:
- Trend Strength (ADX): It measures how powerful the current market movement is.
- Buying Pressure (PlusDI): It identifies the strength of upward momentum.
- Selling Pressure (MinusDI): It identifies the strength of downward momentum.
By comparing these three factors against a user-defined "Signal Level," the script categorizes every candle into one of four distinct market states:
Visual Color Coding
The chart will automatically update colors based on the following conditions:
- Weak Upward Movement: When buying pressure is higher than selling pressure, but the overall trend strength is low (below your signal level).
- Weak Downward Movement: When selling pressure is higher than buying pressure, but the overall trend strength remains low.
- Strong Upward Trend: When buying pressure dominates and the market shows significant, high-strength momentum (above your signal level).
- Strong Downward Trend: When selling pressure dominates and the market shows significant, high-strength momentum (above your signal level).
Key Features for Traders
- Heiken Ashi Compatibility: The logic includes an option to calculate prices based on "Heiken Ashi" values, which smooths out price action to help filter out market noise.
- Visual Clarity: By using different thicknesses and colors (such as Lime and Red for high-strength trends vs. Dark Green and Maroon for weaker movements), it allows you to identify the "health" of a trend at a single glance.
- Customizable Thresholds: You can adjust the period and the signal level to match your specific trading style, whether you prefer to capture small early moves or only trade high-velocity trends.
//+------------------------------------------------------------------+
//| ADX Candles.mq4 |
//+------------------------------------------------------------------+
#property copyright "Code adapted by cja"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DarkGreen
#property indicator_color2 Maroon
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 DarkGreen
#property indicator_color6 Maroon
#property indicator_color7 Lime
#property indicator_color8 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 3
#property indicator_width6 3
#property indicator_width7 3
#property indicator_width8 3
//---- indicator parameters
extern int ADXPeriod=14;
extern int ADXSignal_Level = 21;
double Bar1[],
Bar2[],
Bar3[],
Bar4[],
Candle1[],
Candle2[],
Candle3[],
Candle4[];
extern int BarWidth = 1,
CandleWidth = 3;
extern bool HeikenAshi = false;
double b4plusdi,b4minusdi,nowplusdi,nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("ADX Candles");
IndicatorBuffers(8);
SetIndexBuffer(0,Bar1);
SetIndexBuffer(1,Bar2);
SetIndexBuffer(2,Bar3);
SetIndexBuffer(3,Bar4);
SetIndexBuffer(4,Candle1);
SetIndexBuffer(5,Candle2);
SetIndexBuffer(6,Candle3);
SetIndexBuffer(7,Candle4);
SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(2,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(3,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(4,DRAW_HISTOGRAM,0,CandleWidth);
SetIndexStyle(5,DRAW_HISTOGRAM,0,CandleWidth);
SetIndexStyle(6,DRAW_HISTOGRAM,0,CandleWidth);
SetIndexStyle(7,DRAW_HISTOGRAM,0,CandleWidth);
return(0);
}
int deinit()
{
//----
//----
return(0);
}
double plusdi (int i = 0){return(iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_PLUSDI,i));}
double minusdi (int i = 0){return(iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_MINUSDI,i));}
double ADX (int i = 0){return(iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_MAIN,i));}
void SetCandleColor(int col, int i)
{
double high,low,bodyHigh,bodyLow;
if(HeikenAshi)
{
double lastBodyHigh = MathMax(Candle1[i+1],MathMax(Candle2[i+1],MathMax(Candle3[i+1],Candle4[i+1]))),
lastBodyLow = MathMin(Candle1[i+1],MathMin(Candle2[i+1],MathMin(Candle3[i+1],Candle4[i+1]))),
haOpen = 0.5*(lastBodyHigh+lastBodyLow),
haClose = 0.25*(Open[i]+High[i]+Low[i]+Close[i]);
bodyHigh = MathMax(haOpen,haClose);
bodyLow = MathMin(haOpen,haClose);
high = MathMax(High[i],bodyHigh);
low = MathMin(Low[i], bodyLow);
}
else
{
bodyHigh = MathMax(Open[i],Close[i]);
bodyLow = MathMin(Open[i],Close[i]);
high = High[i];
low = Low[i];
}
Bar1[i] = low; Candle1[i] = bodyLow;
Bar2[i] = low; Candle2[i] = bodyLow;
Bar3[i] = low; Candle3[i] = bodyLow;
Bar4[i] = low; Candle4[i] = bodyLow;
switch(col)
{
case 1: Bar1[i] = high; Candle1[i] = bodyHigh; break;
case 2: Bar2[i] = high; Candle2[i] = bodyHigh; break;
case 3: Bar3[i] = high; Candle3[i] = bodyHigh; break;
case 4: Bar4[i] = high; Candle4[i] = bodyHigh; break;
}
}
int start()
{
for(int i = MathMax(Bars-1-IndicatorCounted(),1); i>=0; i--)
{
double Plusdi = plusdi(i);
double Minusdi = minusdi(i);
double adx = ADX(i);
if((Plusdi > Minusdi)&&(adx < ADXSignal_Level)) SetCandleColor(1,i);
else if((Plusdi < Minusdi)&&(adx < ADXSignal_Level)) SetCandleColor(2,i);
else if((Plusdi > Minusdi) &&(adx > ADXSignal_Level)) SetCandleColor(3,i);
else if((Plusdi < Minusdi) &&( adx > ADXSignal_Level)) SetCandleColor(4,i);
}
return(0);
}
Comments