Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

SignalMAAboveBelow 3 - MetaTrader 5 Library - MT4/MT5 Resources

author EAcpu | 2 reads | 0 comments |

SignalMAAboveBelow 3 - library for MetaTrader 5

SignalMAAboveBelow 3 - library for MetaTrader 5

The library is designed for signals with MAA higher than 2 .

If the price of the current bar is higher than the indicator, both bars must be bullish. If the price of the current bar is below the indicator, both bars must be bearish. So, these two parameters ( current bar size and previous bar size ) are protective filters when opening a position.

In the signal module we need to connect the time series in the constructor :

 //+------------------------------------------------------------------+
//|Constructor |
//+------------------------------------------------------------------+ CSignalMA::CSignalMA( blank ) : m_reverse( wrong ),
                            m_ma_period( 12 ),
                            m_ma_shift( 0 ),
                            m_ma_method( mode_SMA ),
                            m_ma_APPLICATION( 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 the time series, we can access the m_close and m_open objects of the Ci closed and open network classes respectively (the objects are declared at a higher level - at the parent level ExpertLibrary.mqh ).

We work with these objects CSignalMA::long condition

 //+------------------------------------------------------------------+
//| "Poll" indicates that the price will increase.                                  |
//+------------------------------------------------------------------+
integer CSignalMA::long condition( blank )
  {
if (m_type_trade== 1 ) // m_type_trade: Trade enumeration type: 0 -> buy, 1 -> sell, 2 -> buy and sell return ( 0 );
integer result = 0 ;
Integer idx =StartIndex(); //--- if (m_close.GetData(idx+ 1 )-m_open.GetData(idx+ 1 ) return ( 0 );
if (m_close.GetData(idx)-m_open.GetData(idx) return ( 0 );
//--- Analyze the relationship between the closing price of the first analysis bar and the position of the indicator

и в CSignalMA::Short circuit condition

//+------------------------------------------------------------------+
//| "Poll" indicates that the price will fall.                                  |
//+------------------------------------------------------------------+
integer CSignalMA::short-circuit condition( blank )
  { //--- m_type_trade: Trade enumeration type: 0 -> buy, 1 -> sell, 2 -> buy and sell if (m_type_trade== 0 )
return ( 0 );
integer result = 0 ;
Integer idx=start index(); //--- if (m_open.GetData(idx+ 1 )-m_close.GetData(idx+ 1 ) return ( 0 );
if (m_open.GetData(idx)-m_close.GetData(idx) return ( 0 );
//--- Analyze the relationship between the closing price of the first analysis bar and the position of the indicator

Example of opening a position Cancel == Error:

SignalMAAboveBelow 3 - library for MetaTrader 5

Figure 1. SignalMAAboveBelow 3 - Opening a buy position

SignalMAAboveBelow 3 - library for MetaTrader 5

Figure 2. SignalMAAboveBelow 3 - Opening a sell position

Test EA trading test signal MAAboveBelow3.mq5 has default parameters and has not been optimized.

If testing the signal MAAboveBelow3.mq5 in the Expert Advisor is generated in the MQL5 Wizard

 //+------------------------------------------------------------------+
//|Input |
//+------------------------------------------------------------------+
//--- Expert input
input string expert title = "Test signal MAAboveBelow3" ; // document name
Oolong Expert_MagicNumber = 20884 ; //
boolean Expert_EveryTick = false ; //
//--- Main signal input

We enable the operation on each tick (change the default value "false" to "true") and we can get a more interesting result: when the current bar (bar with index #0) becomes equal to or slightly larger than the current bar size range.


Attachment download

📎 signalmaabovebelow_3.mqh (21.56 KB)

📎 testsignalmaabovebelow3.mq5 (17.04 KB)

Source: MQL5 #20164

Verification code Refresh