Color ADX skips bar when changing from rising to falling/faling to rising

 

Hi to all,

and thanks for taking your time!

I want an ADX that shows green if the ADX is rising, red when its falling...for some reason I don't know it doesn't work with  the code below...can you please assist?

In the charts the bars where it changes form risng to falling ans other way around the bar is skipped...


Thanks in advance!

Lupo

//+------------------------------------------------------------------+
//|                                                    Color ADX.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green // rising ADX
#property indicator_color2 Red // falling ADX
//---- input parameters
extern int ADXPeriod=14;
//---- buffers
double ADXUpBuffer[];
double ADXDownBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers
   SetIndexBuffer(0,ADXUpBuffer);
   SetIndexBuffer(1,ADXDownBuffer);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Color ADX("+ADXPeriod+")");
   SetIndexLabel(0,"ADXUp");
   SetIndexLabel(1,"ADXDown");
//----
   SetIndexDrawBegin(0,ADXPeriod);
   SetIndexDrawBegin(1,ADXPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Average Directional Movement Index                               |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   for(int i=1;i<Bars;i++)
   {
      if(iADX(NULL,0,ADXPeriod,PRICE_CLOSE,0,i)>iADX(NULL,0,ADXPeriod,PRICE_CLOSE,0,(i+1)))     //rising ADX
         {
         ADXUpBuffer[i] = iADX(NULL,0,ADXPeriod,PRICE_CLOSE,0,i);
         ADXDownBuffer[i] = EMPTY_VALUE;
         }
      else  //falling ADX
         {
         ADXUpBuffer[i] = EMPTY_VALUE;
         ADXDownBuffer[i] = iADX(NULL,0,ADXPeriod,PRICE_CLOSE,0,i);
         }
   }  
//----
    return(0);
  }
//+------------------------------------------------------------------+
Color ADX
 
Lupo:

Hi to all,

and thanks for taking your time!

I want an ADX that shows green if the ADX is rising, red when its falling...for some reason I don't know it doesn't work with  the code below...can you please assist?

In the charts the bars where it changes form risng to falling ans other way around the bar is skipped...

It's been talked about in the last month or so,  search the Forum.  At the point where the colour changes both buffers need to hold the same value.

For example:  https://www.mql5.com/en/forum/143853

 
RaptorUK:

It's been talked about in the last month or so,  search the Forum.  At the point where the colour changes both buffers need to hold the same value.

For example:  https://www.mql5.com/en/forum/143853


Thanks to you, RaptorUK!
Reason: