Hi forex trader,

In this blog I want to show you how to use Bermaui Channel buffers to build
a simple expert advisor.

All Important Buffers are found in the description dialog.



Bermaui Channel


.



Bermaui Channel


.
This simple expert advisor will buy when close price crosses the highest low level (buffer #1),
and sell when close price crosses the lowest high level (buffer#3)
.
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.

.






#property copyright "Copyright © 2020, Muhammad Al Bermawy,CMT"
#property link      "https://www.mql5.com/en/users/bermaui314"
#property version   "1.00"
#property strict
#property description "Important Output Buffers:"
#property description "===================================="
#property description "1)-Buffer [ 0 ] = Hightest Hight."
#property description "2)-Buffer [ 1 ] = Hightest Low."
#property description "3)-Buffer [ 2 ] = Center Line."
#property description "4)-Buffer [ 3 ] = Lowest High."
#property description "5)-Buffer [ 4 ] = Lowest Low."

sinput string  Trading_Setup;                 
extern int     MagicNumber      = 1234567890; 
extern int     TakeProfit       = 500;        
extern int     StopLoss         = 250;        
extern double  FirstLots        = 0.01;       
sinput  string Index_Settings;                
sinput string  indAdress        = "Market\Bermaui Channel"; 
extern int     Candles          = 50;         
extern int     Shift            = 1;          


int    Ticket1;
int    t1,t2;
datetime timeprev = 0;




void OnTick()
  {

if(timeprev == Time[0]) { return; }
   timeprev =  Time[0];


if(MyRealOrdersTotal(MagicNumber) == 0){
if(Close[2] < BCCustom(1, 2) && Close[1] >= BCCustom(1, 1)) { OpenBUYOrder(MagicNumber);}}


if(MyRealOrdersTotal(MagicNumber) == 0){
if(Close[2] > BCCustom(3, 2) && Close[1] <= BCCustom(3, 1)) { OpenSELLOrder(MagicNumber);}}
   
  }







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);
  }




void OpenBUYOrder(int Magic)
   {
double en,sl,tp;
int    slippage = 30;
 
en = Ask;                  
sl = Ask - (StopLoss * Point);   
tp = Ask + (TakeProfit * Point); 
 
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);}

   }




void OpenSELLOrder(int Magic)
   {
double en,sl,tp;
int    slippage = 30;
 
en = Bid;                        
sl = Bid + (StopLoss * Point);   
tp = Bid - (TakeProfit * Point); 
 
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);}

   }




double BCCustom(int buffer, int shift)
     {




enum X1
   {
aDoNothing,
cHide,
   };




double bc = iCustom(Symbol(),   
                    Period(),   
                    indAdress,  
                    " ",        
                    Candles,    
                    Shift,      
                    " ",        
                    false,      
                    false,      
                    false,      
                    " ",        
                    aDoNothing, 
                    cHide,      
                    false,      
                    1,          
                    clrNONE,    
                    clrNONE,    
                    clrNONE,    
                    clrNONE,    
                    1,          
                    4,          
                    3,          
                    buffer,     
                    shift);     
                    
return(bc);
     }


.
I hope Bermaui Channel to be a good trading tool for you. If you have any question send me a
message, or write a comment and I will answer as soon as I am online.

Best regards
Muhammad Al Bermaui, CMT




Source link

Register at Binance