In this article
After this article, you can
- Check data completeness before evaluating a rule.
- Distinguish missing history from a valid no-entry result.
Terms at hand: Simple Moving Average (SMA) · Trading Plan · Backtesting · Position notional (notional value) · Demo account · Expectancy
A first algorithmic project can record signals, calculate position size or check exposure without placing a trade. Start with one operation whose result you can explain and verify. Define the information, rule and program behaviour before granting order permissions; automation does not establish a profitable strategy.
What algo trading is and definitely is not
Separate signal selection, execution of an existing decision, position management and reporting. A program slicing an existing order does not have the same purpose as a robot selecting entries. BIS’s 2020 report on FX execution algorithms discusses market structure, execution and associated risks; it is not evidence that a particular retail trading robot earns a profit. Its abbreviation EA means execution algorithm, whereas MetaTrader uses EA for Expert Advisor.
Specify the instrument, data source, operating times, decision timestamp, entry and exit rules, size, exposure limit and behaviour when a position already exists. Automation retains human decisions about those inputs and supervision. It may prevent one manual mistake while introducing another, such as a duplicate request after a restart. Check program correctness separately from the rule’s economic result.
Choose tools for the task
An alert may be enough for a notification task. Native MT5 Alerts accepts price, last-deal volume and time comparisons; it is not an arbitrary moving-average-and-ATR editor. An indicator or EA may be needed for custom logic. MQL5 works inside MT5, while Python may analyse data or use an appropriate documented connection. There is no required sequence from alerts to MQL5, Python and FIX.
Choose the environment that fits the account, data and operation. Do not assume a standard line count, build time, execution latency or API access on every broker product. The guide to MQL5 expert advisor basics explains the platform’s program behaviour; Forex backtesting in Python covers a separate research workflow. Reimplementing the same idea in both is optional.
The third average input cannot be guessed
The requested number of records is part of the rule. Two valid prices cannot establish a three-price average.
Scroll sideways to see the full diagram
Assumptions: Hypothetical prices for one instrument and interval. All records are completed historical bars; x is an unknown older price, not a future price. Equal weights of 1/3, with no rounding before comparison. Neither alternative is claimed to be market data.
Exactly three closing prices are required: x, 100 and 102, oldest to newest. Only 100 and 102 are known. The invented alternatives x = 98 and x = 106 give means of 100 and 308 /3 ≈ 102.667, respectively. The condition last price > mean has different results.
Averaging the two known prices to obtain 101 changes the rule. Substituting zero creates a fictitious third input. The program must record incomplete data and issue no decision. If retrieval later succeeds, check that it refers to the same intended bars.
MQL5 — record count returned by CopyRates describes copied records, errors and partially available data. This counterexample concerns completeness, not indexing direction or array order.
Skills and the language choice
Useful skills include programming, data handling, risk sizing and statistical reasoning. A short equity curve is evidence about that sample, not proof of future profitability. Plan a validation process with representative data, out-of-sample evaluation and demo execution checks. MQL5 connects through the MT5 terminal, while Python can use that terminal or other documented interfaces. End-to-end latency depends on code, hosting, network and broker execution; it is not guaranteed to be single-digit milliseconds.
An illustrative example — first strategy from concept to backtest
For a hypothetical EUR/USD H1 crossover, define the EMA, SMA and ATR calculation, signal timing, stop and target precisely. Compare manual and automated decisions on the same data and dates first. A five-year automated test need not match a six-month manual sample: regimes and feeds differ. Reconcile same-period discrepancies, model costs and then evaluate the frozen rules on separate data.
An offline specification might use EMA 21, SMA 55 and an ATR-based distance chosen for the exercise. State whether decisions use completed H1 bars and when the program may evaluate them. Initially log the signal rather than submit an order. Test one signal, no signal, a bar change, missing history and an existing position. A missing input is not a valid “no entry” result.
As a separate hypothetical sizing model, assume USD 10,000 equity, a chosen 0.5% initial price-loss budget, a 25-pip stop distance and EUR/USD pip = 0.0001. With 100,000 EUR per standard lot, the pip value is USD 10 per lot. The budget is USD 50, so volume before costs is 50 ÷ (25 × 10) = 0.20 lots, or EUR 20,000 notional. None of these assumed settings is a universal risk recommendation; notional, margin and initial planned loss are different quantities.
Account for commission and execution assumptions before fitting volume to the contract’s permitted step. An ordinary stop can fill differently during a gap, so the USD 50 plan is not an unconditional maximum loss. Compare identical rules and data, not just similar final profits from different trades.
Keep parameter selection separate from evaluation. A favourable result on the data used to select the rule can reflect selection bias rather than a persistent advantage.
A program can compute a false spread by mixing correct quotes from different times. In a hypothetical stream, t1 has Bid/Ask 1.1000/1.1002 and t2 has 1.1010/1.1012. Both spreads are 2 pips with pip = 0.0001. Combining t1 Ask with t2 Bid instead yields (1.1002 − 1.1010) ÷ 0.0001 = −8 pips. A filter accepting spread < 2.5 would wrongly accept that constructed value; it is not an observed negative market spread.
MQL5 SymbolInfoTick returns current prices and the update time in one MqlTick structure. Check success and calculate the condition from the retained structure’s fields. Add a test that intentionally mixes two changing but individually valid readings. A coherent quote is a data check, not a liquidity or future-fill guarantee.
Test code, data and economic results separately
A project can fail through a bad rule, incorrect code, incomplete data, execution differences or operational problems. Do not infer a fixed two-cause ranking or discount programming errors. After an ambiguous order response, inspect the actual orders, deals and positions before retrying. MQL5 OrderSend returning true alone does not establish a completed fill; inspect its result codes and transaction state. Log the rule version, information timestamp and reason for acting or doing nothing.
A backtest also needs the relevant product data, costs and chronology. Record all attempted variants and distinguish development data from evaluation data; revising the rule after reading an out-of-sample result uses that period for development. The guide to trading edge discovery develops this evaluation. Retain unsuccessful reports and reasons for changes rather than selecting only the best curve.
Win rate, expectancy and profit factor answer different questions. In a hypothetical fixed-R sample of 100 trades with 40 wins of +2R and 60 losses of −1R, the mean is (80 − 60) ÷ 100 = +0.2R before costs. Profit factor is 80 ÷ 60 ≈ 1.33. These are chosen arithmetic inputs, not a tested strategy or evidence that the next sample has those outcomes.
Maintain a cost worksheet for data, hosting, licences and time even if a programming language itself has no licence fee. Provider prices, entitlements and recovery arrangements depend on the chosen setup. Check restart and outage behaviour, using the platforms and tools section for the relevant environment; a VPS does not remove supervision or every failure.
What to do tomorrow
- Choose one operation and write a reproducible specification: data, timestamp, rule, result and cases where evaluation must stop. A trustworthy signal log can be a complete first project.
- Verify data completeness and quote coherence on small explainable cases. Keep completed bars distinct from the current bar and preserve the timestamp of the inputs used for each decision.
- If the project needs orders, add them in a clearly identified demo environment. Test an acknowledged request, a rejection, a restart and an ambiguous response; check actual state before retrying. A calendar deadline does not require progressing to live money.
- Freeze the rule for separate evaluation, with product-appropriate costs and data. Compare the same dates and individual decisions. Investigate any material difference rather than declaring a universal percentage tolerance.
- Write the pause, restart and update procedure. Disabling local AutoTrading does not close existing positions. Separate accepted server protection from program-managed rules, and check any remote instance independently. Demo observation is not a guarantee of identical live execution.
Check your understanding
One short exercise
About 2 min · you can try again
Only closes 100 and 102 arrived, but the rule requires a three-price mean. What should the program record?
- The condition holds because the two-price mean is 101.
- The rule cannot yet be evaluated: the older record is missing.
- The condition fails because the missing close is always 106.
Check the answer and explanation
The rule cannot yet be evaluated: the older record is missing.
Completions 98 and 106 give opposite answers. Keep the absent record as missing data.
Frequently asked
What retail algorithmic trading actually is — and what it is not?
It means specifying an operation for software to carry out: signals, execution, position management or reporting. Those tasks need not be combined, and the first project need not trade. Define the information and decision time, missing-data behaviour, size, exposure and actual order status. A chosen planned-loss percentage is not notional exposure or a guaranteed maximum loss. Automation does not establish a profitable edge or preserve one as conditions change.
How should I choose between alerts, an EA and a research program?
Choose tools for the task rather than a compulsory ladder. Native MT5 alerts can monitor simple price, last-deal volume or time conditions; a custom strategy may need an indicator or EA. MQL5 expert advisor basics covers that platform workflow, while Forex backtesting in Python covers research in another environment. Compare the choices in trading bot — MQL5 versus Python. No fixed twelve-to-twenty-four-month schedule, universal subsecond result or broker API entitlement is established here.
What skills do I actually need — and how does that differ from the "learn to code and get rich" myth?
You need enough programming and data-handling skill to verify the behaviour your project actually uses, plus risk sizing and statistical reasoning for evaluating results. Being able to change a parameter without a syntax error does not test execution, state or economic assumptions. A small sample describes that sample; no universal trade count or demo duration proves an edge. Use explicit missing-data, restart, rejection and ambiguous-response cases alongside separate economic evaluation.
Which failure modes should I check before expanding an algo project?
Evaluate several failure modes: the rule, data, program, execution and ongoing operation. Code errors can invalidate a result or create unintended exposure, so a positive historical mean is not sufficient evidence of a sound deployment. The guide to trading edge discovery covers evaluation rather than a guaranteed increase in success odds. Preserve failed variants and a procedure for rejecting or pausing the project; compare orders and fills as well as the final curve.
Sources & bibliography
-
MetaQuotes MetaTrader 5 — Automated Trading · The provider explains automated trading, Expert Advisors and the role of strategy testing in MT5. www.metatrader5.com ↗
-
MetaQuotes MQL5 Reference — programming language for algorithmic trading · Official reference documentation of MQL5 programming and supported application types. www.mql5.com ↗
-
Backtrader Backtrader Quickstart Guide · Official Backtrader introductory documentation covers strategies, indicators and parameter optimization. www.backtrader.com ↗
-
BIS BIS Quarterly Review, December 2019 — FX trading rises to $6.6 trillion per day · The December 2019 review discusses electronic FX trading and nonbank principal trading firms. www.bis.org ↗
-
BIS — Markets Committee FX execution algorithms and market functioning · The 2020 report examines execution algorithms, including order slicing and the trade-off between market impact, market risk and completion. Its provider/user research does not verify a retail robot’s profitability or the lesson’s hypothetical calculations. www.bis.org ↗
-
MetaQuotes — MQL5 Reference OrderSend · Distinguishes a successful request check or placement from completed execution, with result codes and multiple transaction events. Used for demo-state and retry checks, without a guaranteed fill or native execution experiment. www.mql5.com ↗
-
MetaQuotes — MQL5 Reference SymbolInfoTick · Returns current prices and their update time in a MqlTick structure, with a success result. The mixed-time spread example is hypothetical and demonstrates input consistency rather than an observed market opportunity. www.mql5.com ↗
