//+------------------------------------------------------------------+
//| Web:                                             AO_Adaptive.mq4 |
//|                                                           MNS777 |
//|                                                mns777.ru@mail.ru |
//+------------------------------------------------------------------+
#property copyright "MNS777"
#property link      "Web:" 
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5

#property  indicator_color2  Green
#property  indicator_color3  Red

//---- ٍîëùèيà èينèêàٍîًيûُ ëèيèé

#property indicator_width2 3
#property indicator_width3 3
//---- ïàًàىهًٍû مîًèçîيٍàëüيûُ ًَîâيهé èينèêàٍîًà
#property indicator_level1  0


#property indicator_levelcolor Yellow
#property indicator_levelstyle 2


//---- آصخؤحغإ دہذہجإزذغ بحؤبتہزخذہ ‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏وو+
extern int PriceMA1 = 5 ;
extern int MinPeriod1=5;
extern int MaxPeriod1=10;
extern int LevelStdDevPoint1=8;
extern int Smooth1=1;

extern int PriceMA2 = 5 ;
extern int MinPeriod2=34;
extern int MaxPeriod2=68;
extern int LevelStdDevPoint2=8;
extern int Smooth2=1;

extern int MaxBars = 1000 ; // لàًîâ èٌٍîًèè

//---- ووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووو+

//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
double     ExtBuffer3[];
double     ExtBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_NONE);
  
   IndicatorDigits(Digits+2);
   SetIndexDrawBegin(0,Digits);
   SetIndexDrawBegin(1,Digits);
   SetIndexDrawBegin(2,Digits);
   SetIndexDrawBegin(3,Digits);
   SetIndexDrawBegin(4,Digits);
//---- 4 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
   SetIndexBuffer(3,ExtBuffer3);
   SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("AO_Adaptive");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
    
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double current,prev;
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=MaxBars;
   //---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      ExtBuffer3[i]=iCustom(NULL,0,"EMA_Adaptive_v22Price",PriceMA1,MinPeriod1,MaxPeriod1,LevelStdDevPoint1,Smooth1,0,i)-iCustom(NULL,0,"EMA_Adaptive_v22Price",PriceMA2,MinPeriod2,MaxPeriod2,LevelStdDevPoint2,Smooth2,0,i);
   //---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,1,0,0,i);
   //---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtBuffer4[i];
      prev=ExtBuffer4[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
       ExtBuffer0[i]=current;
     }
   //---- done
   return(0);
  }
//+------------------------------------------------------------------+


