Loading…

Multi Order Risk Envelope

Reading each open position's own risk one at a time never answers "what happens to my account if every stop I have out gets hit at once" - a question that matters most exactly when it is hardest to answer by hand, because correlated positions (several EURUSD-correlated pairs, for example) can all hit their stops on the same adverse move. This library sums each order's stop-bound loss and target-bound gain across an arbitrary ticket set into one combined envelope. Any leg with no stop loss set is excluded from the worst-case total and counted separately as an unbounded-risk leg, rather than being added in as if a missing stop meant zero risk - the same treatment applies to missing take-profits on the best-case side. The result is a worst-case and best-case figure that is honest about what it does and does not cover, plus a live floating P/L figure for the same ticket set as a reference point. The ticket set can be the account's real open orders (collected by magic number, or every order), or a purely hypothetical set built by hand - the same functions work on both, since the calculation only ever reads the struct fields it is given. Notes and limitations - MerClosePnl ignores swap and commission - neither can be known in advance for a future close, so this is a price-only envelope, not a full net-of-costs forecast. - A leg with no stop loss (or no take profit) is deliberately EXCLUDED from the corresponding total and reported via the unbounded/uncapped counts instead of being folded in as zero. A worst-case figure with a nonzero unbounded-leg count is a partial total, not a complete one. - The envelope assumes every stop/target actually fills at its exact price - real slippage and gaps can make the realised worst case worse than this figure shows, particularly around news events or on thin weekend-open gaps. - No hardcoded contract size or point value anywhere - every calculation reads MODE_TICKVALUE / MODE_TICKSIZE per symbol via MarketInfo(), so it behaves correctly on gold, indices and JPY crosses without special-casing.

Script · MT5 · v1.0 · Free

About Multi Order Risk Envelope

Multi Order Risk Envelope is a script for MetaTrader 5. MQL source code included.

Files in the download: MultiOrderRiskEnvelope.mq5.mqh, MultiOrderRiskEnvelope.txt, MultiOrderRiskEnvelopeDemo.ex5, MultiOrderRiskEnvelopeDemo.mq5.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Channels & Envelopes · EURUSD · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria