Bollinger Band Expert Advisor

Guillaume Thomas  

Hello Everyone, 


I've checked a tutorial to perform a bollinger band expert advisor on youtube (Coding a Simple Bollinger Band Expert Advisor in MQL4 - Start to Finish - YouTube). This tutorial is for MQL4, so I tried to translate it to MQL5 but now I have the 'undeclared identifier" on a ' if ' condition statement with a function. Do you know why ? Here's the MQL5 code : 


#property copyright "Guillaume"
#property link      "https://www.mql5.com"
#property version   "1.00"

//------
//INPUTS
//------
//Bands
input int                InpBandsPeriods = 20; //Bands periods
input double             InpBandsDeviations = 2.0; //Bands deviation
input ENUM_APPLIED_PRICE InpBandsAppliedPrice = PRICE_CLOSE; //Bands Applied Price

//TPSL :: Take Profit Stop Loss Deviations

input double InpTPDeviations = 1.0;   //Take Profit Deviations
input double InpSLDeviations =1.0;    // Stop loss deviations 

input double  InpVolume = 0.01;       // Lot Size
input int     InpMagicNumber = 202020;   //Permet de retrouver un trade
input string  InpTradeComment = __FILE__; 


int OnInit()
  {
//besoin de rien
   return(INIT_SUCCEEDED);
   
  }


void OnDeinit(const int reason) {
//besoin de rien
   
}

void OnTick()  {

/// THE MISTAKE IS ON THIS LIGN, ON ISNEWBAR
  if (IsNewBar() == false) return; 

  double   close1 = iClose(Symbol(),Period(),1);
  double   high1  = iHigh(Symbol(),Period(),1); 
  double   low1   = iLow(Symbol(),Period(),1);  
  
  
  double   upper1 = iBands(Symbol(),Period(),InpBandsPeriods,0,InpBandsDeviations,InpBandsAppliedPrice);
  double   lower1 = iBands(Symbol(),Period(),InpBandsPeriods,0,InpBandsDeviations,InpBandsAppliedPrice);
  
  double   close2 = iClose(Symbol(),Period(),2);
  double   upper2 = iBands(Symbol(),Period(),InpBandsPeriods,0,InpBandsDeviations,InpBandsAppliedPrice);
  double   lower2 = iBands(Symbol(),Period(),InpBandsPeriods,0,InpBandsDeviations,InpBandsAppliedPrice);
  
  //Trading test
  //Verification pour sell
  if(close2>upper2 && close1<upper1) {     //rentrey from above : sell
      OpenOrder(ORDER_TYPE_SELL_STOP,low1,(upper1-lower1));
      }
  //meme chose pour le buy
  if(close2<upper2 && close1>upper1) {     //rentrey from bellow : buy
      OpenOrder(ORDER_TYPE_BUY_STOP,high1,(upper1-lower1));
      }
      
  return;
  
}


bool IsNewbar() {
   // Open time for the current bar
   datetime currentBarTime = iTime(Symbol(), Period(),0);
   //Initialise on first use
   static datetime prevBarTime = currentBarTime;
   
   if(prevBarTime<currentBarTime) {   //New bar opened
   prevBarTime = currentBarTime;      //Update prev time before exit
   
   return(true); 
   }
   return(false);
}

//OpenOrder Function
int OpenOrder(ENUM_ORDER_TYPE OrderType, double entryPrice, double channelWidth) {

   //Size of one deviation
   double deviation = channelWidth/(2*InpBandsDeviations); 
   double tp = deviation * InpTPDeviations;
   double sl = deviation * InpSLDeviations;
   datetime expiration = iTime(Symbol(),Period(),0)+PeriodSeconds()-1; 
   entryPrice = NormalizeDouble(entryPrice, Digits());  
   double tpPrice = 0.0;
   double slPrice = 0.0;
   double price = 0.0;
   
   double stopsLevel = Point()*SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL);
   
   //Dans le case d'un ordre de buy
   if (OrderType%2 == ORDER_TYPE_BUY) { //Buy, buystop
      
      
      MqlTick Latest_Price; // Structure to get the latest prices      
      SymbolInfoTick(Symbol() ,Latest_Price); // Assign current prices to structure 
      price = Latest_Price.ask;
      
      
      if (price>=(entryPrice-stopsLevel)){
         entryPrice = price;          
         OrderType = ORDER_TYPE_BUY;  
   } 
         tpPrice = NormalizeDouble(entryPrice-tp,Digits());
         slPrice = NormalizeDouble(entryPrice + sl, Digits());
   
   } else 
   if (OrderType%2==ORDER_TYPE_SELL) { //Sell,sellsstop
      
      MqlTick Latest_Price; // Structure to get the latest prices      
      SymbolInfoTick(Symbol() ,Latest_Price); // Assign current prices to structure 
      price = Latest_Price.bid;
      
      
      if (price<=(entryPrice+stopsLevel)){
         entryPrice = price;
         OrderType = ORDER_TYPE_SELL;
      }
      tpPrice = NormalizeDouble(entryPrice-tp,Digits());
      slPrice = NormalizeDouble(entryPrice + sl, Digits());
   } else {
   
   return(0);
   } 
          
               MqlTradeResult result={}; 
            MqlTradeRequest request={}; 
   return(OrderSend(request,result));

}

Thank you :)

Coding a Simple Bollinger Band Expert Advisor in MQL4 - Start to Finish
Coding a Simple Bollinger Band Expert Advisor in MQL4 - Start to Finish
  • 2020.12.05
  • www.youtube.com
This video takes you through building a complete EA using a simple Bollinger Band strategy step by step.If you do not have Metatrader 4 or 5 you can download...
Haruto Rat  
if (IsNewBar() == false) return;
(...)
bool IsNewbar()

It's B vs. b.

Function names (and MQL generally) are case-sensitive.

I didn't check the rest of the code.

Guillaume Thomas  
Haruto Rat #:

It's B vs. b.

Function names (and MQL generally) are case-sensitive.

I didn't check the rest of the code.

Wow I was too much implicated, I didn't see that... Thank you so much for your answer !
Reason: