/*+-------------------------------------------------------------------+
  |                                                          iMAX.mq4 |
  |                                                                   |
  | "Modified Optimum Elliptic Filter"                                |
  | Source of calculations:                                           |
  | Stocks & Commodities vol 18:7 p20-29                              |
  | Optimal Detrending by John F. Ehlers                              |
  |                                                                   |
  |                                                    Coded by Wylie |
  |                                              dazzle.html@live.com |
  +-------------------------------------------------------------------+*/

#property copyright "Wylie"
#property link      "dazzle.html@live.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Magenta
#property indicator_width1 2
#property indicator_width2 2

extern int Ph2shiftRed = 1;

int buffers = 2;
int MinBars;

double ExtMapBuffer0[];
double ExtMapBuffer1[];

int init()
{
 IndicatorBuffers(2);

 // Index Buffer 0

 SetIndexBuffer(0,ExtMapBuffer0);
 SetIndexShift(0,0);
 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,LawnGreen);

 // Index Buffer 1

 SetIndexBuffer(1,ExtMapBuffer1);
 SetIndexShift(1,0);
 SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Magenta);

 IndicatorShortName("iMAX");
 MinBars = 20;

 return (0);
} // int init()
  
int start()
{    
 if(Bars <= MinBars){return (0);}

 int countedBars = IndicatorCounted();

 if(countedBars < 0){return (-1);}
 if(countedBars > 0){countedBars--;}

 int c,limit = Bars - countedBars - 1;
 double x = 0.5;

 for(c = limit;c >= 0;c--)
     {ExtMapBuffer0[c] = (0.13785 * (2 * ((High[c]   + Low[c])   * x) - ((High[c+1] + Low[c+1]) * x)))
                       + (0.0007  * (2 * ((High[c+1] + Low[c+1]) * x) - ((High[c+2] + Low[c+2]) * x)))
                       + (0.13785 * (2 * ((High[c+2] + Low[c+2]) * x) - ((High[c+3] + Low[c+3]) * x)))
                       + (1.2103  * ExtMapBuffer0[c + 1] - 0.4867 * ExtMapBuffer0[c + 2]); 

      ExtMapBuffer1[c] = ExtMapBuffer0[c+Ph2shiftRed];
     } // for(c = limit;c >= 0;c--)

 return (0);  
} // int start()

/*+-------------------------------------------------------------------+
  |                                                                   |
  +-------------------------------------------------------------------+*/

