mql5

Trailing stops in MQL5: how to lock in profit without choking your winners

Trailing stops in MQL5: how to lock in profit without choking your winners

I once had a long on GBPJPY that was up about 70 pips. Nice trade. I'd bolted on a trailing stop the night before, set it to follow 12 pips behind price, and went to bed feeling clever. By morning the position was closed for a 9-pip gain, and the pair had run another 180 pips in my direction without me. The trailing stop did exactly what I told it to: it strangled the trade on the first pullback. That's the whole problem with trailing stops in one story - set them too tight and they turn your best trades…
Read More
Risk management in MQL5: position sizing and stops that survive a losing streak

Risk management in MQL5: position sizing and stops that survive a losing streak

A few years back I had an EA with a 68% win rate in the tester. It looked fantastic. I dropped it on a small live account at a flat 0.20 lots per trade, left it running, and came back a week later to a 41% drawdown. The signals had behaved - roughly what the backtest promised. What drained the account was that I'd hard-coded the lot size and paid no attention to how far the stop sat from entry. A few wide-stop losers in a row, every one of them sized exactly like the tight-stop winners, and the arithmetic…
Read More
How to Write a Custom Technical Indicator in MQL5

How to Write a Custom Technical Indicator in MQL5

Custom indicators are one of the most practical ways to turn a trading idea into a repeatable, visual tool. While MetaTrader 5 ships with dozens of built-in indicators, sooner or later you will want something more specific: a specialized filter, a custom oscillator, a volatility regime detector, a bespoke “signal line,” or simply a cleaner visualization of existing information. This article explains—thoroughly and practically—how to write custom technical indicators in MQL5, with multiple working examples, performance patterns, and tables you can use as a reference. 1. What Makes an MQL5 Indicator Different From an Expert Advisor? Both indicators and Expert…
Read More
MQL5 explained: OnInit, OnDeinit, OnTick – The core of every Expert Advisor

MQL5 explained: OnInit, OnDeinit, OnTick – The core of every Expert Advisor

If you understand OnInit, OnDeinit and OnTick, you understand the heart of every MQL5 Expert Advisor.Everything else – indicators, money management, signals – lives inside or around these three functions. In this article we’ll go deep: What each function really does and when it is called What belongs in which function (and what absolutely doesn’t) Professional patterns for resource management, order logic and debugging Full code examples, including run-once-per-bar logic and clean shutdown The goal is that, after reading this, you can look at any EA and immediately see whether its lifecycle is designed properly. 1. The Event-Driven Model of…
Read More
How to code Your first Expert Advisor in MQL5 in 60 minutes (with source code)

How to code Your first Expert Advisor in MQL5 in 60 minutes (with source code)

Coding your first Expert Advisor (EA) in MQL5 can feel intimidating if you’re not a programmer. The good news: you don’t need a computer science degree to build a simple, working Forex robot for MetaTrader 5 (MT5). In this tutorial you’ll go from zero to a complete EA that: Trades a Moving Average crossover strategy Uses stop loss and take profit Trades automatically using the CTrade class Can be backtested in the MT5 Strategy Tester You’ll also get the full source code, tables of parameters, and explanations of how everything works. 1. What You’ll Build (and How We’ll Do It)…
Read More
MQL5 from scratch: How to code your first Expert Advisor

MQL5 from scratch: How to code your first Expert Advisor

Automating a trading strategy is one of the biggest milestones in a trader’s development. Instead of manually clicking buy and sell, you let a program execute your rules automatically, without fear, greed, or fatigue. In the MetaTrader 5 ecosystem this program is called an Expert Advisor (EA), and it is written in the MQL5 programming language. This article walks you step by step through coding your first Expert Advisor in MQL5. You will learn: What MQL5 and Expert Advisors are How an EA is structured How to use built-in indicators (Moving Averages) How to open and manage trades from code…
Read More