//+-------------------------------------------------------------------+
//|                               StochPrice Indicator (C) Ralome     |
//|                               Similarity Principle (C) Eurusdd    |
//| On chart version                                                  |
//|        This code comes as is and carries NO WARRANTY whatsoever   |
//|                                           Use at your own risk!   |
//+-------------------------------------------------------------------+
#property  indicator_chart_window
#property  indicator_buffers 8

#property  indicator_color1  Black
#property  indicator_width1  1
#property  indicator_color2  Black
#property  indicator_width2  1
#property  indicator_color3  Black
#property  indicator_width3  1
#property  indicator_color4  Black
#property  indicator_width4  2
#property  indicator_color5  Black
#property  indicator_width5  2

#property  indicator_color6  Magenta
#property  indicator_width6  2

extern int stochperiod=300;
extern int bbperiod=24;
extern int ma_method = 0;

double stochi[],stochi_ma[],priceline[],priceline2[],priceline3[],stochi_bbup[],stochi_bbdn[],dif[];

double price_ma,price_std,stochi_std;
double stochi_perc,price_percm,stochi_0,stochi_100;




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

  IndicatorBuffers(6);


SetIndexStyle(0,DRAW_NONE);
SetIndexBuffer(0,stochi_bbup);
SetIndexLabel(0,"stochi_bbup");
SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(1,stochi_bbdn);
SetIndexLabel(1,"stochi_bbdn");
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,stochi_ma);
SetIndexLabel(2,"stochi_ma");
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(3,priceline);
SetIndexLabel(3,"priceline");
SetIndexStyle(4,DRAW_NONE);
SetIndexBuffer(4,stochi);
SetIndexLabel(4,"stochi");
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(5,dif);
SetIndexLabel(5,"dif");

   return(0);

  }

int start()
  {
  //int s=GetTickCount();

   int limit, handle,i;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   //if (x==1) counted_bars=0;
   limit=Bars-counted_bars;


   for(i=0; i<limit; i++)
      {
      stochi[i]=iStochastic(NULL,0,stochperiod,1,1,ma_method,0,MODE_MAIN,i);
      }
      
   for(i=0; i<limit; i++)
      {
      price_ma=iMA(NULL,0,bbperiod,0,ma_method,PRICE_CLOSE,i);
      price_std=iStdDev(NULL,0,bbperiod,0,ma_method,PRICE_CLOSE,i);
      stochi_ma[i]=iMAOnArray(stochi,0,bbperiod,0,ma_method,i);
      stochi_std=iStdDevOnArray(stochi,0,bbperiod,0,ma_method,i);
      
      if (stochi_std>0) 
         {
         stochi_perc=(stochi[i]-stochi_ma[i])/(2*stochi_std);
 
         }


      priceline[i]=stochi_perc*2*price_std+price_ma;

      
      dif[i]=priceline[i]-Close[i]+price_ma;
      
      }      

   return(0);
  }
//+------------------------------------------------------------------+

int deinit()
{
return(0);
}


