Originally posted by a forex trader who got tired of losing money to bad EAs
Look, I'm just going to be honest with you right from the start. I've probably bought and tested at least 20 different forex EAs over the past 3 years. Most of them were garbage. Some worked for a week, then blew my account. Others never even opened a single trade. And the few that actually made money? They'd get absolutely destroyed during news events.
So about 6 months ago, I decided to stop buying other people's junk and build something myself. This is the story of how I went from complete MQL5 noob to building an EA that's actually profitable (and yes, I'm sharing the code at the end).
The Problem With Most Trading Bots
Here's the thing nobody talks about: most forex EAs are designed to pass backtests, not to actually trade profitably. They're optimized on historical data until they look amazing, then they fall apart on live markets.
I realized this after my third blown account. The EA that looked perfect in backtesting (78% win rate! 3:1 R:R!) lasted exactly 11 days live before hitting my 20% drawdown limit. The issue? Fixed stop losses.
During the UK inflation report (which I forgot was happening), volatility spiked. My EA opened a trade with its usual 30-pip stop loss. The market moved 80 pips in 4 minutes. I got stopped out at -30 pips, then it reversed and would've hit my +60 pip TP. This happened THREE TIMES that day.
That's when I understood: fixed stops are broken.
Starting From Scratch (Sort Of)
I'm primarily a Python guy. I've built ML models for sentiment analysis, written scrapers, done the usual data science stuff. But MQL5? That was new territory.
First attempt: I tried to build everything from scratch. News detection via web scraping, custom indicators, the whole nine yards. Spent 3 weeks on it. It compiled with 47 errors. I gave up.
Second attempt: I looked at how other people structure their EAs. Turns out the MQL5 community has some really solid standard libraries (Trade.mqh, SymbolInfo.mqh, etc.). Started using those. Much better.
Third attempt: I focused on solving ONE problem first - the fixed stop loss issue. Everything else could come later.
The ATR Breakthrough
I'd read about ATR (Average True Range) before but never really understood WHY it mattered. Then I ran this simple test:
// Measure volatility on EURUSD for 1 month
double atr_values[];
for(int i = 0; i < 30; i++) {
double atr = iATR(_Symbol, PERIOD_H1, 14);
Print("Day ", i, " ATR: ", atr);
}
The results were eye-opening. During low volatility periods, ATR was around 0.0010 (10 pips). During news events, it jumped to 0.0035 (35 pips). That's 3.5x difference.
So if I'm using a fixed 30-pip stop loss:
- Low volatility: 30 pips is probably fine
- High volatility: 30 pips gets hit immediately, then the trade works
The solution was obvious: multiply stop loss by current ATR.
double atr = iATR(_Symbol, PERIOD_H1, 14);
double dynamic_sl = atr * 2.0; // 2x ATR for stop loss
double dynamic_tp = atr * 4.0; // 4x ATR for take profit (2:1 R:R)
Ran this in strategy tester. Win rate dropped from 78% to 62%, but the profit factor went from 1.2 to 2.4. The EA was finally adapting to market conditions instead of fighting them.
But Wait, There's More (The Partial Close Secret)
Even with dynamic stops, I still had a problem: I'd be up +50 pips, then market would reverse and I'd close at +10 pips. Felt like I was constantly giving back profits.
One day I was reading about professional traders' tactics and came across this idea: partial position closing. The concept is simple:
- Hit first profit target
- Close 50% of the position
- Let the other 50% run to full TP
This does something psychologically important: it guarantees you bank some profit, even if the market reverses. You're never in a situation where a +50 pip trade becomes a +5 pip trade.
Implementing this in MQL5 was actually pretty straightforward:
if(current_profit >= partial_target) {
double close_volume = position_volume * 0.5;
trade.PositionClosePartial(ticket, close_volume);
// Remaining 50% stays open to full TP
}
Backtested this addition. Win rate stayed at 62%, but average win increased by 40%. Now when trades worked, they REALLY worked.
The News Trading Problem (And Solution)
News trading is weird. Everyone knows high-impact news creates volatility and big moves. But most EAs either:
- Turn off completely during news (miss opportunities)
- Trade through news with no adjustment (get destroyed)
I wanted something smarter. The MQL5 calendar API actually makes this possible:
MqlCalendarValue values[];
int count = CalendarValueHistory(values, start_time, end_time);
for(int i = 0; i < count; i++) {
MqlCalendarEvent event;
CalendarEventById(values[i].event_id, event);
if(event.importance == CALENDAR_IMPORTANCE_HIGH) {
// We have a high impact event
// Measure pre-news range and trade the breakout
}
}
My approach: during the 30 minutes before high-impact news, measure the price range. Then wait for a breakout of 150% of that range. This filters out fake moves and only catches the real explosive breakouts.
The results in backtesting were honestly surprising. News strategy alone had:
- Win rate: 58%
- Avg win: 2.1x avg loss
- Profit factor: 1.8
Not amazing, but consistent. Combined with the trend-following strategy (EMA + RSI + ADX), the overall system became much more robust.
What About Breakeven?
This one's personal preference, but I found it helps psychologically. Once a trade is up +20 pips, I move the stop loss to breakeven +2 pips.
Why +2 and not exactly breakeven? Spreads. If you move to exact breakeven, you can get stopped out by spread widening. The +2 pip buffer prevents that.
if(profit_pips >= 20 && current_sl < open_price) {
double new_sl = open_price + (2 * pip_size);
trade.PositionModify(ticket, new_sl, current_tp);
}
The psychological benefit is huge: once you hit +20 pips, the trade is "free." Even if it reverses, you can't lose. This lets you be more patient with winners.
Lessons I Learned The Hard Way
1. Don't optimize on training data
I made this classic ML mistake with my EA. Optimized parameters on 2023 data, got 85% win rate. Tested on 2024 data, got 42% win rate. Oops. Overfitting isn't just a machine learning problem.
Solution: Use walk-forward analysis. Optimize on 3 months, test on next month, repeat.
2. Broker differences matter
My EA worked great on my demo account (IC Markets). Moved to live with a different broker (won't name them), and suddenly spreads were 2-3x higher. Many trades that were profitable on demo became losers because of spread.
Solution: Always backtest with realistic spreads for YOUR broker.
3. Trailing stops are tricky
First implementation of trailing stop: moved SL every tick. Result: EA tried to modify position 47 times in one minute. Broker got annoyed, I got errors.
Better implementation: only move SL if price moved at least 5 pips (the trailing step) AND the new SL is more favorable than current.
double new_sl = bid - trail_distance;
if(new_sl > current_sl + trail_step) {
// OK to modify
}
4. Test with small position sizes first
When I finally went live, I started with 0.01 lots even though my account could handle 0.1. Good thing too, because I discovered a bug in my lot size calculation that only showed up with certain account balances. Would've cost me real money.
5. Keep detailed logs
The MQL5 Print() function is your best friend:
Print("Opening BUY trade: Lot=", lot, " SL=", sl, " TP=", tp, " ATR=", atr);
When something goes wrong (and it will), these logs are the only way to figure out what happened. Save them. Review them weekly.
The Final Result
After 6 months of development, testing, and iteration, here's what I ended up with:
Features:
- ATR-based dynamic stops and targets
- Partial profit taking (50% at +25 pips)
- Automatic breakeven management
- Three strategies: news breakout, trend following, scalping
- Multi-indicator filters (EMA, RSI, ADX)
- Session-based trading (London/NY preferred)
- Full risk management (daily limits, margin checks)
Performance (last 3 months live):
- Win rate: 61%
- Average R:R: 1.9:1
- Monthly return: 12-18% (on 1% risk per trade)
- Max drawdown: 14%
- Trades: 150 total
Is it perfect? No. Does it make consistent money? Yeah, actually it does.
What's Different About This EA
Look, I'm not trying to sell you some magic money printer. This isn't going to make you rich overnight. But here's what makes it different from the 20 other EAs I've tested:
It adapts to volatility - No more getting stopped out during news because the EA uses last century's fixed stops
It protects profit - Partial closes and breakeven management mean you actually keep money when trades work
It's transparent - Full source code. You can see exactly what it's doing, modify it, learn from it
It's been tested properly - Walk-forward analysis, multiple market conditions, real broker spreads
It's still evolving - I use this EA with my own money. When I improve it, you get the updates free
You Can Check It Out (If You Want)
I put the whole thing (source code + documentation) on Gumroad. It's $97 right now as a launch price. Honestly, I priced it there because I figure if you're serious about algo trading, $97 is nothing - that's like two losing trades. But if you're just curious and not committed, $97 is enough to make you think twice.
What you get:
- Full MQL5 source code (NewsFilterEA v2.0 PRO)
- 150+ page documentation (I may have gone overboard here)
- Quick start guide for the "just let me use it" crowd
- Optimized settings for EURUSD, GBPUSD, XAUUSD
- All my testing notes and optimization tips
Link: https://anusiempreciouso.gumroad.com/l/Advanced_News_Trend_Robot
But honestly? Even if you don't buy it, I hope this article helps you think differently about building trading systems. The key insights:
- Dynamic stops > fixed stops
- Partial profit taking > holding full position
- Multiple strategies > single strategy
- Adaptation > optimization
Questions I Know You're Going to Ask
Q: Is this going to make me rich?
No. It's a tool. A good tool, but still a tool. You need proper risk management, the right broker, realistic expectations. This isn't a lottery ticket.
Q: Why are you selling it if it works?
Because I'm one person with limited capital. I can make maybe $1-2K/month with my account size. Selling the EA for $97 to 100 people = $9,700. That's more than I'd make in 6 months of trading. Plus, I enjoy building this stuff.
Q: Can I use it on MT4?
No, it's MT5 only. I'm not going backward to a platform that's been outdated for years.
Q: Will it work on [exotic currency pair]?
Tested on majors: EURUSD, GBPUSD, USDJPY, XAUUSD. Should work on other pairs but you'll need to optimize settings. Not recommended for exotics with huge spreads.
Q: What if I can't get it working?
Email me: lynaplaodi@gmail.com. I actually respond. Usually within 24 hours. I built this thing, I can help you set it up.
Final Thoughts
Building this EA taught me more about trading than the previous 3 years of manual trading. There's something about having to codify your strategy that forces you to think clearly about what actually works vs. what you THINK works.
If you're a developer who trades (or a trader who codes), I highly recommend going through this exercise. Build something. It doesn't have to be complex. Just make it adaptive, make it protect profit, and test it properly.
And if you want to start with what I built, you know where to find it.
Happy trading, and may your stops never get hunted.
P.S. - I'm working on adding a feature for multi-timeframe confirmation. If you grab the EA, you'll get that update free when it's ready. Probably in the next month or so.
P.P.S. - Yes, I know some of you are going to ask "why not use machine learning?" I tried. Twice. Both times I ended up with overfit models that looked amazing in training and awful in practice. Sometimes simpler is better.
Tags: #forex #algotrading #metatrader5 #mql5 #trading #automation #fintech #programming
Connect: Found this useful? I occasionally write about trading and code. Drop your email if you want updates.
Top comments (0)