//+-------------------------------------------------------------------------------| //| BB_Squeeze_Advanced_v2 | //| Copyright © 2005,MetaQuotes Software Corp. author:!Scriptor or Collector!| //| ForexTSD 2007 mladen fxbs ki http://www.metaquotes.net/ | //| Cleaned up, options, additions (the usual bla,bla:) Mladen; mtf WEN formula | //+-------------------------------------------------------------------------------| #property copyright "Copyright © MetaQuotes Software Corp." #property link "http://www.metaquotes.net/ www.ForexTSD.com 2007 Mladen" // // // // // #property indicator_separate_window #property indicator_buffers 8 #property indicator_color1 ForestGreen #property indicator_color2 Red #property indicator_color3 DarkGreen #property indicator_color4 FireBrick #property indicator_color5 DodgerBlue #property indicator_color6 SlateGray #property indicator_color7 Gray #property indicator_color8 Gold #property indicator_width1 2 #property indicator_width2 2 #property indicator_levelcolor DarkSlateGray #property indicator_levelstyle 4 // // // // // extern int TimeFrame = 0; // extern string graph = "type"; extern int graphType = 1; extern string types = "parameters"; extern int type1.linearRegresion.Period =20; extern int type2.stoch.KPeriod =14; extern int type2.stoch.DPeriod = 3; extern int type2.stoch.Slowing = 3; extern int type3.cci.Period =50; extern int type4.rsi.Period =14; extern int type5.macd.fastEMA =12; extern int type5.macd.slowEMA =26; extern int type5.macd.macdEMA = 9; extern int type6.momentum.Period =14; extern int type7.williamsPR.Period =14; extern int type8.demarker.Period =10; extern int type9.ADX.Period =14; // // // // // extern string squeeze = "parameters"; extern int Bollinger.Period = 20; extern double Bollinger.Deviation = 2.0; extern int Keltner.Period = 20; extern double Keltner.Factor = 1.5; extern string other = "parameters"; extern int BarsToCount =900; extern bool ShowLevels =true; // extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF"; string IndicatorFileName; //------------------------ // // // // double upB[]; double loB[]; double upB2[]; double loB2[]; double histoLine[]; double upK[]; double loK[]; double mm[]; //------------------------------ // // // regression slope variables // // double SumSqrBars; double SumBars; double Num2; //---------------------------------------------------------------------------------| // | //---------------------------------------------------------------------------------| int init() { string shortName; SetIndexBuffer(0,upB); SetIndexBuffer(1,loB); SetIndexBuffer(2,upB2); SetIndexBuffer(3,loB2); SetIndexBuffer(4,mm); SetIndexBuffer(5,histoLine); SetIndexBuffer(6,upK); SetIndexBuffer(7,loK); // // // // // SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexStyle(3,DRAW_HISTOGRAM); SetIndexStyle(4,DRAW_NONE); SetIndexStyle(5,DRAW_LINE); SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,159); SetIndexStyle(7,DRAW_ARROW); SetIndexArrow(7,159); // // // // // if ((graphType < 1) || (graphType > 9)) graphType = 1; switch (graphType) { case 1: SetLevels(0.004,-0.004); shortName = "linear regression slope ("+type1.linearRegresion.Period+")"; // // // constants depending axclusively on linear regression period // // SumBars = type1.linearRegresion.Period * (type1.linearRegresion.Period-1) * 0.5; SumSqrBars = type1.linearRegresion.Period * (type1.linearRegresion.Period-1) * (2 * type1.linearRegresion.Period - 1)/6; Num2 = MathPow(SumBars,2) - type1.linearRegresion.Period * SumSqrBars; break; // // // // // case 2: SetLevels(30,-30); shortName = StringConcatenate("Stochastic (",type2.stoch.KPeriod,",", type2.stoch.DPeriod,",", type2.stoch.Slowing,")"); SetIndexStyle(4,DRAW_LINE); break; case 3: SetLevels(100,-100); shortName = "CCI ("+type3.cci.Period+",CLOSE)"; break; case 4: SetLevels(20,-20); shortName = "RSI ("+type4.rsi.Period+",CLOSE)"; break; case 5: SetLevels(20,-20); shortName = "MACD ("+type5.macd.fastEMA+"," +type5.macd.slowEMA+"," +type5.macd.macdEMA+",CLOSE)"; SetIndexStyle(4,DRAW_LINE); break; case 6: SetLevels(1,-1); shortName = "Momentum ("+type6.momentum.Period+",CLOSE)"; break; case 7: SetLevels(-30,30); shortName = "Williams% ("+type7.williamsPR.Period+")"; break; case 8: SetLevels(0.20,-0.20); shortName = "Demarker ("+type8.demarker.Period+")"; break; case 9: SetLevels(20,-20); shortName = "ADX ("+type9.ADX.Period+")"; SetIndexStyle(4,DRAW_LINE); } // // // // // IndicatorFileName = WindowExpertName(); IndicatorShortName("BollingerSqueeze["+TimeFrame+"] with "+shortName); if (TimeFrame < Period()) TimeFrame = Period(); BarsToCount = MathMax(BarsToCount,150); return(0); } //---------------------------------------------------------------------------------| // | //---------------------------------------------------------------------------------| int deinit() { return(0); } //---------------------------------------------------------------------------------| // | //---------------------------------------------------------------------------------| //void SetLevels(double level1,double level2,double level3=NULL,double level4=NULL) void SetLevels(double level1,double level2) { if (ShowLevels) { SetLevelValue(1,level1); SetLevelValue(2,level2); // SetLevelValue(3,level3); // SetLevelValue(4,level4); } return; } // // // // // double CallMain(int buffNo,int shift) { double result = iCustom(NULL,TimeFrame,IndicatorFileName, 0,"", graphType,"", type1.linearRegresion.Period, type2.stoch.KPeriod, type2.stoch.DPeriod, type2.stoch.Slowing, type3.cci.Period, type4.rsi.Period, type5.macd.fastEMA, type5.macd.slowEMA, type5.macd.macdEMA, type6.momentum.Period, type7.williamsPR.Period, type8.demarker.Period, type9.ADX.Period,"", Bollinger.Period, Bollinger.Deviation, Keltner.Period, Keltner.Factor,"", BarsToCount, false, buffNo,shift); return(result); } //---------------------------------------------------------------------------------| // | //---------------------------------------------------------------------------------| int start() { int counted_bars1=IndicatorCounted(); int limit1,i1; if(counted_bars1 < 0) return(-1); limit1 = Bars-counted_bars1; if (TimeFrame != Period()) { limit1 = MathMax(limit1,TimeFrame/Period()); datetime TimeArray[]; ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame); for(i1=0,int y=0; i1<limit1; i1++) { if(Time[i1]<TimeArray[y]) y++; upB [i1] = CallMain(0,y); loB [i1] = CallMain(1,y); upB2 [i1] = CallMain(2,y); loB2 [i1] = CallMain(3,y); mm [i1] = CallMain(4,y); histoLine [i1] = CallMain(5,y); upK [i1] = CallMain(6,y); loK [i1] = CallMain(7,y); } return(0); } int limit=IndicatorCounted(); int i; double diff,std,bbs,d; if (limit<0) return(-1); if (limit>0) limit--; limit=MathMin(Bars-limit,BarsToCount); // // // // // for (i=limit;i>=0;i--) { switch (graphType) { case 1: d=LinearRegressionSlope(type1.linearRegresion.Period,i); break; case 2: d=iStochastic(NULL,0,type2.stoch.KPeriod, type2.stoch.DPeriod, type2.stoch.Slowing,MODE_SMA,0,MODE_MAIN,i)-50; mm[i]=iStochastic(NULL,0,type2.stoch.KPeriod, type2.stoch.DPeriod, type2.stoch.Slowing,MODE_SMA,0,MODE_SIGNAL,i)-50; break; case 3: d=iCCI(NULL,0,type3.cci.Period,PRICE_CLOSE,i); break; case 4: d=iRSI(NULL,0,type4.rsi.Period,PRICE_CLOSE,i)-50; break; case 5: d=iMACD(NULL,0, type5.macd.fastEMA, type5.macd.slowEMA, type5.macd.macdEMA,PRICE_CLOSE,MODE_MAIN,i); mm[i]=iMACD(NULL,0,type5.macd.fastEMA, type5.macd.slowEMA, type5.macd.macdEMA,PRICE_CLOSE,MODE_SIGNAL,i); break; case 6: d=iMomentum(NULL,0,type6.momentum.Period,PRICE_CLOSE,i)-100; break; case 7: d=iWPR(NULL,0,type7.williamsPR.Period,i)+50; break; case 8: d=iDeMarker(NULL,0,type8.demarker.Period,i)-0.5; break; case 9: d=iADX(NULL,0,type9.ADX.Period,PRICE_CLOSE, MODE_PLUSDI,i) -iADX(NULL,0,type9.ADX.Period,PRICE_CLOSE, MODE_MINUSDI,i); mm[i]=iADX(NULL,0,type9.ADX.Period,PRICE_CLOSE, MODE_MAIN,i); break; break; } // // // // // diff = iATR(NULL,0,Keltner.Period,i)*Keltner.Factor; std = iStdDev(NULL,0,Bollinger.Period,MODE_SMA,0,PRICE_CLOSE,i); bbs = Bollinger.Deviation * std / diff; // // // // // histoLine[i]=d; if(bbs<1) { upK[i]=0; loK[i]=EMPTY_VALUE; upB[i]=EMPTY_VALUE; loB[i]=EMPTY_VALUE; if (d > 0) { upB2[i]=d; loB2[i]=EMPTY_VALUE; } else { loB2[i]=d; upB2[i]=EMPTY_VALUE; } } else { loK[i] =0; upK[i] =EMPTY_VALUE; upB2[i]=EMPTY_VALUE; loB2[i]=EMPTY_VALUE; if (d > 0) { upB[i]=d; loB[i]=EMPTY_VALUE; } else { loB[i]=d; upB[i]=EMPTY_VALUE; } } } return(0); } //---------------------------------------------------------------------------------| // | //---------------------------------------------------------------------------------| double LinearRegressionSlope(int Len,int shift) { double LinearRegSlope; double SumY = 0; double Sum1 = 0; double Num1; int i; // // // // // for (i=0; i<Len; i++) { Sum1 += i*iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,i+shift); SumY += iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,i+shift); } Num1 = Len * Sum1 - SumBars * SumY; // // // // // if( Num2 != 0 ) LinearRegSlope = 100*Num1/Num2; else LinearRegSlope = 0; return (LinearRegSlope); }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_HISTOGRAM
Implements a curve of type DRAW_NONE
Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_ARROW
Indicators Used:
Stochastic oscillator
Commodity channel index
Relative strength index
MACD Histogram
Momentum indicator
Larry William percent range indicator
DeMarker indicator
Movement directional index
Indicator of the average true range
Standard Deviation indicator
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: