Navigation´╝ÜHome > Content >

Blau_-_eco.mq4

Time: 2012-02-22 | Download file:Blau_-_eco.mq4

//------------------------------------------------------------------
#property link      "www.forex-tsd.com"
#property copyright "www.forex-tsd.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1  LimeGreen
#property indicator_color2  LimeGreen
#property indicator_color3  PaleVioletRed
#property indicator_color4  PaleVioletRed
#property indicator_color5  DarkGray
#property indicator_color6  Gold
#property indicator_width1  2
#property indicator_width3  2
#property indicator_width5  2
#property indicator_width6  2
#property indicator_level1  0
#property indicator_levelcolor DarkGray

//
//
//
//
//

extern double Period1 = 32;
extern double Period2 =  5;
extern double Period3 =  5;

double eco[];
double ecohuu[];
double ecohud[];
double ecohdd[];
double ecohdu[];
double signal[];
double slope[];

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

int init()
{
   IndicatorBuffers(7);
   SetIndexBuffer(0,ecohuu); SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(1,ecohud); SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(2,ecohdd); SetIndexStyle(2, DRAW_HISTOGRAM);
   SetIndexBuffer(3,ecohdu); SetIndexStyle(3, DRAW_HISTOGRAM);
   SetIndexBuffer(4,eco);
   SetIndexBuffer(5,signal);
   SetIndexBuffer(6,slope);
      IndicatorShortName("Blau ergodic candlestic oscillator ("+DoubleToStr(Period1,1)+","+DoubleToStr(Period2,1)+","+DoubleToStr(Period3,1)+")");
   return(0);
}
int deinit() { return(0); }

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

int start()
{
   int count,counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

      for(int i = limit; i >= 0; i--)
      {
         double co = iEma(iEma(Close[i]-Open[i],Period1,i,0),Period2,i,1);
         double hl = iEma(iEma(High[i]-Low[i],Period1,i,2),Period2,i,3);
            if (hl!=0)
                  eco[i] = 100.0*co/hl;
            else  eco[i] = 0;                  
            ecohuu[i] = EMPTY_VALUE;
            ecohud[i] = EMPTY_VALUE;
            ecohdd[i] = EMPTY_VALUE;
            ecohdu[i] = EMPTY_VALUE;
            signal[i] = iEma(eco[i],Period3,i,4);

            //
            //
            //
            //
            //
                           
            slope[i] = slope[i+1];
               if (eco[i] > eco[i+1]) slope[i] =  1;
               if (eco[i] < eco[i+1]) slope[i] = -1;
               if (eco[i]>0)
               if (slope[i]==1)
                     ecohuu[i] = eco[i];
               else  ecohud[i] = eco[i];
               if (eco[i]<0)
               if (slope[i]==1)
                     ecohdu[i] = eco[i];
               else  ecohdd[i] = eco[i];
      }
   return(0);
}

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

double workEma[][5];
double iEma(double price, double period, int r, int instanceNo=0)
{
   if (ArrayRange(workEma,0)!= Bars) ArrayResize(workEma,Bars); r = Bars-r-1;

  
      
   double alpha = 2.0 / (1.0+period);
          workEma[r][instanceNo] = workEma[r-1][instanceNo]+alpha*(price-workEma[r-1][instanceNo]);
   return(workEma[r][instanceNo]);
} 

Recommend