//+------------------------------------------------------------------+ //| All Woodies CCI.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" // // // // // #property indicator_separate_window #property indicator_buffers 8 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 LimeGreen #property indicator_color4 Tomato #property indicator_color5 SpringGreen #property indicator_color6 Magenta #property indicator_color7 SlateGray #property indicator_color8 YellowGreen #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 #property indicator_width5 2 #property indicator_width6 2 #property indicator_width7 2 #property indicator_level1 -100 #property indicator_level2 100 #property indicator_level3 200 #property indicator_level4 -200 #property indicator_levelcolor DarkSlateGray // // // // // // 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 bool ShowLSMAline = false; extern int EMAPeriod = 34; extern int EMAPrice = PRICE_CLOSE; extern bool ShowEMAline = true; extern bool ShowLsmaEma = true; extern int LsmaEmaLevel = 15; extern string __ = "Chose timeframes"; extern string timeFrames = "M1;M5;M15;M30;H1;H4;D1;W1;MN"; extern int barsPerTimeFrame = 35; extern bool shiftRight = False; extern bool currentFirst = true; extern color txtColor = Silver; extern color separatorColor = C'29,29,29'; //---- 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); SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM); if(!ShowLSMAline) { SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,158); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,158); } else { SetIndexStyle(2,DRAW_LINE); SetIndexStyle(3,DRAW_LINE); } if(!ShowEMAline) { SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,158); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,158); } else { SetIndexStyle(4,DRAW_LINE); SetIndexStyle(5,DRAW_LINE); } SetIndexBuffer(2,buffer3); SetIndexBuffer(3,buffer4); SetIndexBuffer(4,buffer5); SetIndexBuffer(5,buffer6); 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) Shift = 1; else Shift = 0; barsPerTimeFrame = MathMax(barsPerTimeFrame,15); shortName = "All Woodies CCI ("+CCIPeriod+") "; shortName = MakeUniqueName(shortName,"" ); IndicatorShortName(shortName); // // // // // for (int k =0;k <8; k++) SetIndexShift(k,Shift*(barsPerTimeFrame+1)); // // // // // 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;l= 0) result = first+(MathRand()%1001)+rest; return(result); } // // // // void CalculateWoodie() { int counted_bars=IndicatorCounted(); int i,limit; if(counted_bars<0) return(-1); if(counted_bars>0) 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); SetHisto(i); if (ShowLsmaEma) SetLsmaEma(i); } } // // // // // void SetHisto(int i) { int k; buffer1[i] = EMPTY_VALUE; buffer2[i] = EMPTY_VALUE; // // // // // if (buffer7[i]>0) { if (buffer1[i+1] != EMPTY_VALUE) { buffer1[i] = buffer7[i]; return; } for (k=1; k lsmaValue) buffer3[i] = LsmaEmaLevel +2.00; if (Close[i] < lsmaValue) buffer4[i] = LsmaEmaLevel +2.00; if (Close[i] > emaValue) buffer5[i] = -LsmaEmaLevel; if (Close[i] < emaValue) buffer6[i] = -LsmaEmaLevel; } // // // // // double iLsma(int shift) { double ma1=iMA(NULL,0,LSMAPeriod,0,MODE_SMA ,LSMAPrice,shift); double ma2=iMA(NULL,0,LSMAPeriod,0,MODE_LWMA,LSMAPrice,shift); return(3.0*ma2-2.0*ma1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // 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); }