Keep breakout risk stable when volatility changes
A fixed lot size makes a breakout EA take more monetary risk when its protective stop widens. Instead, calculate volume from the intended entry and stop before submitting an MT5 market order. A simple long-only example uses a completed candle closing above the highest high of the preceding 20 completed candles, with a stop two ATR(14) below the current ask. Evaluate once per new bar, and skip if an existing strategy position or pending entry is present.
Worked example
Assume a hypothetical instrument where one lot loses $5 per point and the risk budget is $100. A 20-point stop permits 1 lot; 40 points permits 0.5 lots; 80 points permits 0.25 lots, assuming the volume step allows them.

Figure: blue bars show stop distance in points; green bars show position volume in lots. Each pair targets $100 before costs. Separate scales are used.
MQL5 implementation
OrderCalcProfit estimates profit or loss in account currency for a specified order side, volume and price pair. Round volume down rather than up. The following helper assumes a valid adverse stop and market BUY or SELL side; zero means skip the trade.
double RiskVolume(ENUM_ORDER_TYPE side, double entry, double stop, double budget)
{
double loss;
if(budget <= 0 || !OrderCalcProfit(side,_Symbol,1.0,entry,stop,loss) || loss >= 0)
return 0;
double step = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
double minv = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
double maxv = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
if(step <= 0) return 0;
double v = MathFloor(MathMin(maxv,budget/(-loss))/step)*step;
return v >= minv ? v : 0;
}
Use the latest ask for a buy and bid for a sell. Normalize the stop to the symbol tick size, check minimum stop distance, and calculate volume again after any stop adjustment. Reserve part of the risk budget for commission and slippage. Validate volume limits, margin and request parameters with OrderCheck before sending; inspect trade-server return codes and actual fills. A netting account requires particular care if another strategy trades the same symbol.
Testing and limitations
Compare fixed-lot and risk-sized variants on identical real-tick history with realistic spreads and commissions. Test minimum-lot rejection, gaps, insufficient margin, changing conversion rates and duplicate signals. Record intended risk and realized loss separately. The helper is illustrative and has not been compiled or backtested here. Stops do not guarantee execution prices; leveraged trading can cause substantial losses.
For broker-specific execution controls or additional filters, explore Custom MT5 strategy Development Services.