//KurlFX 2009/1/29
//+-------------------------------------------------------------------------+
//|    *** MTFPI-sub1 ***                                                   |
//+-------------------------------------------------------------------------+
#property copyright "Copyright (c) 2009,Kurl FX"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color2 Blue

extern int FastEMA = 5;
extern int SlowEMA = 100;
extern int SignalSMA = 3;
extern int K_Period = 5;
extern int D_Period = 3;
extern int Slowing = 3;

double BS[];//Buy/Sell sign: -1;0;1
double GS[];//Go/Stop price: Entry or LossCutPoint 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---sub-pidsha   ;
   SetIndexBuffer(0,BS);
   SetIndexBuffer(1,GS);
   SetIndexLabel(0,"sign");
   SetIndexLabel(1,"val");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   double spread = MarketInfo(Symbol(),MODE_SPREAD);
   
   int counted_bar = IndicatorCounted(); 
   int limit = Bars-counted_bar;
   for(int i=limit-1; i>=0; i--)
   {   
      double A=iCustom(NULL,0,"MTFPI-sub2",FastEMA,SlowEMA,SignalSMA,0,i);
      double Bb=iCustom(NULL,0,"MTFPI-sub3",K_Period,D_Period,Slowing,0,i);
      double Bs=iCustom(NULL,0,"MTFPI-sub3",K_Period,D_Period,Slowing,1,i);
      double Chi=iCustom(NULL,0,"MTFPI-sub4",0,i);
      double Clo=iCustom(NULL,0,"MTFPI-sub4",1,i);   
      if (Clo>Chi){double w=Chi; Chi=Clo; Clo=w;}
      
      if (A>0 && Bb!=EMPTY_VALUE && Clo>Bb)
      {
          if(Close[i]<Bb)Bb=Bb+spread*Point;
          BS[i]=1;
          GS[i]=Bb;
      }
      else
      { 
          if (A<0 && Bs!=EMPTY_VALUE && Chi<Bs)
          {
               if(Close[i]<Bs)Bs=Bs+spread*Point;
               BS[i]=-1;
               GS[i]=Bs;
          }
          else
          {
               BS[i]=0;
               GS[i]=EMPTY_VALUE;
          } 
      }
   }
	  
   return(0);
}
//+------------------------------------------------------------------+