i use bollinger bands when trading in mt4/5 and the setups i look for are the ones with clean, straight bands, i avoid trading bollinger bands squeezes, or the rounded ones which narrows at the current candle or the flared out ones which just go in the opposite direction, i had setup an alert EA but always manually traded, now i wish to automate, does anybody have any idea how i can go about this ? I am not asking for the code itself, maybe someone who has encountered a similar problem before or redirect me to another article or something, tried on many other forums but no one seems to know the answer and the one's that do demand a large sum of money, i just want to learn for myself. I've checked everywhere else, need help.. if someone is kind enough to show me the code in either mql4 or mql5, it would be greatly appreciated. Thank you.
2 Answers
Q : "...if someone is kind enough to show me the code..."
The code is obvious and simple. Use your preferred sigma & period values and formulate your conditions using the MQL4/5, by a documented call-signature for the Bollinger Bands® technical indicator iBands()
.
MQL4 Reference / Technical Indicators / iBands
iBands
Calculates the Bollinger Bands® indicator and returns its value.
double iBands(
string symbol, // symbol
int timeframe, // timeframe
int period, // averaging period
double deviation, // standard deviations
int bands_shift, // bands shift
int applied_price, // applied price
int mode, // line index
int shift // shift
);
Parameters
symbol
[in]
Symbol name on the data of which the indicator will be calculated.NULL
means the current symbol.
timeframe
[in] Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.
period
[in]
Averaging period to calculate the main line.
deviation
[in]
Number of standard deviations from the main line.
bands_shift
[in]
The indicator shift relative to the chart.
applied_price
[in]
Applied price. It can be any ofENUM_APPLIED_PRICE
enumeration values.
mode
[in]
Indicator line index. It can be any of the Indicators line identifiers enumeration value(0 - MODE_MAIN, 1 - MODE_UPPER, 2 - MODE_LOWER)
.
shift
[in]
Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).Returned value
Numerical value of the Bollinger Bands® indicator.
Example :
if( iBands( NULL, 0, 20, 2, 0, PRICE_LOW, MODE_LOWER, 0 ) > Low[0] ) return( 0 );

- 1
- 6
- 50
- 92
If you are looking to see the difference between the lower and higher deviations, you can use the int mode
to access the deviations. 1 - MODE_UPPER
being the upper deviation and 2 - MODE_LOWER
being the lower. If you compare these two values leaving some leeway you should easily be able to calculate a channel. The documentaion is also quite extensive and explains a lot.

- 1