Navigation:Home > Content >

MaEnv_02.mq4

Time: 2014-06-21 | Download file:MaEnv_02.mq4

/*-------------------------------------------------------------------+
 |                                                        MaEnv.mq4  |
 |                                                 Copyright © 2010  |
 |                                             basisforex@gmail.com  |
 +-------------------------------------------------------------------*/
#property copyright "Copyright © 2010, basisforex@gmail.com"
#property link      "basisforex@gmail.com"

#property indicator_chart_window

#property indicator_buffers 8
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_color7 Green
#property indicator_color8 Red
#property indicator_style1 STYLE_DASH
#property indicator_style2 STYLE_DASH
#property indicator_style3 STYLE_DASH
#property indicator_style4 STYLE_DASH
#property indicator_style5 STYLE_DASH
#property indicator_style6 STYLE_DASH
#property indicator_style7 STYLE_DASH
#property indicator_style8 STYLE_DASH

extern string TimeFrame   = "Current Time Frame";
extern bool   Interpolate = true;

double aquaUp1[];
double aquaDn1[];
double aquaUp2[];
double aquaDn2[];
double aquaUp3[];
double aquaDn3[];
double aquaUp4[];
double aquaDn4[];

//
//
//
//
//

string indicatorFileName;
bool   returnBars;
int    timeFrame;

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

int init()
{
   IndicatorBuffers(8);
   SetIndexBuffer(0, aquaUp1);
   SetIndexBuffer(1, aquaDn1);
   SetIndexBuffer(2, aquaUp2);
   SetIndexBuffer(3, aquaDn2);
   SetIndexBuffer(4, aquaUp3);
   SetIndexBuffer(5, aquaDn3);
   SetIndexBuffer(6, aquaUp4);
   SetIndexBuffer(7, aquaDn4);

      //
      //
      //
      //
      //

      indicatorFileName = WindowExpertName();
      returnBars        = (TimeFrame=="returnBars");     if (returnBars)     return(0);
      timeFrame         = stringToTimeFrame(TimeFrame);

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

//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
int start()
{
   int limit, counted_bars = IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
            limit = MathMin(Bars - counted_bars,Bars-1);
            if (returnBars) { aquaUp1[0] = limit+1; return(0); }
            if (timeFrame>Period()) limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
   
   //
   //
   //
   //
   //
   
      double pointMultiplier=1; if (Digits==3 || Digits==5) pointMultiplier=10;

   //
   //
   //
   //
   //
      
   for(int i = limit; i >= 0; i--)
   {
      int y      = iBarShift(NULL,timeFrame,Time[i]);
      double yMA = (iMA(NULL, timeFrame,   5, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,   8, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,  13, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,  21, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,  34, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,  55, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame,  89, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame, 144, 0, MODE_EMA, PRICE_WEIGHTED, y) +
                    iMA(NULL, timeFrame, 233, 0, MODE_EMA, PRICE_WEIGHTED, y)) / 9.0;
         
         aquaUp1[i] = yMA +  50.0 * Point * pointMultiplier;
         aquaDn1[i] = yMA -  50.0 * Point * pointMultiplier;
         aquaUp2[i] = yMA +  61.8 * Point * pointMultiplier;
         aquaDn2[i] = yMA -  61.8 * Point * pointMultiplier;
         aquaUp3[i] = yMA +  76.4 * Point * pointMultiplier;
         aquaDn3[i] = yMA -  76.4 * Point * pointMultiplier;
         aquaUp4[i] = yMA +  88.2 * Point * pointMultiplier;
         aquaDn4[i] = yMA -  88.2 * Point * pointMultiplier;
         
         //
         //
         //
         //
         //
      
            if (timeFrame <= Period() || y==iBarShift(NULL,timeFrame,Time[i-1])) continue;
            if (!Interpolate) continue;

         //
         //
         //
         //
         //

         datetime time = iTime(NULL,timeFrame,y);
            for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;	
            for(int k = 1; k < n; k++)
            {
               aquaUp1[i+k] = aquaUp1[i] + (aquaUp1[i+n]-aquaUp1[i])*k/n;
               aquaDn1[i+k] = aquaDn1[i] + (aquaDn1[i+n]-aquaDn1[i])*k/n;
               aquaUp2[i+k] = aquaUp2[i] + (aquaUp2[i+n]-aquaUp2[i])*k/n;
               aquaDn2[i+k] = aquaDn2[i] + (aquaDn2[i+n]-aquaDn2[i])*k/n;
               aquaUp3[i+k] = aquaUp3[i] + (aquaUp3[i+n]-aquaUp3[i])*k/n;
               aquaDn3[i+k] = aquaDn3[i] + (aquaDn3[i+n]-aquaDn3[i])*k/n;
               aquaUp4[i+k] = aquaUp4[i] + (aquaUp4[i+n]-aquaUp4[i])*k/n;
               aquaDn4[i+k] = aquaDn4[i] + (aquaDn4[i+n]-aquaDn4[i])*k/n;
            }               
   }
   return(0);
}


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

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int char = StringGetChar(s, length);
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                     s = StringSetChar(s, length, char - 32);
         else if(char > -33 && char < 0)
                     s = StringSetChar(s, length, char + 224);
   }
   return(s);
}

Recommend