
//+------------------------------------------------------------------+
//|                                                        NDuet.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 HotPink


extern int sper=55;
extern int fper=21;
extern int nBar=300;
extern int per=14;

double mas[];
double maf[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{//1
   SetIndexBuffer(0,mas);
   SetIndexBuffer(1,maf);
   return(0);
}//1
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{//1
   ObjectsDeleteAll(0);
   return(0);
}//1
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{//1
   int limit=0,i=0,blokb=0,bloks=0;
   double mstwo=0,mftwo=0,cci=0,trend=0;
   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(i=0; i<limit; i++)
   {//2
      cci=iCCI(NULL,0,per,PRICE_CLOSE,i);
      trend=((Close[i+fper]-Close[i])/Point);
      mas[i]=iMA(NULL,0,sper,0,MODE_EMA,PRICE_CLOSE,i);
      mstwo =iMA(NULL,0,sper,0,MODE_EMA,PRICE_CLOSE,i+2);

      maf[i]=iMA(NULL,0,fper,0,MODE_EMA,PRICE_CLOSE,i);
      mftwo =iMA(NULL,0,fper,0,MODE_EMA,PRICE_CLOSE,i+2);

      if((mas[i]>maf[i])&&((mas[i]-maf[i])/Point<10)&&((mas[i]-maf[i])/Point>=1)
      &&(mstwo<mftwo)&&(cci<0)&&(trend>0)&&(bloks==0))
      {//3
         string Name1="S"+i;
         double Price1=NormalizeDouble(High[i]+10*Point,Digits);
         ObjectCreate(Name1,OBJ_ARROW,0,Time[i],Price1);
         ObjectSet(Name1,OBJPROP_ARROWCODE,242);
         ObjectSet(Name1,OBJPROP_COLOR,Aqua);
         ObjectSetText(Name1,"Sell",10,"Times New Roman",Aqua);         
         bloks=1;
         blokb=0;
      }//3
      
      if((mas[i]<maf[i])&&((maf[i]-mas[i])/Point<10)&&((maf[i]-mas[i])/Point>=1)
      &&(mstwo>mftwo)&&(cci>0)&&(trend<0)&&(blokb==0))
      {//3
         string Name2="B"+i;
         double Price2=NormalizeDouble(Low[i]-10*Point,Digits);
         ObjectCreate(Name2,OBJ_ARROW,0,Time[i],Price2);
         ObjectSet(Name2,OBJPROP_ARROWCODE,241);
         ObjectSet(Name2,OBJPROP_COLOR,Red);
         ObjectSetText(Name2,"Buy",10,"Times New Roman",Aqua);         
         blokb=1;
         bloks=0;
      }//3
   }//2   
   return(0);
}//1
//+------------------------------------------------------------------+




