Hi Forex trader,
In this blog, I want to show you how to use Bermaui
RSI Candles buffers to build a simple expert advisor.
- You can know more about RSI Candles from here: https://www.mql5.com/en/market/product/4809
You can find the important buffers are in the description dialog.
The buffer used to generate alerts is called "Arrows". It is buffer number one. That is because mql4
count buffers from zero.
The arrows buffer returns a numeric value when RSI Candles crosses an overbought or an oversold level as follow:
This simple expert advisor will buy when the arrows buffer equals to -2, and sell when the arrows buffer equals to -1.
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.
.
//+------------------------------------------------------------------+ //| RSI_Candles_EA_Example.mq4 | //| Copyright © 2020, Muhammad Al Bermawy,CMT | //| https://www.mql5.com/en/users/bermaui314 | //+------------------------------------------------------------------+ #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 ] = RSI." #property description "2)-Buffer [ 1 ] = 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; // INDICATOR INPUTS sinput string indAdress = "Market\\Bermaui RSI Candles"; // Indicator Path & Name : extern int RSIPeriod = 14; // RSI Period extern double OverSold = 30.0; // Over Sold Level extern double OverBought = 70.0; // Over Bought Level //---Global Variables int Ticket1; int t1,t2; datetime timeprev = 0; //+------------------------------------------------------------------+ //| 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(RSICustom() == -2) { OpenBUYOrder(MagicNumber);}} //---Sell Order if(MyRealOrdersTotal(MagicNumber) == 0){ if(RSICustom() == -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);} } //+==================================================================+ //| iCustom Function. | //+==================================================================+ double RSICustom() { //+------------------------------------------------------------------+ //| Indicator Options | //+------------------------------------------------------------------+ // Colors List Options enum X1 { aCustom, aDoNothing, }; //+------------------------------------------------------------------+ //| iCustom Function | //+------------------------------------------------------------------+ double bc = iCustom(Symbol(), // Symbol Period(), // Time-Frame indAdress, // Indicator Path and name " ", // (1) INDICATOR PARAMETERS RSIPeriod, // RSI Period OverSold, // Over Sold Level OverBought, // Over Bought Level " ", // (2) V LINES & ALERTS false, // Show Vertical Line: false, // Sound Alert: false, // Send Email: false, // Send Mobile Notification: " ", // (3) UTILITIES SETTINGS aCustom, // Symbols Source From: " ", // List of Symbols (Separated by ";") 10, // Button Font Size 100, // Channel Length [> 1] "A", // Panel Appear [Shift + Letter] "D", // Panel Disappear [Shift + Letter] " ", // (4) INDICATOR STYLE aDoNothing, // Chart Colors List: clrSeaGreen,// RSI Bullish Color clrOrange, // RSI Bearish Color clrNONE, // Inner & Outer Channel Color clrNONE, // Main Grid Levels Color clrNONE, // Sub Grid Levels Color clrNONE, // Zig Resistance Color clrNONE, // Zig Support Color 3, // RSI Candle Body Width 1, // Buffer [ 1 ] = Aorrows 0); // Shift return(bc); }
.
I hope Bermaui RSI Candles 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.
Enjoy the game
Muhammad Al Bermaui, CMT