Indicators Used
Miscellaneous
2
Views
1
Downloads
0
Favorites
ADX Candles
//+------------------------------------------------------------------+
//| 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
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---