Inflection color

 

If you want to change the color of the buffer, not based on turning points like usual (when the slope changes from negative to positive the color changes from red to green & vice versa), but on inflection points: when the first derivative changes signs, how would you code that? This is a start, but something tells me I need to use a loop and save that I am now in a "positive inflection" part, etc. Help pls!

#property indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Lime
#property  indicator_color2  Red

#property  indicator_width1 2
#property  indicator_width2 2

double up[];
double dn[];


extern int length=14;

int init()
  {
   SetIndexBuffer(0,up);
   SetIndexBuffer(1,dn);
   SetIndexStyle(0,DRAW_LINE);   
   SetIndexStyle(1,DRAW_LINE);
   IndicatorDigits(Digits+1);
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int limit;
   double cur,prev,pprev;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //ArrayIsSeries(ExtMapBuffer1);

   for(int i=0; i<limit; i++)
   {    
   cur=iCustom(0,0,"indicatorname",length,1,i);
   prev=iCustom(0,0,"indicatorname",length,1,i+1);
   pprev=iCustom(0,0,"indicatorname",length,1,i+2);
   
   
   if (prev < cur && (cur-prev)>(prev-pprev))
      {
       up[i]=cur;
       up[i+1]=prev;
      }
    if (prev > cur && (cur-prev)<(prev-pprev))
      {
       dn[i]=cur; 
       dn[i+1]=prev;
      }
   }

   return(0);
  }


 
Some mql4 coding problems almost same problem look to the solution
 
deVries:
Some mql4 coding problems almost same problem look to the solution
I don't think the issue is the changing colour bit . . . I think it's calculating where the point of inflexion is . . . I have my doubts it's possible due to the nature of the discontinuous X axis . .