Trading Risk Controls for Position Size, Daily Loss, Drawdown, and Exposure
Summary
This document explains a modular risk-control library for MetaTrader 5 expert advisors. Its position sizer calculates lot size from stop distance and a balance- or equity-based risk allowance, floors volume to the broker’s step, and returns zero when the allowed risk falls below the minimum lot. Other components track daily loss and optional profit or trade-count limits, impose static or trailing drawdown limits, and measure open-position counts and aggregate money at risk. Filters can constrain spread, trading hours, and Friday activity. The library itself does not place or modify orders; an EA calls its checks before submitting trades.
The description covers persistent guard state across terminal restarts, margin checking, and a demo panel with an optional enforcement mode that can close positions after a limit is reached. It reports a self-test with 78 checks and testing on hedging demo accounts, while noting that netting accounts were not tested. These checks support arithmetic and guard logic, not broker-specific execution assumptions. Gaps and fast moves can cross stops before limits respond, so the controls cannot guarantee a maximum realized loss.
Key ideas
- Lot sizing uses stop distance and floors to the broker’s volume step, returning zero below minimum size.
- Daily guards can track loss limits, optional profit targets, and trades per day.
- Drawdown rules can use static or trailing reference levels, while exposure checks estimate losses if stops are hit.
- Spread, session, and Friday cutoff filters can block new trades before order submission.
- The stated tests do not validate broker execution, and loss guards cannot prevent gap-related losses.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.