//+------------------------------------------------------------------+
//|                                            Supertrend_simple.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen

extern int  CCI_Period=50;
extern int  ATR = 5;
double Trend[];
//+------------------------------------------------------------------+
int init() {
  SetIndexBuffer(0, Trend);  SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
  return(0);
 }
//+------------------------------------------------------------------+
int deinit() {  return(0); }
//+------------------------------------------------------------------+
int start() {
  int limit, i;
  double  cciTrendNow;

  int counted_bars = IndicatorCounted();
  if(counted_bars < 0) return(-1);
  if(counted_bars > 0) counted_bars--;

  limit=Bars-counted_bars;
  for(i = limit; i >= 0; i--) {
    cciTrendNow = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, i);
     
    if (cciTrendNow > 0) {
       Trend[i] = Low[i] - iATR(NULL, 0, ATR, i);
       if (Trend[i] < Trend[i+1])  Trend[i] = Trend[i+1];
    }
    else if (cciTrendNow <= 0) {
       Trend[i] = High[i] + iATR(NULL, 0, ATR, i);
       if (Trend[i] > Trend[i+1])  Trend[i] = Trend[i+1];
    }
  }
  return(0);
 }
//+------------------------------------------------------------------+