Navigation´╝ÜHome > Content >

Double_smoothed_stochastic_2.mq4

Time: 2011-10-16 | Download file:Double_smoothed_stochastic_2.mq4

//------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1  DarkGray
#property indicator_color2  LimeGreen
#property indicator_color3  Green
#property indicator_color4  LightPink
#property indicator_color5  PaleVioletRed
#property indicator_width1  1
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2
#property indicator_width5  2
#property indicator_minimum 0
#property indicator_maximum 100

//
//
//
//
//

extern int    Stochastic.Period    = 55;
extern int    Ema.Smoothing.Period = 15;
extern double Up.Level             = 80;
extern double Down.Level           = 20;
extern string Unique.ID            = "DSS1";
extern color  Zone.Color           = C'255,238,210';

double sto[];
double stoUa[];
double stoUb[];
double stoDa[];
double stoDb[];
double inZone[];
double slope[];
string shortName;

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()
{
   IndicatorBuffers(7);
   SetIndexBuffer(0,sto);
   SetIndexBuffer(1,stoUa); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,159);
   SetIndexBuffer(2,stoUb); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159);
   SetIndexBuffer(3,stoDa); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159);
   SetIndexBuffer(4,stoDb); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,159);
   SetIndexBuffer(5,inZone);
   SetIndexBuffer(6,slope);
      SetLevelValue(0,Up.Level);
      SetLevelValue(1,Down.Level);
         shortName = Unique.ID+" Double smoothed stochastic ("+Stochastic.Period+","+Ema.Smoothing.Period+")";
         IndicatorShortName(shortName);
   return(0);
}
int deinit() { ObjectDelete(Unique.ID); return(0); }


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
      if (counted_bars<0) return(0);
      if (counted_bars>0) counted_bars--;
            int limit=MathMin(Bars-counted_bars,Bars-1);
            
            static bool initialized = false;
            if (!initialized)
            {
               initialized = true;
               int window = WindowFind(shortName);
                  ObjectCreate(Unique.ID,OBJ_RECTANGLE,window,0,0,0,0);
                     ObjectSet(Unique.ID,OBJPROP_COLOR,Zone.Color);
                     ObjectSet(Unique.ID,OBJPROP_TIME1,Time[Bars-1]);
                     ObjectSet(Unique.ID,OBJPROP_PRICE1,Up.Level);
                     ObjectSet(Unique.ID,OBJPROP_PRICE2,Down.Level);
                     ObjectSet(Unique.ID,OBJPROP_BACK,true);
            }
            if (ObjectFind(Unique.ID)>-1) ObjectSet(Unique.ID,OBJPROP_TIME2,Time[0]);
 
   //
   //
   //
   //
   //
 
   for(int i=limit; i>=0; i--)
   {
      stoUa[i]  = EMPTY_VALUE;
      stoUb[i]  = EMPTY_VALUE;
      stoDa[i]  = EMPTY_VALUE;
      stoDb[i]  = EMPTY_VALUE;
      sto[i]    = iDss(Stochastic.Period,Ema.Smoothing.Period,i);
      inZone[i] = inZone[i+1];
         if (sto[i]>sto[i+1])                      slope[i]  =  1;
         if (sto[i]Up.Level)                      inZone[i] =  1;
         if (sto[i]Down.Level) inZone[i] =  0;
         if (inZone[i]== 1 && slope[i]== 1) stoUa[i] = sto[i];
         if (inZone[i]== 1 && slope[i]==-1) stoUb[i] = sto[i];
         if (inZone[i]==-1 && slope[i]== 1) stoDb[i] = sto[i];
         if (inZone[i]==-1 && slope[i]==-1) stoDa[i] = sto[i];
   }
   return(0);
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

double workDss[][2];
double iDss(int StochasticPeriod, int EMAPeriod, int i, int instanceNo=0)
{
   if (ArrayRange(workDss,0) != Bars) ArrayResize(workDss,Bars); int r=Bars-i-1; instanceNo*=2;

   //
   //
   //
   //
   //

      double alpha = 2.0/(1.0+EMAPeriod);
      double sto   = 0;
      double max   = High[i]; 
      double min   = Low[i];
         for(int k=1; k        

Recommend