Case study

Prop-firm risk management engine

A control layer between strategy and account that enforces hard limits — independently of what the strategy would like to do next.

The problem

Prop-firm evaluations impose strict daily and total drawdown rules that an automated trading system has to account for explicitly. A strategy on its own does not know about them: it sees a signal and opens a position. Whether that position is still allowed under today's loss budget, or how it combines with positions already open, is a separate question — and it has to be answered before the order goes out, not after.

What I built

A risk layer the strategy has to pass through. Every intended order is checked against the account state first; if a limit would be breached, the order does not happen.

  • Percentage-based position sizing from the account balance
  • Daily loss guard
  • Total drawdown guard
  • Floating loss monitoring on open positions
  • Equity protection
  • Exposure limits across simultaneous positions
  • Maximum number of trades
  • Emergency shutdown at a defined threshold
On-chart panel showing the current risk state and the active limits, per account
On-chart panel with the current risk state: the values that decide how big a position may be, kept per account.

Technical considerations

Most of the work in a risk layer is not the limit itself — it is the states in which the limit has to still be correct.

  • Equity versus balance: which one a rule refers to changes what it does
  • Floating profit and loss on positions that are still open
  • Session and day boundaries, including the broker's server time rather than local time
  • Restart behaviour: after a terminal restart the day's loss must not reset to zero
  • Several positions at once, including partially closed ones
  • Broker differences in symbol specification, stop level and lot step

Technologies

  • MQL5
  • MQL4
  • MetaTrader 4
  • MetaTrader 5
  • Risk management

Current status

In use in my own Expert Advisors and adaptable to a given provider's rule set, since the limits differ between providers.

Risk rules limit exposure. They do not make a strategy profitable, and no risk layer guarantees that a prop-firm evaluation is passed.