//+------------------------------------------------------------------+
//|                                                   fisher sto.mq4 |
//|                             transfo de fisher appliquée à la sto |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2

#property indicator_color1 White
#property indicator_color2 MediumBlue
#property indicator_width2 2

#property indicator_level1 0.0
#property indicator_level2 0.6
#property indicator_level3 -0.6

#property indicator_levelstyle STYLE_SOLID
#property indicator_levelcolor Red
#property indicator_levelwidth 1

#property indicator_maximum 1
#property indicator_minimum -1


//---- input parameters
extern int       K_Period  = 25;
extern int       slow      = 5;
extern int       STO_MA=5;
extern int       polarisation=40;
extern bool      SHOW_STO=true;
//---- buffers
double STOval[];
double IF[];
double STO[];
double WMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,STOval);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,IF);
      
   SetIndexBuffer(2,STO);   
   SetIndexBuffer(3,WMA); 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("toplevel");
   ObjectDelete("botlevel"); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   
   int limit,i;
   
   limit = Bars - counted_bars + 1;
   
   for (i = limit; i>=0; i--)
      {
         STO[i] = (iStochastic(NULL,0,K_Period,3,slow,0,MODE_MAIN,PRICE_CLOSE,i)-50.0)/polarisation;
         if (SHOW_STO) STOval[i] = STO[i]/3.0;
         else STOval[i]=EMPTY_VALUE;
      }
   for (i = limit; i>=0; i--)
      {
         WMA[i] = iMAOnArray(STO,0,STO_MA,0,MODE_LWMA,i);        
         IF[i] = (MathExp(2.0*WMA[i])-1.0) / (MathExp(2.0*WMA[i])+1.0);
      } 
 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+