Navigation´╝ÜHome > Content >

kase_permission_stochastic_smoothed_+_alerts.mq4

Time: 2013-07-25 | Download file:kase_permission_stochastic_smoothed_+_alerts.mq4

//+------------------------------------------------------------------+
//|                                    kase permision stochastic.mq4 |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "[email protected]"

#property indicator_separate_window
#property indicator_buffers  2
#property indicator_color1   Magenta
#property indicator_color2   DimGray
#property indicator_width1   2
#property indicator_width2   1
#property indicator_minimum  0
#property indicator_maximum  100
#property indicator_level1   25
#property indicator_level2   75
#property indicator_levelcolor DimGray 

//
//
//
//
//

extern int  pstLength     =   9;
extern int  pstX          =   5;
extern int  pstSmooth     =   3;
extern int  smoothPeriod  =  10;
extern int  smoothPhase   = 100;

//
//
//
//
//

extern bool  alertsOn        = false;
extern bool  alertsOnCurrent = true;
extern bool  alertsMessage   = true;
extern bool  alertsSound     = false;
extern bool  alertsEmail     = false;

//
//
//
//
//

double pstBuffer[];
double pssBuffer[];
double wrkBuffer[][5];
double trend[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0,pstBuffer); SetIndexLabel(0,"Stochastic");
   SetIndexBuffer(1,pssBuffer); SetIndexLabel(1,"Signal");
   SetIndexBuffer(2,trend);
   
      pstSmooth    = MathMax(pstSmooth,1);
      smoothPeriod = MathMax(smoothPeriod,1);

   IndicatorShortName("Kase permission stochastic smoothed ("+pstLength+","+pstX+")");   
   return(0);
}
int deinit() { return(0); }




//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

#define TripleK   0
#define TripleDF  1
#define TripleDFs 2
#define TripleDS  3
#define TripleDSs 4

//
//
//
//
//

int start()
{
   double alpha = 2.0/(1.0+pstSmooth);
   int lookBackPeriod = pstLength*pstX;
   int counted_bars   = IndicatorCounted();
   int i,r,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);
         if (ArrayRange(wrkBuffer,0) != Bars) ArrayResize(wrkBuffer,Bars);
         
   //
   //
   //
   //
   //

   for(i=limit,r=Bars-i-1; i>=0; i--,r++)
   {
      double min = Low [iLowest (NULL,0,MODE_LOW ,lookBackPeriod,i)];
      double max = High[iHighest(NULL,0,MODE_HIGH,lookBackPeriod,i)]-min;
      if (max>0)
            wrkBuffer[r][TripleK] = 100.0*(Close[i]-min)/max;
      else  wrkBuffer[r][TripleK] =   0.0;
      if (i==(Bars-1))
      {
            wrkBuffer[r][TripleDF] = wrkBuffer[r][TripleK];
            wrkBuffer[r][TripleDS] = wrkBuffer[r][TripleK];
            continue;
      }
      wrkBuffer[r][TripleDF] =  wrkBuffer[r-pstX][TripleDF]+alpha*(wrkBuffer[r][TripleK]-wrkBuffer[r-pstX][TripleDF]);
      wrkBuffer[r][TripleDS] = (wrkBuffer[r-pstX][TripleDS]*2.0+wrkBuffer[r][TripleDF])/3.0;
      
      //
      //
      //
      //
      //
      
      wrkBuffer[r][TripleDSs] = iSma(TripleDS ,3,r);
      pssBuffer[i]            = iSmooth(wrkBuffer[r][TripleDSs],smoothPeriod,smoothPhase,i, 0);
      wrkBuffer[r][TripleDFs] = iSma(TripleDF ,3,r);
      pstBuffer[i]            = iSmooth(wrkBuffer[r][TripleDFs],smoothPeriod,smoothPhase,i,10);
      
      //
      //
      //
      //
      //
      
      trend[i] = trend[i+1];
      if (pstBuffer[i] > pssBuffer[i]) trend[i] =  1;
      if (pstBuffer[i] < pssBuffer[i]) trend[i] = -1;
   }
   
   //
   //
   //
   //
   //
   
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      if (trend[whichBar] != trend[whichBar+1])
         if (trend[whichBar] == 1)
               doAlert("up");
         else  doAlert("down");
   }

   //
   //
   //
   //
   //
      
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

double iSma(int forDim, int period, int pos)
{
   double sum = wrkBuffer[pos][forDim];
      for(int i=1; i MathAbs(del2)) wrk[r][volty+s] = MathAbs(del1); 
               if(MathAbs(del1) < MathAbs(del2)) wrk[r][volty+s] = MathAbs(del2); 
         wrk[r][vsum+s] =	wrk[r-1][vsum+s] + 0.1*(wrk[r][volty+s]-wrk[r-10][volty+s]);
   
         //
         //
         //
         //
         //
      
         double avgLen = MathMin(MathMax(4.0*length,30),150);
            if (r=0 ; k++) avg += wrk[r-k][vsum+s];
                                                                                   avg /= k;
            }
            else avg = (wrk[r-1][avolty+s]*avgLen-wrk[r-toInt(avgLen)][vsum+s]+wrk[r][vsum+s])/avgLen;
            
         //
         //
         //
         //
         //
                                                           
         wrk[r][avolty+s] = avg;                                           
            if (wrk[r][avolty+s] > 0)
               double dVolty = wrk[r][volty+s]/wrk[r][avolty+s]; else dVolty = 0;   
	               if (dVolty > MathPow(len1,1.0/pow1)) dVolty = MathPow(len1,1.0/pow1);
                  if (dVolty < 1)                      dVolty = 1.0;

      //
      //
      //
      //
      //
	        
   	double pow2 = MathPow(dVolty, pow1);
      double len2 = MathSqrt(0.5*(length-1))*len1;
      double Kv   = MathPow(len2/(len2+1), MathSqrt(pow2));		
	
         if (del1 > 0) wrk[r][bsmax+s] = price; else wrk[r][bsmax+s] = price - Kv*del1;
         if (del2 < 0) wrk[r][bsmin+s] = price; else wrk[r][bsmin+s] = price - Kv*del2;

   //
   //
   //
   //
   //

      double R     = MathMax(MathMin(phase,100),-100)/100.0 + 1.5;
      double beta  = 0.45*(length-1)/(0.45*(length-1)+2);
      double alpha = MathPow(beta,pow2);

         wrk[r][0+s] = price + alpha*(wrk[r-1][0+s]-price);
         wrk[r][1+s] = (price - wrk[r][0+s])*(1-beta) + beta*wrk[r-1][1+s];
         wrk[r][2+s] = (wrk[r][0+s] + R*wrk[r][1+s]);
         wrk[r][3+s] = (wrk[r][2+s] - wrk[r-1][4+s])*MathPow((1-alpha),2) + MathPow(alpha,2)*wrk[r-1][3+s];
         wrk[r][4+s] = (wrk[r-1][4+s] + wrk[r][3+s]); 

   //
   //
   //
   //
   //

   return(wrk[r][4+s]);
}
int toInt(double value) { return(value); }

Recommend