Code Library / Bollinger Bands

MQL4 BB Breakout EA

Bollinger Band breakout strategy trading closes outside the bands.

Language: MQL4 · Category: Bollinger Bands · Tags: Bollinger Bands, breakout, MQL4, EA, volatility

Source code

input int BBP=20; input double BBD=2.0; input double Lots=0.1;
void OnTick() {
   double u=iBands(Symbol(),0,BBP,BBD,0,PRICE_CLOSE,MODE_UPPER,0);
   double l=iBands(Symbol(),0,BBP,BBD,0,PRICE_CLOSE,MODE_LOWER,0);
   double m=iBands(Symbol(),0,BBP,BBD,0,PRICE_CLOSE,MODE_MAIN,0);
   if(Close[0]>u&&Close[1]<=u&&OrdersTotal()==0)
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,l,u+(u-m),"BB");
   if(Close[0]<l&&Close[1]>=l&&OrdersTotal()==0)
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,u,l-(m-l),"BB");
}

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own MQL4 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.

Related snippets