Navigation´╝ÜHome > Content >

Double_smoothed_stochastic.mq4

Time: 2013-12-05 | Download file:Double_smoothed_stochastic.mq4

//------------------------------------------------------------------
#property copyright   "www.forex-tsd.com"
#property description "Powered by tommy27 - puretrade.ru"
#property link        "www.puretrade.ru"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1  DarkGray
#property indicator_color2  DeepSkyBlue
#property indicator_color3  DeepSkyBlue
#property indicator_color4  PaleVioletRed
#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    StochasticPeriod    = 55;
extern int    EmaSmoothingPeriod = 15;
extern double UpLevel             = 80;
extern double DownLevel           = 20;
extern string UniqueID            = "DSS1";
extern color  ZoneColor           = DimGray;

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

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

int init()
{
   IndicatorBuffers(6);
   SetIndexBuffer(0,sto);
   SetIndexBuffer(1,stoUa);
   SetIndexBuffer(2,stoUb);
   SetIndexBuffer(3,stoDa);
   SetIndexBuffer(4,stoDb);
   SetIndexBuffer(5,inZone);
      SetLevelValue(0,UpLevel);
      SetLevelValue(1,DownLevel);
         shortName = UniqueID+" Double smoothed stochastic ("+StochasticPeriod+","+EmaSmoothingPeriod+")";
         IndicatorShortName(shortName);
   return(0);
}
int deinit() { ObjectDelete(UniqueID); 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(UniqueID,OBJ_RECTANGLE,window,0,0,0,0);
                     ObjectSet(UniqueID,OBJPROP_COLOR,ZoneColor);
                     ObjectSet(UniqueID,OBJPROP_TIME1,Time[Bars-1]);
                     ObjectSet(UniqueID,OBJPROP_PRICE1,UpLevel);
                     ObjectSet(UniqueID,OBJPROP_PRICE2,DownLevel);
                     ObjectSet(UniqueID,OBJPROP_BACK,true);
            }
            if (ObjectFind(UniqueID)>-1) ObjectSet(UniqueID,OBJPROP_TIME2,Time[0]);
            if (inZone[limit]== 1) CleanPoint(limit,stoUa,stoUb);
            if (inZone[limit]==-1) CleanPoint(limit,stoDa,stoDb);
 
   //
   //
   //
   //
   //
 
   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(StochasticPeriod,EmaSmoothingPeriod,i);
      inZone[i] = inZone[i+1];
         if (sto[i]>UpLevel)                      inZone[i] =  1;
         if (sto[i]DownLevel) inZone[i] =  0;
         if (inZone[i] ==  1) PlotPoint(i,stoUa,stoUb,sto);
         if (inZone[i] == -1) PlotPoint(i,stoDa,stoDb,sto);
   }
   return(0);
}


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

double workDss[][2];
double iDss(int StochasticPer, 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 sto1   = 0;
      double max   = High[i]; 
      double min   = Low[i];
         for(int k=1; k        

Recommend