Discussing the article: "Custom Indicator Workshop (Part 4) : Automating UT Bot Alerts into a Trading Expert Advisor"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Custom Indicator Workshop (Part 4) : Automating UT Bot Alerts into a Trading Expert Advisor.
This article shows how to build an MQL5 Expert Advisor around the UT Bot Alerts indicator. The EA reads custom indicator signals via iCustom() and CopyBuffer(), evaluates entries only on new bars, using the last closed candle at index 1, and enforces a one-direction-at-a-time model by closing opposite positions before taking new entries. It also adds optional ATR-based stop-losses, reward-to-risk take-profits, dedicated buy/sell execution functions, magic-number tracking, and basic backtesting for repeatable evaluation.
The Expert Advisor is built around a set of clear rules that control how signals are read, interpreted, and executed. These rules keep the system predictable during both testing and live execution. First, all trading decisions are executed strictly on the opening of a new bar. This is enforced with a new-bar detection mechanism so that the EA does not react to incomplete price data or repeated ticks within the same candle.
Second, signal evaluation is performed using indicator buffer values at index 1, which represents the most recently closed candle. Signals on the current forming candle are ignored to avoid unstable or misleading trade entries. Third, the EA reads signals directly from the indicator buffers using a controlled acquisition process. The required number of values is copied with CopyBuffer(), and the arrays are maintained as timeseries to keep indexing consistent.
Fourth, position management follows a strict one-direction-at-a-time model. When a new signal appears, any existing position in the opposite direction is closed before a new trade is considered. Fifth, trade direction is controlled through a user-defined input, allowing the system to trade only buys, only sells, or both without changing the core logic. This keeps the strategy flexible while preserving a single execution structure.
Sixth, protective stops are optional and are applied only when enabled. When active, stop-loss levels are calculated from the Average True Range of the most recently closed bar, which provides a volatility-based risk measure that adapts to market conditions. Seventh, take-profit levels are derived from the defined risk distance using a reward-to-risk ratio, keeping profit targets consistent with the level of risk used for each trade.
Finally, trade execution is handled through dedicated functions for opening buy and sell positions. These functions receive all required parameters, including entry price, stop-loss, take-profit, and position size. All positions are identified and managed using a unique magic number so that the Expert Advisor interacts only with its own trades and does not interfere with other running systems. With these rules in place, signal detection, decision-making, and execution remain well defined and consistent.
Author: Chacha Ian Maroa