BACD Cloud EA Example

BACD Cloud EA Example

17 November 2019, 16:32
Muhammad Elbermawi
0
557

BACD Cloud EA Example

Hi forex trader,

In this blog I want to show you how to use BACD Cloud buffers to build a simple expert advisor. If you want to know more about BACD Cloud, then here are some important links about that could be helpful for you:

 

The most important buffers can be found in the description section, like in the next photo:

  Bermaui Cloud


Bermaui Cloud

Here is a coding example about how to build an expert advisor depending on MQL4 iCustom() function.

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.

//+------------------------------------------------------------------+
//|                                        BACD Cloud EA Example.mq4 |
//|                       Copyright © 2019, Muhammad Al Bermawy,CMT. |
//|                         https://www.mql5.com/en/users/bermaui314 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Muhammad Al Bermawy,CMT."
#property link      "https://www.mql5.com/en/users/bermaui314"
#property version   "1.00"
#property strict
#property description "MASR Stochastic Important Output Buffers:"
#property description "========================================="
#property description "1)-Buffer [ 0 ] = BACD Line."
#property description "2)-Buffer [ 1 ] = BACD Histogram Line."
#property description "3)-Buffer [ 6 ] = Arrows."

sinput string  Trading_Setup;                     // 1) >>>>>>>>>> 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;                // 2) >>>>>>>>>> INDICATOR INPUTS
sinput string  indAdress            = "Market\\BACD Cloud"; // Indicator Path & Name : 
extern int     FastPeriod           = 12;         // Fast MA Period
extern int     SlowPeriod           = 26;         // Slow MA Period
extern int     SignalPeriod         = 9;          // Signal Line Period

//---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(BACDCustom() ==  1) { OpenBUYOrder(MagicNumber);}}

//---Sell Order
if(MyRealOrdersTotal(MagicNumber) == 0){
if(BACDCustom() == -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 BACDCustom()
     {
//+------------------------------------------------------------------+
//| Indicator Options                                                |
//+------------------------------------------------------------------+
// Arrows & Vertical Lines choises
enum AW
{
aShowArrow,    // Show Arrows Only
bShowArrowsVL, // Show Arrows & Lines
cShowVL,       // Show Lines Only
dHideAll       // Hide All
};

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

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

//+------------------------------------------------------------------+
//| iCustom Function                                                 |
//+------------------------------------------------------------------+
double BC = iCustom(Symbol(),      // Symbol
                    Period(),      // Time-Frame
                    indAdress,     // Indicator Path and name
                    " ",           // (1) INDICATOR PARAMETERS
                    FastPeriod,    // Fast MA Period
                    SlowPeriod,    // Slow MA Period
                    SignalPeriod,  // Signal Line Period
                    " ",           // (2) ARROWS & ALERTS
                    aShowArrow,    // Show Arrows & Lines:
                    1,             // Arrows Size
                    true,          // Alert on New Arrow:
                    false,         // Send e-Mail on New Arrow:
                    false,         // Send Mobile Notification on New Arrow:
                    " ",           // (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]
                    eDoNothing,    // Chart Colors List:
                    6,             // Buffer [ 6 ] = Arrows
                    0);

//---Signal Line Binary Value
return(BC);
     }
     

The same code is attached to this blog. I hope BACD Cloud 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