Universal Signals and Universal Tracking Modules - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources








MetaTrader 5 provides MQL wizard for generating expert advisors based on trading, tracking and money management modules from the standard library. The library provides a limited number of predefined signals up to certain built-in indicators . The project allows you to generate EAs based on arbitrary signals, driven not only by standards but also by custom indicators and expressions.
Disclaimer. This is a proof-of-concept (POC) library. It may not offer all the methods you want for generating trading signals. Please use the source code to extend the library as you see fit.
The new signal module is SignalUniversal.mqh (should be placed in MQL5/Include/Expert/Signal).
The new tracking module is TrailingUniversal.mqh (should be placed in MQL5/Include/Expert/Trailing).
These modules are available in MetaEditor's MQL Wizard only after the editor is restarted.
Indicators and signals setup is based on the article:
In this article you can find a list of supported indicators, how to specify custom indicators, how to pass parameters, how to construct signals and more, including optimization support. The core is the header file IndicatR.mqh (located in MQL5/Include/IndStats/ and is an improved version of the original IndicatN.mqh).
Custom indicators with maximum 20 parameters are supported. The core allows you to define 6 explicit indicators in inputs, and 8 signals in inputs, with optional 2 implicit indicators in each signal. Explicit indicators are defined in the __INDICATOR_1 .. __INDICATOR_6 group, which can then be referenced from the signal via the numeric index (1..6) in the IndicatorX/Y input of the corresponding signal. Implicit indicators are specified in IndicatorX/Y inputs as strings of special format indicator name@buffer(param1,param2,...)[bar] .
The universal signal equivalent to the "so called" model/pattern is provided by the module. All modules of the standard library follow the same principles.
SignalUniversal.mqh supports the following signals of IndicatR.mqh: buy, sell, buyExit, sellExit (can be combined for recovery).
TrailingUniversal.mqh supports the following signals of IndicatR.mqh: ModifySL, ModifyTP.
IndicatR.mqh currently does not support stop-loss orders and limit orders.
In addition to the original SignalCondition introduced in the article (such as NotEmptyIndicatorX, IndicatorXcrossesIndicatorY, IndicatorXcrossesLevelX, etc.), a new option ExpressionByIndicatorX has also been introduced. It allows you to calculate signal values via mathematical expressions. When ExpressionByIndicatorX is enabled, the expression should be given in the first IndicatorX input of the desired signal.
Expressions are processed by the parser described in the article:
You don't need to know how the parser works, but the article provides useful information about supported operators, functions, and principles of operation. An extended version (v.1.2) of the parser is included here.
New functors were added in version 1.2:
To generate an EA with a new universal signal, select File -> New -> Expert Advisor (Generate) in the meta-editor. In the second step after pressing the "Add" button, in the "Signal module parameters" dialog box you should select "Universal signal from any indicator".

This block provides input parameters with Pattern_N intensity for each of the 8 signals. According to the article [1], the actual parameters of signals and underlying indicators should be specified in the exposed inputs of IndicatR.mqh. In the 3-d step of the wizard you can select "Trailing stop based on universal signals" (there are no inputs here, all settings are made through inputs exposed by IndicatR.mqh).

After creating the EA, you should have source code similar to UniversalSignalDemo.mq5 attached here.
Below is an example demonstrating EA setup. It uses the custom indicator SilverTrend_Signal . This is a signaling indicator that places bullets on the chart during buy and sell conditions. The 0th buffer holds the sell signal and the 1st buffer holds the buy signal. Normally, the signal indicator should use the EMPTY_VALUE value for all bars without signals. For such correct indicators, the library provides the special condition NotEmptyIndicatorX (it checks the value against EMPTY_VALUE and returns true for any other number). SilverTrend_Signal however uses 0 to represent a null value. To deal with this peculiarity, we can use different methods. First, there is the IndicatorXrelatesToLevelX condition, which can be used to compare the indicator value with 0 (default is level). Secondly, we can use expressions with built-in conditions ExpressionByIndicatorX. For the first indicator, the value from the desired buffer and bar number can be used as C1, for the second indicator as C2, and so on. Below you can see the "C1!= 0" and "C2!= 0" settings for Sell and Buy.

Buy and sell signals via custom indicator SilverTrend_Signal with expressions
This indicator has 2 parameters (RISK and NumberofAlerts), which are ignored in the settings, so the default values of 3 and 2 will be used. If we need to give specific parameters, they should be filled in the parameter input in the form of a comma separated list, for example "5,1". Signal names are arbitrary strings that will be displayed in logs and alerts when the corresponding conditions are met.
Explicit indicator values can be read through the INDn function instead of the variable Cn. So the same settings can be changed in the following way.

Using SilverTrend_Signal buy and sell signals via another expression
The same indicator can be set implicitly directly in the input IndicatorX of the corresponding signal, for example: SilverTrend_Signal@0(3,2)[1] Sell (buffer 0, bar 1). This eliminates the need to use explicit indicator groups.
We can use the Universal Trailing Indicator.

MA Universal Trailing (for demonstration purposes only)
Finally, this is how you access symbol properties from expressions.

Buy and sell signals are in units of 10 pips
The screenshot below shows a test trade with a custom signal.

Unfortunately, by default, all inputs of the library are located before the EA's working parameters, since the library is included before the EA inputs. You can move all includes after the input in the generated source code.
Attachment download
📎 rubbarray.mqh (2.33 KB)
📎 fmtprnt3.mqh (3.86 KB)
📎indicatr.mqh (64.74 KB)
📎 expressioncompiler.mqh (2.23 KB)
📎expressionevaluator.mqh (1.94 KB)
📎 expressionpratt.mqh (6 KB)
📎 expressionprecedence.mqh (3.03 KB)
📎expressionprocessor.mqh (14.55 KB)
📎 expressionpromise.mqh (16.76 KB)
📎 expressionshuntingyard.mqh (6.16 KB)
📎 functors.mqh (3.92 KB)
📎 hashmapsimple.mqh (2.85 KB)
📎 indicators.mqh (1.41 KB)
📎 nans.mqh (1.23 KB)
📎 variabletable.mqh (5.63 KB)
📎 globalvars.mqh (1.16 KB)
📎 indicators.mqh (5.13 KB)
📎 series.mqh (2.32 KB)
📎 symbolprops.mqh (2.05 KB)
📎 signaluniversal.mqh (6.59 KB)
📎 trailinguniversal.mqh (3.71 KB)
📎universalsignaldemo.mq5 (7.66 KB)
📎universalsignaldemo.set (8.65 KB)
Source: MQL5 #32107
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •