Navigation´╝ÜHome > Content >

ZeroLag_Stochs_true_mtf.mq4

Time: 2010-03-20 | Download file:ZeroLag_Stochs_true_mtf.mq4

#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers    2
#property indicator_color1     DimGray
#property indicator_width1     1
#property indicator_style1     STYLE_SOLID
#property indicator_color2     DimGray
#property indicator_width2     1
#property indicator_style2     STYLE_DOT
#property indicator_level1     20
#property indicator_level2     80
#property indicator_levelcolor Gray
#property indicator_levelstyle STYLE_DOT
#property indicator_minimum    -30
#property indicator_maximum    130

extern int kPeriod   = 5;
extern int dPeriod   = 3;
extern int slowing   = 3;
extern int timeFrame = 0;

double mainBuffer[];
double signBuffer[];
double upperBuffer[];
double lowerBuffer[];
double workBuffer1[];
double workBuffer2[];
double workBuffer3[];

int drawBeginOne = 0;
int drawBeginTwo = 0;

/*********************************************************************
 * init                                                              *
 *********************************************************************/
int init()
{
   drawBeginOne = kPeriod+slowing;
   drawBeginTwo = drawBeginOne+dPeriod;
   
   if(timeFrame == 0) {
      timeFrame = Period();
   }
   if(Period() > timeFrame) {
      timeFrame = Period();
   }
   
   IndicatorBuffers(7);
   
   SetIndexBuffer(0, mainBuffer);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexLabel(0, "Main");
   SetIndexDrawBegin(0, drawBeginOne);
   
   SetIndexBuffer(1, signBuffer);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexLabel(1, "Signal");
   SetIndexDrawBegin(1, drawBeginTwo);
   
   SetIndexBuffer(2, upperBuffer);
   SetIndexBuffer(3, lowerBuffer);
   SetIndexBuffer(4, workBuffer1);
   SetIndexBuffer(5, workBuffer2);
   SetIndexBuffer(6, workBuffer3);
   
   IndicatorShortName("ZeroLag Stochastic Oscillator ("+kPeriod+","+dPeriod+","+slowing+")");
   
   return(0);
}

/*********************************************************************
 * init                                                              *
 *********************************************************************/
int start()
{
   int    i;
   int    j;
   int    k;
   int    aBars = Bars;
   int    cBars = IndicatorCounted();
   if    (cBars > 0) { cBars--; }
   int    lBars = aBars-cBars;
   double price;
   double ema;
   double min;
   double max;
   
   if(timeFrame != Period()) {
      datetime timeArray[];
      lBars = MathMax(lBars,timeFrame/Period());
      ArrayCopySeries(timeArray,MODE_TIME,NULL,timeFrame);
   }
   
   // if(Time[i] kPeriod) {
      i = aBars - cBars - 1;
   }
   while(i >= 0) {
      min = 1000000;
      j = i + kPeriod - 1;
      while(j >= i) {
         price = Low[j];
         if(min > price) {
            min = price;
         }
         j--;
      }
      lowerBuffer[i] = min;
      i--;
   }
   i = aBars - kPeriod;
   if(cBars > kPeriod) {
      i = aBars - cBars - 1;
   }
   while(i >= 0) {
      max=-1000000;
      j = i + kPeriod - 1;
      while(j >= i) {
         price = High[j];
         if(max < price) {
            max = price;
         }
         j--;
      }
      upperBuffer[i] = max;
      i--;
   }
   i = aBars - drawBeginOne;
   if(cBars > drawBeginOne) {
      i = aBars - cBars - 1;
   }
   while(i >= 0) {
      if(!compareDouble((upperBuffer[i] - lowerBuffer[i]), 0.0)) {
         workBuffer1[i] = 100*((Close[i] - lowerBuffer[i]) / (upperBuffer[i] - lowerBuffer[i]));
      }
      i--;
   }
   for(i = 0; i < lBars; i++) {
      workBuffer2[i] = iMAOnArray(workBuffer1, aBars, slowing, 0, MODE_SMA, i);
   }
   for(i = 0; i < lBars; i++) {
      ema = iMAOnArray(workBuffer2, aBars, slowing, 0, MODE_SMA, i);
      mainBuffer[i] = workBuffer2[i] + workBuffer2[i] - ema;
   }
   for(i = 0; i < lBars; i++) {
      workBuffer3[i] = iMAOnArray(mainBuffer, aBars, dPeriod, 0, MODE_SMA, i);
   }
   for(i = 0; i < lBars; i++) {
      ema = iMAOnArray(workBuffer3, aBars, dPeriod, 0, MODE_SMA, i);
      signBuffer[i] = workBuffer3[i] + workBuffer3[i] - ema;
   }
   
   return(0);
}

/*********************************************************************
 * compareDouble                                                     *
 *********************************************************************/
bool compareDouble(double numberOne, double numberTwo)
{
   bool compare = NormalizeDouble(numberOne-numberTwo,8) == 0;
   return(compare);
}

/*********************************************************************/

Recommend