Hi forex trader,

In this blog I want to show you how to use MASR Bands buffers to build a simple expert advisor. If you want to know more
about MASR Bands that read visit next links:

All Important Buffers are found in the description dialog.


MASR Bands


MASR Bands

Here
is an example about how to use those buffers to code an expert advisor depending on MQL4 iCustom() function.






#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com/en/users/bermaui314"
#property version   "1.00"
#property strict

sinput string         Trading_Setup;                           
extern int            MagicNumber      = 1234567890;           
extern int            TakeProfit       = 500;                  
extern int            StopLoss         = 250;                  
extern double         FirstLots        = 0.01;                 
sinput  string        MASR_Settings;                           
sinput string         indAdress        = "Market\MASR Bands"; 
extern int            MASR_Bars        = 40;                   
extern ENUM_MA_METHOD MA_Method        = MODE_SMA;             


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




int OnInit()
  {



   return(INIT_SUCCEEDED);
  }



void OnDeinit(const int reason)
  {

   
  }



void OnTick()
  {

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

double MAR_1 = MBCustom(0,1);
double MAR_2 = MBCustom(0,2);


double MAS_1 = MBCustom(5,1);
double MAS_2 = MBCustom(5,2);


if(MyRealOrdersTotal(MagicNumber) == 0){
if(Low[2] >= MAS_2 && Low[1] < MAS_1) { OpenBUYOrder(MagicNumber);}}


if(MyRealOrdersTotal(MagicNumber) == 0){
if(High[2] <= MAR_2 && High[1] > MAR_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 MBCustom(int buffer, int shift)
     {

enum AW
   {
aShowArrow,    
bShowArrowsVL, 
cShowVL,       
dHideAll       
   };

double MB = iCustom(Symbol(),  
                    Period(),  
                    indAdress, 
                    "",        
                    MASR_Bars, 
                    MA_Method, 
                    "",        
                    dHideAll,  
                    1,         
                    false,     
                      buffer,  
                      shift);
     
return(MB);
     }

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

www.bermaui.com



Source link

Register at Binance