Hi forex trader,
In this blog I want to show you how to use Bermaui Bands buffers to build a simple MT4 EA. You can know more about Bermaui Bands from those links:
Important Information
Bermaui Bands Demo: https://www.mql5.com/en/market/product/43084
Bermaui Bands: https://www.mql5.com/en/market/product/16251
Bermaui Bands User's Manual: https://www.mql5.com/en/blogs/post/718688
Next screen shots show important buffers:
.
.
In this code I wrote function that call Bermaui Bands buffer four and five that represent the buy and sell arrows on the chart.
This code is just an example about how to use the indicators buffer in building an expert advisor and It was not written to test the indicator ability to trade on real accounts.
Here is the code.
//+------------------------------------------------------------------+ //| Bermaui Bands EA Example.mq4 | //| Copyright © 2019, Muhammad Al Bermawy,CMT. | //| https://www.mql5.com/en/users/bermaui314 | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com/en/users/bermaui314" #property version "1.00" #property strict #property description "BBands Important Output Buffers:" #property description "==============================" #property description "1)-Buffer [ 0 ] = Upper Band." #property description "2)-Buffer [ 1 ] = Middle Line." #property description "3)-Buffer [ 2 ] = Lower Band." #property description "4)-Buffer [ 4 ] = Buy Arrows." #property description "5)-Buffer [ 5 ] = Sell Arrows." sinput string Trading_Setup; // Trading Setup extern int MagicNumber = 1234567890; // Magic Number extern int TakeProfit = 500; // Take Profit (points) extern int StopLoss = 250; // Stop Loss (points) extern double FirstLots = 0.01; // Lot Size sinput string Indicator_Settings; // 1) >>>>>>>>>> INDICATOR INPUTS sinput string BBnd_indAdress = "Market\\Bermaui Bands"; // Indicator Path & Name : extern int Candles = 50; // Candles [Min =2] extern double Deviation_Multiplier = 2.1; // Deviation Multiplier [>0] //---Global Variables int Ticket1; int t1,t2; datetime timeprev = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //---Check trading at candle open only if(timeprev == Time[0]) { return; } timeprev = Time[0]; //---Buy Order if(MyRealOrdersTotal(MagicNumber) == 0){ if(BBndCustom() == 1) { OpenBUYOrder(MagicNumber);}} //---Sell Order if(MyRealOrdersTotal(MagicNumber) == 0){ if(BBndCustom() == -1) { OpenSELLOrder(MagicNumber);}} } //+------------------------------------------------------------------+ //| Custom functions. | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| The number of current Market orders only. | //+------------------------------------------------------------------+ int MyRealOrdersTotal(int Magic) { int c = 0; int total = OrdersTotal(); t1 = -1; t2 = -1; for(int cnt = 0 ; cnt < total ; cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { if(t1 == -1) { t1 = OrderTicket(); } else { if(t2 == -1) { t2 = OrderTicket(); } } c++; } } return(c); } //+------------------------------------------------------------------+ //| Open a Buy Order Function. | //+------------------------------------------------------------------+ void OpenBUYOrder(int Magic) { double en,sl,tp; int slippage = 30; en = Ask; //---Enter of order sl = Ask - (StopLoss * Point); //---Stop Loss tp = Ask + (TakeProfit * Point); //---Take Profit if(FirstLots > 0) {Ticket1 = OrderSend(Symbol(),OP_BUY, FirstLots, en, slippage, sl, tp, "EA Comment", Magic, 0, clrGreen);} else {Alert("Buying Error "," Err = ",GetLastError()," Price = ",Ask," Lots = ",FirstLots);} } //+------------------------------------------------------------------+ //| Open a Sell Order Function. | //+------------------------------------------------------------------+ void OpenSELLOrder(int Magic) { double en,sl,tp; int slippage = 30; en = Bid; //---Enter of order sl = Bid + (StopLoss * Point); //---Stop Loss tp = Bid - (TakeProfit * Point); //---Take Profit if(FirstLots > 0) {Ticket1 = OrderSend(Symbol(),OP_SELL, FirstLots, en, slippage, sl, tp, "EA Comment", Magic, 0, clrRed);} else {Alert("Selling Error "," Err = ",GetLastError()," Price = ",Ask," Lots = ",FirstLots);} } //+==================================================================+ //| Bermaui Bands iCustom Function. | //+==================================================================+ double BBndCustom() { double BB_Up = iCustom(Symbol(), // Symbol Period(), // Period BBnd_indAdress, // Indicator Path and name ">>>>> Bermaui Bands Settings", // 1))Bermaui Bands Settings Candles, // Candles [Min =2] Deviation_Multiplier, // Deviation Multiplier [>0] 2, // Bands Width clrGray, // Bands Color ">>>>> Arrow Settings", // 2)) Arrow Settings true, // Show Arrow Signals: clrBlue, // Buy Arrows Color clrRed, // Sell Arrows Color ">>>>> Alert & eMail Settings", // 3)) Alert & eMail Settings" false, // Send Alert: 4, // Calculation Buffer 1), BB_Dn = iCustom(Symbol(), // Symbol Period(), // Period BBnd_indAdress, // Indicator Path and name ">>>>> Bermaui Bands Settings", // 1))Bermaui Bands Settings Candles, // Candles [Min =2] Deviation_Multiplier, // Deviation Multiplier [>0] 2, // Bands Width clrGray, // Bands Color ">>>>> Arrow Settings", // 2)) Arrow Settings true, // Show Arrow Signals: clrBlue, // Buy Arrows Color clrRed, // Sell Arrows Color ">>>>> Alert & eMail Settings", // 3)) Alert & eMail Settings" false, // Send Alert: 5, // Calculation Buffer 1); int SignalLine = 0; //---Signal Line Binary Value if(BB_Up > 0 && BB_Dn == 0) { SignalLine = 1; } if(BB_Up == 0 && BB_Dn > 0) { SignalLine = -1; } if(BB_Up == 0 && BB_Dn == 0) { SignalLine = 0; } return(SignalLine); }
I hope Bermaui Bands to be a good trading tool for you. If you have any question send me a message and I will answer as soon as I am online.
Best regards
Muhammad Al Bermaui, CMT