Add risk controls to an Expert Advisor
Learn the safety layer every bot needs: demo lock, max spread, risk-based sizing, daily loss limit, and emergency disable rules.
Lesson outcomes
- Design risk checks before entry logic.
- Understand why fixed lot size is not enough.
- Build an EA safety checklist before backtesting.
Workshop lab
Complete the demo, notebook, platform, or code task before treating the lesson as finished.
Evidence pack
Keep screenshots, exports, logs, calculations, or code versions in a dated learning folder.
Pass standard
You should be able to explain the failure modes, show your work, and name the stop rule.
Free education, not signals. This lesson is part of EarnSouthAfrica's free forex course. It does not tell you what to buy or sell, it does not promise income, and it should be practised on a demo account before any real-money decision.
Most bot sellers show entries. Serious automation starts with exits, limits, and kill switches. A bot with no risk controls is just a fast way to make uncontrolled decisions.
This lesson teaches design rules. Exact implementation depends on symbol, broker, account currency, and strategy, so treat the examples as patterns to understand and test.
What you should be able to do after this lesson
- Design risk checks before entry logic.
- Understand why fixed lot size is not enough.
- Build an EA safety checklist before backtesting.
Risk checks before signals
- Is the account demo if this is learning code?
- Is the spread below the maximum allowed?
- Is there enough free margin?
- Is today's closed loss below the daily stop?
- Is total open risk below the cap?
- Is the symbol and timeframe allowed by the plan?
Risk-based lot sizing pattern
double CalculateLots(double riskMoney, double stopPoints)
{
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
double moneyPerPointPerLot = tickValue * point / tickSize;
if(moneyPerPointPerLot <= 0 || stopPoints <= 0) return 0;
double lots = riskMoney / (stopPoints * moneyPerPointPerLot);
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
lots = MathFloor(lots / step) * step;
return MathMax(minLot, MathMin(maxLot, lots));
}
This function is still a starting point. You must test it on the exact symbols and account currency you use. CFDs, metals, indices, and exotics can behave differently from major currency pairs.
Emergency stop rules
A bot should have conditions where it refuses to trade: excessive spread, abnormal slippage, repeated order errors, daily loss exceeded, symbol closed, and news window if your plan avoids news. Automation should reduce impulsive trading, not remove caution.
Academy-grade study plan
Automation is software engineering under financial pressure. The lesson standard is not 'the code compiles'; it is that the logic, risk controls, logs, tests, and failure states are explicit before the EA is trusted even on demo.
| Course element | What you must produce |
|---|---|
| Primary artifact | EA design specification |
| Lesson focus | Add risk controls to an Expert Advisor |
| Working environment | Demo account, notebook, exported platform data, or local code sandbox. Never live funds for first practice. |
| Completion standard | You can explain the concept, reproduce the exercise, identify failure modes, and show evidence without relying on a seller's claims. |
Instructor workflow
Use this workflow as if an instructor were marking the lesson. The important question is not whether the topic sounds familiar. The question is whether your notes, screenshots, calculations, logs, or code prove that you can apply add risk controls to an expert advisor under controlled conditions.
- Write the strategy and safety rules in plain language before opening MetaEditor.
- Separate signal generation, position sizing, order execution, trade management, logging, and emergency stop logic.
- Use magic numbers, symbol filters, spread limits, max-trade limits, and daily-loss limits from the first prototype.
- Treat every code change as a new version that needs a new demo test record.
Worked case study: EA opens repeated trades on every tick
A beginner EA compiles and appears to work, but it opens several positions because the entry condition remains true across many ticks. The paid-course response is to add state management: new-bar checks, open-position checks, magic-number filtering, max-trade limits, and logs that explain why a trade was allowed or rejected.
After reading the scenario, write the decision you would make before checking the suggested workflow above. Then compare your decision with the operating model. The gap between those two answers is the part of the lesson that deserves another demo repetition.
Professional template
Complete this template in your own notebook. A paid course would normally hide this kind of operating document behind worksheets; here it is part of the free lesson.
| Field | Standard |
|---|---|
| Requirement | Plain-language rule that a non-programmer could review. |
| MQL5 component | Function, event handler, class, or input used to implement the rule. |
| Safety gate | Condition that prevents oversized, duplicated, stale, or forbidden trades. |
| Test evidence | Compiler result, Strategy Tester report, forward-demo log, and versioned settings file. |
Failure-mode lab
Paid courses often sell confidence. A serious course teaches you how the idea breaks. Before continuing, test the failure modes below on demo, paper, or code review. If you cannot describe the failure, you are not ready to trust the concept.
- Confusing a compiling EA with a tested EA.
- Forgetting that OnTick can fire many times while the same condition remains true.
- Hard-coding risk, symbol names, or trade volume without receiver/account context.
- Removing logs because they look messy, then being unable to explain behaviour later.
Evidence pack and pass standard
Do not mark this lesson complete because you read it. Mark it complete only when you can show the evidence below. Keep the files in a dated folder so your learning history survives platform updates, memory gaps, and sales pressure.
- A one-page note explaining add risk controls to an expert advisor without sales language or copied definitions.
- A screenshot, export, calculation, log, or code file that proves the practical work was completed on demo.
- A written stop rule that says when this topic must not be used with real money.
- A versioned EA specification with inputs, risk gates, and known limitations.
- A demo test folder with compiled file, settings, report, journal logs, and change notes.
Assessment rubric
| Level | What it looks like |
|---|---|
| Not ready | You can repeat the vocabulary but cannot complete the demo task, calculate the risk, explain the failure mode, or show evidence. |
| Course pass | You can complete the practical task on demo, explain the decision rules, show evidence, and name the conditions where the idea must not be used. |
| Strong pass | You can teach the concept to someone else, find edge cases, document a rejected example, and improve the template without weakening risk controls. |
Advanced homework
- Add one safety gate, then create a test that proves the gate blocks a bad trade.
- Refactor one EA idea into signal, risk, execution, and logging sections.
- Write an incident report for a demo EA failure as if it happened in production.
Practical drill
Do this lesson as a controlled exercise, not as a reason to trade live. Open a demo account or notebook, write the lesson title, and record what you changed, clicked, calculated, or checked. If the lesson includes code, compile it only in a demo environment and keep the original version unchanged so you can compare edits safely.
- Write a one-paragraph explanation of add risk controls to an expert advisor in your own words.
- Take one screenshot or note that proves you completed the platform, maths, research, or code task.
- Record one risk rule that would stop you from using this idea with real money.
- If anything feels unclear, repeat the lesson before moving to the next module.
How scammers misuse this topic
Scammers often take real concepts and wrap them in urgency. They may use platform jargon, bot screenshots, copied profit charts, or official-sounding language to make a paid offer feel safe. A real concept is not the same as a safe offer. Before paying anyone, ask whether you can verify the provider, reproduce the calculation, test the claim on demo, understand the risk, and walk away without pressure.
Checkpoint before continuing
- You can list the risk checks that should happen before a bot enters.
- You understand why lot size should come from risk and stop distance.
- You have a bot kill-switch rule in writing.
Official references
These lessons are written as free education. When platform features or rules matter, verify against the official source before using real money.
Risk note: leveraged forex and contracts for difference can lose money quickly. EarnSouthAfrica is an educational publisher, not a broker, adviser, signal provider, or money manager.
Keep exploring
Read the latest guides, take the side-hustle quiz, or contact the editorial desk if you spot a correction.