//+------------------------------------------------------------------+
//| ADX Crossing.mq4 
//+------------------------------------------------------------------+
#property  copyright "Author - Amir, modified by akadex"

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

//---- input parameters
extern int ADXbars=14;
extern int mabars=50;
extern int ma1bars=120;
extern int CountBars=1000;
extern int STD.Rgres.period=0;
extern int STD.Rgres.length=56;
extern double STD.Rgres.width=1.618;

//---- buffers
double val1[],val2[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi,m50,m120,one,two,trend=0,c,b,a,starttime,grad,hi,lo;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,108);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,108);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
//----
   return(0);
  }
  int deinit()
  { ObjectsDeleteAll(0, OBJ_STDDEVCHANNEL); ObjectsDeleteAll(0, OBJ_TRENDBYANGLE); ObjectsDeleteAll(0, OBJ_TREND); Comment(""); return(0);}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2                                            |
//+------------------------------------------------------------------+
int start()
  {   
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars);
   SetIndexDrawBegin(1,Bars-CountBars);

   int i,shift,counted_bars=IndicatorCounted();


   //---- check for possible errors
   if(counted_bars<0) return(-1);

   //---- initial zero
   if(counted_bars<1)
     {
      for(i=1;i<=CountBars;i++) val1[CountBars-i]=0.0;
      for(i=1;i<=CountBars;i++) val2[CountBars-i]=0.0;
     } 

for (shift = CountBars; shift>=0; shift--) 
{ 
   starttime=iTime(Symbol(),STD.Rgres.period,STD.Rgres.length);
   ObjectCreate("regression channel",OBJ_STDDEVCHANNEL,0,starttime,Bid,Time[0],Ask);
   ObjectSet("regression channel",OBJPROP_TIME1,starttime);
   ObjectSet("regression channel",OBJPROP_TIME2,Time[0]);
   ObjectSet("regression channel",OBJPROP_DEVIATION,STD.Rgres.width);
   ObjectSet("regression channel",OBJPROP_RAY,true);
   one=ObjectGet("regression channel", OBJPROP_PRICE1);
   two=ObjectGet("regression channel", OBJPROP_PRICE2);
   if (one<two) {trend=1; b=two-one;}
   if (one>two) {trend=-1; b=one-two;}

  ObjectCreate("grad channel",OBJ_TRENDBYANGLE,0,0,0);
  ObjectSet("grad channel",OBJPROP_WIDTH,3);
  ObjectSet("grad channel",OBJPROP_TIME1,starttime);
  ObjectSet("grad channel",OBJPROP_TIME2,Time[0]);
  ObjectSet("grad channel",OBJPROP_PRICE1,one);
  ObjectSet("grad channel",OBJPROP_PRICE2,two); 
  grad=ObjectGet("grad channel", OBJPROP_ANGLE);
      
   hi=iHigh(NULL,PERIOD_D1,1);
   lo=iLow(NULL,PERIOD_D1,1);
      ObjectCreate("HDayBorder", OBJ_TREND, 0, 0,0, 0,0);
    ObjectSet("HDayBorder", OBJPROP_TIME1, StrToTime(TimeToStr(Time[STD.Rgres.length], TIME_DATE)+" 00:00"));
    ObjectSet("HDayBorder", OBJPROP_TIME2, Time[0]);
    ObjectSet("HDayBorder", OBJPROP_PRICE1, hi);
    ObjectSet("HDayBorder", OBJPROP_PRICE2, hi);
    ObjectSet("HDayBorder", OBJPROP_COLOR, Blue);
    ObjectSet("HDayBorder", OBJPROP_STYLE, STYLE_DASH);
        
      ObjectCreate("LDayBorder", OBJ_TREND, 0, 0,0, 0,0);
    ObjectSet("LDayBorder", OBJPROP_TIME1, StrToTime(TimeToStr(Time[STD.Rgres.length], TIME_DATE)+" 00:00"));
    ObjectSet("LDayBorder", OBJPROP_TIME2, Time[0]);
    ObjectSet("LDayBorder", OBJPROP_PRICE1, lo);
    ObjectSet("LDayBorder", OBJPROP_PRICE2, lo);
    ObjectSet("LDayBorder", OBJPROP_COLOR, Red);
    ObjectSet("LDayBorder", OBJPROP_STYLE, STYLE_DASH);
   
   Comment ("\nУгол отклонения тренда = ",grad,"\nТренд = ",trend,"\nУровень сопротивления = ",hi,"\nУровень поддержки = ",lo);

	b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift-1);
	nowplusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift);
	b4minusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift-1);
	nowminusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift);



if (b4plusdi>b4minusdi && nowplusdi<nowminusdi)
{
	val1[shift]=Low[shift]-5*Point;
}
if (b4plusdi<b4minusdi && nowplusdi>nowminusdi) 
{
	val2[shift]=High[shift]+5*Point;
}
}

   return(0);
  }
//+------------------------------------------------------------------+