//+------------------------------------------------------------------+
//|                   Based on Original indicator RAVI FX Fisher.mq4 |
//|                                        by Luis Guilherme Damiani |
//|                               Modified by Linuxser for FOREX TSD |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Olive
#property indicator_color3 Olive
//---- input parameters
extern int       MAfast=7;
extern int       MAslow=65;
extern double    trigger=0.03;
extern int       maxbars=500;
extern int       Mode = 0; //0=sma, 1=ema, 2=smma, 3=lwma

//---- buffers
double RAVI[];
double LoTrigBuff[];
double HiTrigBuff[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RAVI);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,LoTrigBuff);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,HiTrigBuff);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
      int    counted_bars=IndicatorCounted();
      double MAValue=0;
      double IFish=0;
      //---- check for possible errors
      if(counted_bars<0) return(-1);
      int limit=Bars-counted_bars;
      if(limit>maxbars)limit=maxbars;
      if (limit>Bars-MAslow-1)limit=Bars-MAslow-1;   
      //---- 
      for (int shift = 0; shift<=limit;shift++)
      {
	     
	
	     MAValue = 100 * (iMA(NULL,0,MAfast,0,Mode,PRICE_TYPICAL,shift) - iMA(NULL,0,MAslow,0,Mode,PRICE_TYPICAL,shift))
	              /iMA(NULL,0,MAslow,0,Mode,PRICE_TYPICAL,shift);
	     IFish=(MathExp(2*MAValue)-1)/(MathExp(2*MAValue)+1);
	    
	    
         RAVI[shift]=IFish;
         LoTrigBuff[shift]=-trigger;
         HiTrigBuff[shift]=trigger;
       }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+