//+------------------------------------------------------------------+
//|                                 support and resistance doris.mq4 |
//|                                                           .....h |
//|                                                    hayseedfx.com |
//+------------------------------------------------------------------+
#property copyright ".....h"
#property link      "hayseedfx.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime


extern int support    =    242;
extern int resistance =    241;
//extern int limit      =     50;

double zig;
double zag;
double zigs[];
double zags[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  
int init()
  {

//---- 
  
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Red);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Lime);
   
   SetIndexBuffer(0, zigs);
   SetIndexBuffer(1, zags);
   
   SetIndexArrow(0, support);
   SetIndexArrow(1, resistance);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("high");
   ObjectDelete("low");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars = IndicatorCounted();
   int    i;
   int    lls,lhs;
   double high,low,lasthigh,lastlow;

   i=Bars;               // limit
   while(i>=0)
     {
   
 zig = iCustom(NULL,0,"ZigZag",1,i);   
   if(zig > 0) 
      {
      zigs[i]= High[i];
      lhs    = i;
      }
      else
      zigs[i] = zigs[i+1];
  
 zag = iCustom(NULL,0,"ZigZag",2,i); 
   if(zag > 0)
      { 
      zags[i] = Low[i];
      lls  = i;
      }
      else
      zags[i] = zags[i+1];

      i--;
     }   


      
         high = lasthigh; 
           if(zigs[1] != 0.0) high = zigs[1]; else high = high;
           ObjectCreate("high", OBJ_TREND, 0, Time[lhs], high, Time[0],high); 
           ObjectSet("high", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("high", OBJPROP_COLOR, Blue);                  
           ObjectSet("high", OBJPROP_WIDTH, 2);
           ObjectSet("high", OBJPROP_RAY, true); 
           ObjectSet("high", OBJPROP_BACK,true);

           low = lastlow;
           if(zags[1] != 0.0) low = zags[1]; else low = low;
           ObjectCreate("low", OBJ_TREND, 0, Time[lls], low, Time[0],low);
           ObjectSet("low", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("low", OBJPROP_COLOR, Red);                  
           ObjectSet("low", OBJPROP_WIDTH, 2);
           ObjectSet("low", OBJPROP_RAY, true); 
           ObjectSet("low", OBJPROP_BACK,true);     
     
     
     
     
     
   return(0);
  }
 
//+------------------------------------------------------------------+


