Bermaui DBD% Expert Advisor Example

Bermaui DBD% Expert Advisor Example

9 November 2019, 17:16
Muhammad Elbermawi
0
461

Hi forex trader,

In this blog I want to show you how to use Dual Bermaui Deviation Percent (DBD%) buffers to build a simple MT4 EA.

Important Information

Next screen shots show important buffers:

Dual Bermaui Deviation Percent

.

Dual Bermaui Deviation Percent

.

The only buffer we need here is buffer eight, as it is used to generate trend signals.  Here is the code:

//+------------------------------------------------------------------+
//|                                     Bermaui DBD%s 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 "DBD% Important Output Buffers:"
#property description "=============================="
#property description "Buffer [ 8 ] = DBD% Signal."

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  indAdress            = "Market\\Dual Bermaui Deviation Percent"; // Indicator Path & Name : 
extern int     Fast_Candles         = 20;         // Fast DBD% Candles [Min=2]
extern int     Slow_Candles         = 80;         // Slow DBD% Candles [Min=3]
extern double  Upper_Level          = 40;         // DBD% Sideways Level

//---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(DBDPCustom(1) ==  1 && DBDPCustom(2) == 0) { OpenBUYOrder(MagicNumber);}}

//---Sell Order
if(MyRealOrdersTotal(MagicNumber) == 0){
if(DBDPCustom(1) == -1 && DBDPCustom(2) == 0) { 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 DBD% iCustom Function.                                   |            
//+==================================================================+
double DBDPCustom(int shift)
     {
//+------------------------------------------------------------------+
//| Indicator Options                                                |
//+------------------------------------------------------------------+
// Arrows & Vertical Lines choises
enum AW
{
aShowArrow,    // 1. Show Arrows Only
bShowArrowsVL, // 2. Show Arrows & Lines
cShowVL,       // 3. Show Lines Only
dHideAll       // 4. Hide All
};

// Sympols Source
enum SS
{
aCustom,    // Symbols List
bDataWindow // Market Watch
};

// Colors List Options 
enum CL
   {
aAlex,      // 1. Alex
bLotus,     // 2. Lotus
cNile,      // 3. Nile
dCairo,     // 4. Cairo
eDoNothing, // 5. Do Nothing
   };

//+------------------------------------------------------------------+
//| iCustom Function                                                 |
//+------------------------------------------------------------------+

double DBDP = iCustom(Symbol(),       // Symbol
                      Period(),       // Time-Frame
                      indAdress,      // Indicator Path and name
                      " ",            // 1)) INDICATOR SETTINGS
                      Fast_Candles,   // Fast DBD% Candles [Min=2]
                      Slow_Candles,   // Slow DBD% Candles [Min=3]
                      Upper_Level,    // DBD% Sideways Level
                      " ",            // ALERT SETTINGS
                      false,          // 2)) Alert on New Arrow:
                      false,          // Send e-Mail on New Arrow:
                      false,          // Send Mobile Notification on New Arrow:
                      " ",            // Arrows_Settings
                      aShowArrow,     // Show Arrows & Lines :
                      1,              // Arrows Size
                      " ",            // 3)) UTILITIES SETTINGS 
                      aCustom,        // Symbols Source From:
                      " ",            // List of Symbols (Separated by ";")
                      10,             // Button Font Size
                      false,          // Chart on Foreground
                      100,            // Channel Length [> 1]
                      "A",            // Panel Appear [Shift + Letter]
                      "D",            // Panel Disappear [Shift + Letter]
                      aAlex,          // Chart Colors List :
                      8,              // Buffer [ 8 ] = DBD% Signal
                      shift);
     
return(DBDP);
     }
     

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.

I hope DBD% 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

Share it with friends: