J'ai mis un certain temps à appréhender l'ADX fourni avec Metatrader 4 et je me suis dit qu'une simple consolidation des courbes (différence des +DI et -DI multiplié par l'ADX) pourrait donner des indications intéressantes.
On voit grâce à cet indic les gros mouvements, souvent initiateurs de retournement.
On voit grâce à cet indic les gros mouvements, souvent initiateurs de retournement.
Code
//+------------------------------------------------------------------+
//| ADX.mq4 |
//| Copyright © 2011, Nicolas Tuffier |
//| http://www.furyweb.fr/forex/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Nicolas Tuffier"
#property link "http://www.furyweb.fr/forex/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 ForestGreen
#property indicator_color2 Red
#property indicator_width1 4
#property indicator_width2 4
//--- input parameters
extern int period=13;
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, counted_bars=IndicatorCounted();
double adx;
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
//---- the first bar must be skipped
if(counted_bars == 0)
counted_bars++;
limit = Bars - counted_bars;
//----
for (int i = limit ; i >= 0 ; i--) {
adx = (iADX(NULL, 0, period, PRICE_CLOSE, MODE_PLUSDI, i) - iADX(NULL, 0, period, PRICE_CLOSE, MODE_MINUSDI, i)) * iADX(NULL, 0, period, PRICE_CLOSE, MODE_MAIN, i);
if (adx > 0) {
ExtMapBuffer1[i] = adx;
ExtMapBuffer2[i] = EMPTY_VALUE;
} else {
ExtMapBuffer1[i] = EMPTY_VALUE;
ExtMapBuffer2[i] = adx;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+