CStopOutGuard shows how far a symbol's price can move before the modeled margin level reaches stop-out, and how much closer a planned order would bring that threshold. Positions are valued with OrderCalcProfit() and OrderCalcMargin() at each tested price instead of a fixed tick value, so volume margin tiers are included. Unit tests, test EAs, and a Python consistency check cover the search. The model keeps the spread and swaps at their current values, and CanAdd() does not replace OrderCheck().
An Expert Advisor that trades without a stop loss, or with a stop far away, has one exit it does not control. When the margin level falls to the broker's stop-out level, the server starts closing positions on its own. The account information shows the margin level now. It does not show how far the price has to move before the level is reached, and it does not show how much closer a new order would bring that point.
Grid and averaging EAs need this number most, because every new position moves the stop-out closer. The usual estimate takes the equity above the stop-out level and divides it by the money one point is worth. That shortcut assumes a point is worth the same at any price, and that the margin stays the same while the price moves. On MetaQuotes-Demo the first assumption failed for USDJPY, whose profit is converted at the price it is valued at. The second one held in the tester runs, and my first model got it wrong. For EURUSD and XAUUSD, OrderCalcMargin() returns a different margin at a different price, and the model used that. The tester kept the margin of an open position at its value from the fill, and a check built into the class showed the difference. A third finding concerns new orders: the margin per lot grows with the total volume on the symbol.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: How Far Away Is the Stop-Out? A Stop-Out Threshold Finder and Pre-Trade Guard in MQL5.
An Expert Advisor that trades without a stop loss, or with a stop far away, has one exit it does not control. When the margin level falls to the broker's stop-out level, the server starts closing positions on its own. The account information shows the margin level now. It does not show how far the price has to move before the level is reached, and it does not show how much closer a new order would bring that point.
Grid and averaging EAs need this number most, because every new position moves the stop-out closer. The usual estimate takes the equity above the stop-out level and divides it by the money one point is worth. That shortcut assumes a point is worth the same at any price, and that the margin stays the same while the price moves. On MetaQuotes-Demo the first assumption failed for USDJPY, whose profit is converted at the price it is valued at. The second one held in the tester runs, and my first model got it wrong. For EURUSD and XAUUSD, OrderCalcMargin() returns a different margin at a different price, and the model used that. The tester kept the margin of an open position at its value from the fill, and a check built into the class showed the difference. A third finding concerns new orders: the margin per lot grows with the total volume on the symbol.
Author: Ali Akbar