Navigation´╝ÜHome > Content >

All_Woodies_CCI_yb_v1.0.mq4

Time: 2016-10-17 | Download file:All_Woodies_CCI_yb_v1.0.mq4

//+------------------------------------------------------------------+
//|                                              All Woodies CCI.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright   "mladen"
#property link        "mladenfx@gmail.com"

//
//
//
//
//

#property indicator_separate_window
#property indicator_minimum -300.0
#property indicator_maximum 300.0
#property indicator_buffers 8
#property indicator_color1  C'140,140,140'     
#property indicator_color2  Blue
#property indicator_color3  Red
#property indicator_color4  Gold
#property indicator_color5  Lime
#property indicator_color6  Red
#property indicator_color7  Black
#property indicator_color8  YellowGreen
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2
#property indicator_width7  3

#property indicator_level1  -100.0
#property indicator_level2   100.0
#property indicator_level3   200.0
#property indicator_level4  -200.0
#property indicator_levelcolor C'115,157,123'

//
//
//
//
//
//

extern string _                    = "Parameters";
extern int    CCIPeriod            = 14;
extern int    TrendPeriod          =  6;
extern int    TurboCCIPeriod       =  6;
extern int    LSMAPeriod           = 25;
extern int    LSMAPrice            = PRICE_CLOSE;
extern string __                   = "Chose timeframes";
extern string timeFrames           = "M1;M5;M15;M30;H1;H4;D1;W1;MN";
extern int    barsPerTimeFrame     = 35;
extern int    shiftRight           = 0;   
extern bool   currentFirst         = true; 
extern color  txtColor             = YellowGreen; 
extern color  separatorColor       = C'115,157,123'; 

//---- buffers
//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];
double buffer7[];
double buffer8[];

//
//
//
//
//

string shortName;
string labels[];
int    periods[];
int    Shift;
double minValue;
double maxValue;
string indicatorName;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
      SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
      SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
      SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
      SetIndexBuffer(4,buffer5); SetIndexStyle(4,DRAW_ARROW);  SetIndexArrow(4,59);
      SetIndexBuffer(5,buffer6); SetIndexStyle(5,DRAW_ARROW);  SetIndexArrow(5,59);
      SetIndexBuffer(6,buffer7);
      SetIndexBuffer(7,buffer8);
            SetIndexLabel(0,"Trend up");
            SetIndexLabel(1,"Trend down");
            SetIndexLabel(2,"Close above LSMA");
            SetIndexLabel(3,"Close bellow LSMA");
            SetIndexLabel(4,"Close above EMA");
            SetIndexLabel(5,"Close bellow EMA");
            SetIndexLabel(6,"CCI");
            SetIndexLabel(7,"Turbo CCI");

      if (_=="CalculateWoodie") return(0);

      //
      //
      //
      //
      //
            
      if (shiftRight>0) Shift=shiftRight;
      else              Shift = 0;
         barsPerTimeFrame = MathMax(barsPerTimeFrame,15);      
         shortName =  "All Woodies CCI ("+CCIPeriod+")";
                     IndicatorShortName(shortName);

         //
         //
         //
         //
         //
         
         for (int k =0;k <8; k++) SetIndexShift(k,Shift);            

      //
      //
      //
      //
      //
      
      timeFrames = StringTrimLeft(StringTrimRight(timeFrames));
      if (StringSubstr(timeFrames,StringLen(timeFrames),1) != ";")
                       timeFrames = StringConcatenate(timeFrames,";");

         //
         //
         //
         //
         //                                   
            
         int s = 0;
         int i = StringFind(timeFrames,";",s);
         int time;
         string current;
            while (i > 0)
            {
               current = StringSubstr(timeFrames,s,i-s);
               time    = stringToTimeFrame(current);
               if (time > 0) {
                     ArrayResize(labels ,ArraySize(labels)+1);
                     ArrayResize(periods,ArraySize(periods)+1);
                                 labels[ArraySize(labels)-1] = TimeFrameToString(time); 
                                 periods[ArraySize(periods)-1] = time; }
                                 s = i + 1;
                                     i = StringFind(timeFrames,";",s);
            }
      
      //
      //
      //
      //
      //

      if(currentFirst)
         for (i=1;i0; k--)
                     {
                        labels[k]  = labels[k-1];
                        periods[k] = periods[k-1];
                     }                     
               labels[0]  = tmpLbl;
               periods[0] = tmpPer;
            }
   indicatorName = WindowExpertName();                  
   return(0);
}

//
//
//
//
//

int deinit()
{
   for(int l=0;l0) counted_bars--;
           limit=Bars-counted_bars;

   //
   //
   //
   //
   //
   
   for (i=limit;i>=0;i--)
   {
      if (TurboCCIPeriod>1) buffer8[i] = iCCI(NULL,0,TurboCCIPeriod,PRICE_TYPICAL,i); 
                            buffer7[i] = iCCI(NULL,0,CCIPeriod     ,PRICE_TYPICAL,i);
                            buffer1[i] = buffer7[i];
            SetHisto(i);
            SetLsma(i);
   }
}
  
//
//
//
//
//

void SetHisto(int i)
{
   int k,s;

   buffer2[i] = EMPTY_VALUE;
   buffer3[i] = EMPTY_VALUE;
   buffer4[i] = EMPTY_VALUE;
   
   //
   //
   //
   //
   //

      if (buffer7[i]>0)
         if (buffer2[i+1] != EMPTY_VALUE) s = TrendPeriod;
         else
            for (k=1,s= 1; k lsmaValue) buffer5[i] =  0.00;
      if (Close[i] < lsmaValue) buffer6[i] =  0.00;
}




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

void checkMinMax(int shift)
{
   minValue = MathMin(buffer7[shift],minValue);
   maxValue = MathMax(buffer7[shift],maxValue);
}

//
//
//
//
//


int barTime(int a)
{
   if(a<0)
         return(Time[0]+Period()*60*MathAbs(a));
   else  return(Time[a]);   
}

//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   int tf=0;
       tfs = StringUpperCase(tfs);
       
         if (tfs=="M1" || tfs=="1")       tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")       tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")      tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")      tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")      tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")     tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")    tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080")   tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200")   tf=PERIOD_MN1;
         
   return(tf);
}
string TimeFrameToString(int tf)
{
   string tfs="Current time frame";
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN1";
   }
   return(tfs);
}

//
//
//
//
//

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

Recommend