Video summary
📌 Day 9 | How to Create a Trading Robot | High Frequency EA (HFT) | Full MQL5 Code | #AutomationFX
Main summary
Key takeaways
Purpose of the Series (EA Type & Goal)
The video (Day 9) is part of an “MQL by Program” series teaching how to build a high-frequency trading Expert Advisor (EA) for MQL5 named HFTA / HFT Robot.
It also highlights the difference between backtesting and live trading, warning that backtest results can be misleading due to real-world constraints.
Backtest Setup + Warning About Live Trading
Example backtest configuration
- Initial deposit: $1000
- Risk percentage: 1%
- Symbol: Gold
- Timeframe: 1 minute (M1)
Why the backtest can look too good
The backtest shows an “up and up” equity curve (described as potentially reaching very high values), but the presenter warns that:
- The EA can open/close/modify many trades very quickly
- Many brokers impose restrictions that affect high-frequency strategies:
- Order/request limits
- If limits are exceeded, you may see:
- warnings
- or even temporary suspension
Recommendation: Test the EA within your broker’s limits before deploying it live.
Trading Strategy Logic (Core Behavior)
Pending order placement
The EA places two pending stop orders around the current price:
- Buy Stop above current price
- Sell Stop below current price
What happens when one triggers
When one pending order executes (e.g., Buy Stop triggers):
- The EA applies an aggressive trailing stop loss to the opened position.
- It also mirrors/updates the opposite pending order so the opposite order’s stop level trails in relation to the active trade.
Code-Building Workflow (MQL5 Tutorial Steps)
Creating the EA
- A new EA file is created in MetaEditor
- Expert name: HFT Robot
Reusing prior patterns
- The tutorial reuses code patterns from earlier episodes (e.g., Day Seven)
- The build is modular, using include files
Include Files / Modular Components
The EA includes reusable modules:
- trade.trade.mqh
- Built-in trading helper
- trade.trade.info.mqh
- Account/info utilities
- Lot size management (.mqh)
- Risk/equity/fixed lot sizing using enum functions
- time filter (.mqh)
- Start/end time restriction using selectable hour/minute inputs
Exposed EA inputs (parameters)
User-configurable inputs include:
- Risk percentage / equity percentage
- Lot sizing method
- Take profit / stop loss / distance (points) between orders and current price
- Magic number (EA identifier)
- Trading window control (start/end hour & minute)
Order Placement Logic
Within OnTick, the EA:
- checks its Magic number to identify its own trades
- applies the time filter to allow/disallow trading
- calculates pending order prices using the configured distance
- examples mention 100 points / 200 points
Placing and updating pending orders
- Places/updates Buy Stop when buy conditions are met
- Places/updates Sell Stop when sell conditions are met
- Uses counting functions (reused from a prior video) to determine:
- current open orders/positions
- current pending orders
Trailing Stop Loss Implementation
The tutorial adds a trailing stop system that runs on each tick/candle:
- It checks whether relevant positions exist (matching symbol + magic number).
- If profit moves in the favorable direction:
- For sells: it calculates a new SL 10 pips behind the current price
- It updates SL via
trade.Modifyonly if the new SL is “better” (i.e., improves in the favorable direction)
Trailing behavior is controlled by an input flag:
- If
trailing=true, trailing logic and related pending updates run.
Mirroring Function: “Mirror SL to Opposite Pending”
A key feature is copying the active trade’s stop-loss logic into the opposite pending order.
This behaves like a reverse-hedging-like mechanism:
- If a buy position is open and has an SL:
- the EA places/updates a sell stop so that if price reverses and hits the SL,
- the EA can trigger a corresponding trade at a related level.
Similarly:
- If a sell exists, it creates/updates the corresponding buy stop pending order.
Implementation outline
- If a buy position exists:
- read its SL
- update/create the opposite (sell stop) pending order with that logic
- If a sell position exists:
- read its SL
- update/create the opposite (buy stop) pending order
If modifications fail, the EA prints trade request errors for debugging.
Modify Pending Order Function
A dedicated function is added to update pending orders with SL/TP using a TradeRequest structure, including error printing if the modify fails.
Backtest Execution / Visual Testing
The presenter runs the EA tester (visualizer mode) on Gold using example parameters such as:
- stop loss / risk settings around 1%
- distance = 200 points initially
- trailing enabled
During the demo:
- after orders are placed and the SL executes:
- the EA updates the open trade’s stop (trailing)
- and updates the relevant opposite pending order’s stop level too
Preview of the Next Video
The next part will make the strategy more aggressive by placing extra pending orders (e.g., “two or three extra orders”) after one side triggers.
Main Speakers / Sources
- Speaker: The video author/presenter (“Hello friends… Day N episode… #AutomationFX”), referencing previous tutorial days and linking components in the description.
- Source material: The MQL5 Expert Advisor code built live in MetaEditor using include files and functions described from earlier episodes (e.g., Day Seven).