Skip to content
All library documents

Managing Aggregate Risk Across an EA’s Position Basket

Article MQL5 articles

Summary

This tutorial extends trade-level risk controls by treating an Expert Advisor’s open positions on one symbol as a combined basket. It describes aggregating position count, total volume, volume-weighted entry, floating profit and loss including swap, estimated margin, direction, and oldest open time. The resulting snapshot supports an aggregate loss limit, a time stop for losing baskets, and pre-trade ceilings on position count, margin, and implied risk. Basket checks run every bar so existing exposure remains supervised even without a new signal.

A companion mean-reversion example addresses sizing methods where a target price or expected move determines position size, making risk an output that needs its own per-leg and basket caps. The tutorial also recommends tracking maximum adverse and favorable excursion and peak position count as diagnostics before choosing limits. The measurements are limited to a symbol and magic number; margin is estimated by pricing each leg as a new order, commission is omitted, and tracking resets after a restart. Once-per-bar checks may also miss intrabar changes, while netting accounts make position-count limits largely ineffective.

Key ideas

  • Aggregate positions by symbol and strategy identifier to assess combined volume, floating P/L, margin, and holding time.
  • Apply basket loss and losing-basket time limits independently of signal generation.
  • Gate new entries against position, margin, and implied-risk ceilings.
  • Target-based sizing requires explicit risk caps because the sizing process can make risk an output.
  • Use excursion and peak-count diagnostics to inform limits, while accounting for per-symbol scope and restart loss of in-memory tracking.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.