//+------------------------------------------------------------------+
//|                                                  IINWMARROWS.mq4 |
//|                                           Based on EMA_CROSS.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//|                           Last little modified by Iin Zulkarnain |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
double CrossUp[];
double CrossDown[];
extern int       ADX_Period=10; 
extern double    threshold= 30;
extern int Mode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int MA=  2;
extern int vMA = 3;
extern int xMA = 3;
extern int yMA = 2;
extern int zMA = 3;
extern double dist = 0.3;
extern int devi = 0;
extern int oops1 = 0;
extern int oops2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double ADX,ADXb,ADXs;
   double ma_close,ma_open,ma_future;
   double vma_close,vma_open,vma_future;
   double xma_close,xma_open,xma_future;
   double yma_close,yma_open,yma_future;
   double zma_close,zma_open,zma_future;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
//----
   limit=Bars-counted_bars;
     for(i=0; i<=limit; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i ;counter<=i+9;counter++)
        {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
        }
      Range=AvgRange/10;
      ADX = iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_MAIN,i);
      ADXb = iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_PLUSDI,i);
      ADXs = iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_MINUSDI,i);
      
      ma_close=iMA(NULL, 0, MA, 0, 2, PRICE_CLOSE, i);
      ma_open=iMA(NULL, 0, MA, 0, 2, PRICE_OPEN, i);
      ma_future=iMA(NULL, 0,MA, -1, 2, PRICE_CLOSE,i);
      
      vma_close=iMA(NULL, 0, vMA, 0, 2, PRICE_CLOSE, i);
      vma_open=iMA(NULL, 0, vMA, 0, 2, PRICE_OPEN, i);
      vma_future=iMA(NULL, 0,vMA, -1, 2, PRICE_CLOSE,i);
      
      xma_close=iMA(NULL, 0, xMA, 0, Mode, PRICE_CLOSE, i);
      xma_open=iMA(NULL, 0, xMA, 0, Mode, PRICE_OPEN, i);
      xma_future=iMA(NULL, 0,xMA, -1, Mode, PRICE_CLOSE,i);
      
      yma_close=iMA(NULL, 0, yMA, 0, Mode, PRICE_CLOSE, i);
      yma_open=iMA(NULL, 0, yMA, 0, Mode, PRICE_OPEN, i);
      yma_future=iMA(NULL, 0,yMA, -1, Mode, PRICE_CLOSE,i);
      
      zma_close=iMA(NULL, 0, zMA, 0, Mode, PRICE_CLOSE, i);
      zma_open=iMA(NULL, 0, zMA, 0, Mode, PRICE_OPEN, i);
      zma_future=iMA(NULL, 0,zMA, -1, Mode, PRICE_CLOSE,i);
      double dev = devi*Point;
      
     // Comment( "buy= " + ((ma_future > ma_close) && (ma_close>ma_open)) + "\nsell= " + ((ma_future<ma_close) && (ma_close<ma_open)));
      
      bool b1 = (ma_future-ma_close > dev)   && (ma_close-ma_open > dev);
      bool b2 = (vma_future-vma_close > dev) && (vma_close-vma_open > dev);
      bool b3 = (xma_future-xma_close > dev) && (xma_close-xma_open > dev);
      bool b4 = (yma_future-yma_close > dev) && (yma_close-yma_open > dev);
      bool b5 = (zma_future-zma_close > dev) && (zma_close-zma_open > dev);
      
      bool s1 = (ma_close-ma_future > dev ) && (ma_open-ma_close > dev );
      bool s2 = (vma_close-vma_future > dev ) && (vma_open-vma_close > dev );
      bool s3 = (xma_close-xma_future > dev ) && (xma_open-xma_close > dev );
      bool s4 = (yma_close-yma_future > dev ) && (yma_open-yma_close > dev );
      bool s5 = (zma_close-zma_future > dev ) && (zma_open-zma_close > dev );
      
        if (b1 && b2 && b3 && b4 && b5 && ((ADX > threshold)&&(ADXb>ADXs))) 
        {
         CrossUp[i]=Close[i] + Range*dist;
        }
        else if (s1 && s2 && s3 && s4 && s5 && ((ADX>threshold)&&(ADXs>ADXb))) 
        {
            CrossDown[i]=Close[i] - Range*dist;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+