SignalMAAboveBelow 3 – library MetaTrader 5

This library is a further development of SignalMAAboveBelow 2.

What’s New in ver. 3

  • The CurrentBarSize parameter allows setting the size of the current bar (which is calculated as Close-Open);
  • The PreviousBarSize is the size of the previous bar (calculated as Close-Open).

If the price at the current bar is ABOVE the indicator, both bars must be bullish. If the price at the current bar is BELOW the indicator, both bars must be bearish. So, these two parameters (CurrentBarSize and PreviousBarSize) are protective filters when opening a position.

In the module of signals, we need to connect timeseries in the constructor:

//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSignalMA::CSignalMA(void) : m_reverse(false),
                             m_ma_period(12),
                             m_ma_shift(0),
                             m_ma_method(MODE_SMA),
                             m_ma_applied(PRICE_CLOSE),
                             m_pattern_0(80),
                             m_size_current_bar(40),
                             m_size_previous_bar(20)
  {
//--- initialization of protected data
   m_used_series=USE_SERIES_OPEN+USE_SERIES_HIGH+USE_SERIES_LOW+USE_SERIES_CLOSE;
  }

After connecting timeseries, we can access the m_close and m_open objects of the CiClose and CiOpen classes respectively (the objects are declared at a higher level – at the level of parent ExpertBase.mqh).

We work with these objects in CSignalMA::LongCondition

//+------------------------------------------------------------------+
//| "Voting" that price will grow.                                   |
//+------------------------------------------------------------------+
int CSignalMA::LongCondition(void)
  {
   if(m_type_trade==1) // m_type_trade: enum type of trade: 0 -> BUY, 1 -> SELL, 2 -> BUY and SELL
      return(0);
   int result=0;
   int idx   =StartIndex();
//---
   if(m_close.GetData(idx+1)-m_open.GetData(idx+1)<m_previous_bar_size*PriceLevelUnit())
      return(0);
   if(m_close.GetData(idx)-m_open.GetData(idx)<m_current_bar_size*PriceLevelUnit())
      return(0);
//--- analyze positional relationship of the close price and the indicator at the first analyzed bar

и в CSignalMA::ShortCondition

//+------------------------------------------------------------------+
//| "Voting" that price will fall.                                   |
//+------------------------------------------------------------------+
int CSignalMA::ShortCondition(void)
  {
//--- m_type_trade: enum type of trade: 0 -> BUY, 1 -> SELL, 2 -> BUY and SELL
   if(m_type_trade==0)
      return(0);
   int result=0;
   int idx=StartIndex();
//---
   if(m_open.GetData(idx+1)-m_close.GetData(idx+1)<m_previous_bar_size*PriceLevelUnit())
      return(0);
   if(m_open.GetData(idx)-m_close.GetData(idx)<m_current_bar_size*PriceLevelUnit())
      return(0);
//--- analyze positional relationship of the close price and the indicator at the first analyzed bar

Example of opening positions when Reverse == false:

Alternative:  RSI Peak & Bottom - indicator MetaTrader 4

SignalMAAboveBelow 3 Open Buy

Fig. 1. SignalMAAboveBelow 3 – opening a BUY position

SignalMAAboveBelow 3 Open Sell

Fig. 2. SignalMAAboveBelow 3 – opening a SELL position

Parameters of the signals module

  • Reverse – the flag of the reverse of signals;
  • PeriodMA – the averaging period of the Moving Average indicator;
  • Shift – the horizontal shift of the Moving Average indicator;
  • Method – type of smoothing of the Moving Average indicator;
  • Applied – the type of the price used for the Moving Average calculation;
  • TypeOfTrade – the type of trading signals: 0 → BUY, 1 → SELL, 2 → BUY and SELL;
  • CurrentBarSize – the size of the current bar (calculated as Close-Open);
  • PreviousBarSize – the size of the previous bar (calculated as Close-Open);

The test Expert Advisor TestSignalMAAboveBelow3.mq5 has default parameters, no optimization was performed.

If in the Expert Advisor TestSignalMAAboveBelow3.mq5 generated in the MQL5 Wizard

//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title                 ="TestSignalMAAboveBelow3"; // Document name
ulong                    Expert_MagicNumber           =20884;                     // 
bool                     Expert_EveryTick             =false;                     // 
//--- inputs for main signal

we enable operation ON EVERY TICK (change the default “false” to “true”), we can obtain more interesting results: the EA will faster process the condition when the current bar (bar with index #0) becomes equal to or slightly greater than the CurrentBarSize parameter.

Alternative:  Multi_BreakEven.mt5 - script MetaTrader 5


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks