SunCloudCloud
Avatar

Engineer by

Back to home

FX Algo Trader

Forex Algorithmic Trading Strategies in MQL5

H2 2023 - PresentAlgorithmic TradingMQL5MetaTrader 5Finance

Overview

A collection of forex trading strategies written in MQL5 for MetaTrader 5

This is a collection of foreign exchange (FX) trading strategies written in MQL5 and designed to be compiled and executed with MetaTrader 5. Currently running on a $10,000 USD FTMO account and a $65,000 AUD live account, both showing profitable results as of November 2025.

This is a public GitHub repository where anyone can download the strategies and source code. It's my most starred repository with 21 stars as of November 2025.

The Hard Lesson

Why I stopped manual trading

During H2 2023, I began manually trading a $10,000 Pepperstone account. Within a few months, I managed to turn it into $20,000. That trader's high, that feeling of invincibility, was intoxicating. I thought I had cracked the code.

Then reality hit. In a single trading week, I gave back the entire $10,000 profit. It wasn't the market that beat me—it was my own emotional weakness and hubris. Every loss made me want to revenge trade. Every win made me overconfident. The leverage amplified not just my positions, but my emotions. It became too stressful, too emotional, and ultimately unsustainable.

That experience taught me a crucial lesson: having a profitable strategy means nothing if you can't execute it consistently. As a result, I stopped manual trading entirely and began exploring algorithmic trading as a way to enforce discipline and eliminate emotional decision-making from my trading process.

The Strategy

Range Breakout on Asian Session Highs/Lows

The primary strategy I've been developing and trading is a range breakout strategy focused on USDJPY and XAUUSD (Gold). The logic is simple but effective:

  1. Paint the Asian Session Range: Identify and mark the high and low points during the Asian trading session when markets are typically quieter and ranges are established.
  2. Place Limit Orders: During the London session, place limit buy orders at the Asian high and limit sell orders at the Asian low, anticipating breakouts when the higher-volume London session begins.
  3. Let It Run: Allow trades to run until midway through the New York trading session, capturing the momentum from London-New York overlap—the most liquid period in forex.

Each trade is scaled dynamically to risk at most 1% of the account balance, ensuring consistent risk management regardless of market volatility or position size.

System Architecture

Built with MQL5 for MetaTrader 5

The strategies are written in MQL5, MetaTrader 5's native programming language, allowing for tight integration with the trading platform and direct execution on my broker's servers:

  1. Session Detection: Algorithms identify Asian, London, and New York trading sessions based on GMT time and paint the appropriate ranges.
  2. Order Management: Automated placement of limit orders, stop losses, and take profits based on the identified ranges and risk parameters.
  3. Position Sizing: Dynamic lot calculation to ensure each trade risks exactly 1% of account balance, adjusting for different instruments and volatility levels.
  4. Execution & Monitoring: 24/7 automated execution with alerts and logging for all trades, errors, and system events.

Risk Management

Consistent 1% risk per trade

After learning the hard way that emotions and inconsistent position sizing can destroy an account, I built strict risk management into every aspect of the system:

  • Fixed Risk Per Trade: Every single trade risks exactly 1% of the current account balance. No exceptions, no manual overrides.
  • Dynamic Position Sizing: Lot sizes are calculated automatically based on stop loss distance and account size to maintain the 1% risk target.
  • Automated Stop Loss & Take Profit: Every trade has predefined exit points based on the session ranges and risk-reward ratios, removing any temptation to hold too long or cut winners short.
  • Session-Based Trading: Trades are only placed during specific session windows, preventing overtrading and ensuring the strategy only executes when market conditions align with the edge.

Backtesting Results

5 years of historical data validation

Before risking real capital, I ran extensive backtests using 5 years of historical tick data with realistic spreads and commission. The most profitable set of parameters turned a $10,000 starting balance into $33,946.54—a 239% return over 5 years.

To put this in perspective, the S&P 500 returned 170% from 2019 to 2024, with a particularly rough -18.11% drawdown in 2022 alone. The strategy outperformed the benchmark by 69 percentage points while maintaining a maximum drawdown of just 7.55% across the entire 5-year period—a significant advantage in risk-adjusted returns.

Beyond the raw returns, the risk metrics tell an important story: a profit factor of 1.41 and that minimal drawdown suggested the strategy had a genuine edge, not just curve-fitted parameters that looked good on paper.

5-year backtest equity curve
Backtest performance statistics

Of course, backtests aren't perfect—slippage, server downtime, and real-world execution issues aren't fully captured. But these results gave me enough confidence to deploy the strategy on funded and live accounts, where it continues to perform profitably.

Technology Stack

Core Language

MQL5

Platform

MetaTrader 5

Brokers

FTMO, Live Accounts

Instruments

USDJPY, XAUUSD

Live Performance

Real results from funded and live accounts

As of November 2025, the strategies are running on two accounts with real money—no backtests, no simulations, just live performance:

FTMO Account (USD 10,000)

Performance stats for 10k USD FTMO account

Live Account (AUD 65,000)

Performance stats for 65k AUD live account

Both accounts are in profitable positions overall, demonstrating that the strategy has a genuine edge when executed without emotion. The win rates hover around 46-48%, but because winners are slightly larger than losers on average (positive risk-reward ratio), the expectancy remains positive on the FTMO account.

Key Learnings

What this journey has taught me

  • Consistency beats emotion: The same strategy that made me money manually also lost me money when I couldn't execute it consistently. Algorithmic trading enforces discipline and removes emotional decision-making from the equation.
  • Data-driven edge finding: Searching for edges using algorithms and backtesting has been far more productive than relying on gut feelings. The data reveals what actually works without ego or confirmation bias.
  • Risk management matters more than win rate: A 48% win rate is perfectly fine when your average winner is bigger than your average loser. Consistent position sizing and disciplined stops are what keep you in the game long-term.
  • Leverage is a double-edged sword: Leverage amplifies everything—gains, losses, and especially emotions. For most people (myself included), manual trading with high leverage becomes stressful and leads to poor decision-making.
  • Simple strategies can be effective: You don't need complex machine learning or exotic indicators. A well-defined range breakout strategy with proper risk management can generate consistent profits.
  • Open source benefits everyone: Making my strategies public on GitHub has led to valuable feedback, collaboration opportunities, and helped others learn algorithmic trading. The 21 stars represent people who found it useful enough to bookmark and reference.
Designed by Me