0
453
Hi forex trader,
In this blog I want to show you how to use MASR Bands buffers to build a simple expert advisor. You can know more about MASR Bands fromt next links:Important Links:
- MASR Bands: https://www.mql5.com/en/market/product/43431
- MASR Tools Manual: https://www.mql5.com/en/blogs/post/721889
All Important Buffers are found in the description dialog.
.
Here is an example about how to use those buffers to code 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.
//+------------------------------------------------------------------+ //| MASR Bands EA Example v1.0.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com/en/users/bermaui314" #property version "1.00" #property strict #property description "Important Output Buffers:" #property description "4)-Buffer [ 11 ] = 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 MASR_Settings; // 1) >>>>>>>>>> MASR INPUTS sinput string indAdress = "Market\\MASR Bands"; // MASR Bands Path & Name : extern int MASR_Bars = 40; // MASR Candles [Min = 2] extern ENUM_MA_METHOD MA_Method = MODE_SMA; // MASR Moving Average Method: //---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(MBCustom() == +1) { OpenBUYOrder(MagicNumber);}} //---Sell Order if(MyRealOrdersTotal(MagicNumber) == 0){ if(MBCustom() == -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);} } //+------------------------------------------------------------------+ // MASR BANDS iCUSTOM FUNCTION | //+------------------------------------------------------------------+ double MBCustom() { enum X { aDoNothing, dHideAll, }; double MB = iCustom(Symbol(), // Symbol Period(), // Time-Frame indAdress, // Indicator Path and name "", // 1) >>>>>>>>>> MASR INPUTS MASR_Bars, // MASR Candles [Min = 2] MA_Method, // MASR Moving Average Method: "", // 2) >>>>>>>>>> MASR ALERTS dHideAll, // Show Arrows & Vertical Lines: 1, // Arrow Size: false, // Sound Alert: false, // Send Email: false, // Send Notification: "", // 3) >>>>>>>>>> MASR STYLE aDoNothing, // Chart Colors List: 11, // Buffer (0 - 3 - 5) 0); // Shift return(MB); }
Best regards
Muhammad Al Bermaui, CMT
Files: