Need help to check EA of Bollinger Band

 

Hi, can anyone help to check this code for Bollinger Band MT4? Becos it is not working in the right way. (see in picture).


//Technical analysis of the indicators


extern int BandsPeriod = 20;          //Period of the Bollinger Bands
extern double BandsDeviation = 2;      //Deviation of the Bollinger Bands
bool BandsBreakUp=false;
bool BandsBreakDown=false;

void FindBandsTrend(){
   BandsBreakUp=false;
   BandsBreakDown=false;
   double BandsTopCurr=iBands(Symbol(),0,BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_UPPER,1);
   double BandsLowCurr=iBands(Symbol(),0,BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_LOWER,1);
   double BandsTopPrev=iBands(Symbol(),0,BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_UPPER,2);
   double BandsLowPrev=iBands(Symbol(),0,BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_LOWER,2);
   if(Close[2]<BandsTopPrev && Close[1]>BandsTopCurr ) { 
      BandsBreakUp=true;
      bHasBrokenHighBarrier = true;
   }
   if(Close[2]>BandsLowPrev && Close[1]<BandsLowCurr ){ 
      BandsBreakDown=true;
      bHasBrokenLowBarrier = true;
   }
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   //Calling initialization, checks and technical analysis
   Initialize();
   CheckCanOrder();
   FindBandsTrend();
   //Check of Entry/Exit signal with operations to perform
   if(BandsBreakUp){
      if(CanOpenBuy && CanOpenSell && CanOrder){ 
         if (bHasBrokenLowBarrier)
            OpenNew(OP_BUY);
         bHasBrokenLowBarrier = false;
      }
   }
   if(BandsBreakDown){
      if(CanOpenSell && CanOpenBuy && CanOrder) {
         if (bHasBrokenHighBarrier)
            OpenNew(OP_SELL);
         bHasBrokenHighBarrier = false;
      }
   }
  }
//+------------------------------------------------------------------+
 
Taproum:

Hi, can anyone help to check my code for Bollinger Band MT4? Becos it is not working in the right way. (see in picture).

Did you try swapping these?

   if(BandsBreakUp){
      if(CanOpenBuy && CanOpenSell && CanOrder){ 
         if (bHasBrokenLowBarrier)
            OpenNew(OP_BUY);
         bHasBrokenLowBarrier = false;
      }
   }
   if(BandsBreakDown){
      if(CanOpenSell && CanOpenBuy && CanOrder) {
         if (bHasBrokenHighBarrier)
            OpenNew(OP_SELL);
         bHasBrokenHighBarrier = false;
      }
   }

 

Hmm,

  1. it's NOT your code!
  2. It is the intention to trade exactly this way:
//+------------------------------------------------------------------------+
//|                                    EA-Bollinger-Breakout-FiverrGig.mq4 |
//|                                                    Gary Lewis          |
//|                                                                        |
//+------------------------------------------------------------------------+

#property copyright     "Taproum_Test"
#property link          "www"
#property version       "1.0"
#property strict
#property description   "This EA will attempt to open orders when it thinks there is a breakout of the Bollinger Bands"

/*
ENTRY BUY: The price breaks above the top bollinger band
ENTRY SELL: The price breaks below the low bollinger band
EXIT: Fixed take profit or hit stop loss
Only 1 order at a time
*/

Maybe you better should search for an EA (I strongly assume they exist!) that trades ranges: "Bollinger range" and select CodeBase or Articles!

 
Carl Schreiber:

Hmm,

  1. it's NOT your code!
  2. It is the intention to trade exactly this way:

Maybe you better should search for an EA (I strongly assume they exist!) that trades ranges: "Bollinger range" and select CodeBase or Articles!

Hi, check the OpenNew() function if it really has the code to do what you want it to do. If it does, try to split the functions into 2 separate functions. like OpenNewBuy() and OpenNewSell() instead of just one.  

Reason: