# bollinger band trend detect?

26

7239

yeah016:

google for bb and how to interpret them and/or use them..

Or just look at the end of the page all forums there is an example of using BB in an EA: https://www.mql5.com/en/code/14209.

• 2016.06.09
• Khurram Mustafa
• www.mql5.com
Auto trading with the help of some indicators.
26

Hi Thanks for reply, I know how to interpret BB is ranging or flat, just in EA, what is the method/formula to let the EA determine it?
5040

yeah016:
Hi Thanks for reply, I know how to interpret BB is ranging or flat, just in EA, what is the method/formula to let the EA determine it?
```double currUpper=iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_UPPER,0);
double currLower=iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_LOWER,0);
double prevUpper=iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_UPPER,1);
double prevLower=iBands(NULL,0,20,2.0,0,PRICE_CLOSE,MODE_LOWER,1);

if(MathAbs((currUpper-currLower)-(prevUpper-prevLower))<100*_Point)  //less than 10 pip difference between current and previous bands - flat
return(0);```
26

pipPod:
Thanks a million !!!
5040

yeah016:
Thanks a million !!!
You're welcome.
26

pipPod:
You're welcome.

Hi PipPod, after I tested, seem like this method also not so accurate to detecting the BB flag or ranging as it compare previous value and current value.

currently I tried on other formula something like below.

MathArctan(MathTan(((price1-price2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0.0)/WindowBarsPerChart())))*180/3.14;

Or maybe you have more accurate formula to detect BB patern?  Thanks in advance

5040

I'd rather use a range with the same period.

```//---
double max =-1000000;
double min = 1000000;
//---
for(int k=BandsPeriod;k>0;k--)
{
//---
if(High[k]>max)
max=High[k];
if(Low[k]<min)
min=Low[k];
}
//---
MathArctan(MathTan(((Close[0]-close[BandsPeriod])/(max-min))/((BandsPeriod-0.0)/BandsPeriod)))*180/M_PI;
```

573

pipPod:

I'd rather use a range with the same period.

573

Thanks