The approach that has been reliable for me is the one Fernando Carreiro described years ago: ask OrderCalcProfit() for a known volume, then scale to the money you are willing to lose. I use the symbol's maximum volume as that known size, because 1.0 lot is not always a valid volume.
OrderCalcProfit already returns the result in the account currency, including the contract size and the profit-currency conversion, so the same function works for FX, metals and indices.
Two pitfalls that are easy to miss:
1. Round down to SYMBOL_VOLUME_STEP, not to the nearest step. Nearest can push the real stop loss above the risk budget. If the floored size is below SYMBOL_VOLUME_MIN, I skip the trade rather than silently taking a larger risk than the input says. If you want "use min lot anyway, but only up to X percent", that should be a separate, visible input.
2. A failed OrderCalcProfit or a zero tick value is not a reason to fall back to a hard-coded pip value. It usually means the symbol is not ready yet (no quote, not selected). Retry later, or skip.
Here is a compact version I compiled and use as a script. profit from OrderCalcProfit is negative when the close price is a loss, which is what we want for a stop.
I would be interested in how other people handle the "min lot already exceeds the budget" case on gold with a small account, and whether anyone still prefers TICK_VALUE for anything other than a quick estimate.
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.
The approach that has been reliable for me is the one Fernando Carreiro described years ago: ask OrderCalcProfit() for a known volume, then scale to the money you are willing to lose. I use the symbol's maximum volume as that known size, because 1.0 lot is not always a valid volume.
OrderCalcProfit already returns the result in the account currency, including the contract size and the profit-currency conversion, so the same function works for FX, metals and indices.
Two pitfalls that are easy to miss:
1. Round down to SYMBOL_VOLUME_STEP, not to the nearest step. Nearest can push the real stop loss above the risk budget. If the floored size is below SYMBOL_VOLUME_MIN, I skip the trade rather than silently taking a larger risk than the input says. If you want "use min lot anyway, but only up to X percent", that should be a separate, visible input.
2. A failed OrderCalcProfit or a zero tick value is not a reason to fall back to a hard-coded pip value. It usually means the symbol is not ready yet (no quote, not selected). Retry later, or skip.
Here is a compact version I compiled and use as a script. profit from OrderCalcProfit is negative when the close price is a loss, which is what we want for a stop.
I would be interested in how other people handle the "min lot already exceeds the budget" case on gold with a small account, and whether anyone still prefers TICK_VALUE for anything other than a quick estimate.