Volatility-adjusted position sizing for MT4 breakout strategies

A fixed lot size makes a breakout EA risk more money when volatility expands. Instead, use the last completed bar's ATR to define a protective stop and calculate volume from a fixed equity risk budget. This example is long-only and educational.

Signal and risk rules

At the first tick of a new bar, compare Close[1] with the highest High of bars 2 through 21. Enter only if it exceeds that level and no position with the EA's symbol and magic number is open. Use ATR(14) at shift 1, and set the initial stop two ATR below the current Ask. Exit at the protective stop or when a completed close falls below the lowest low of the preceding ten bars. Do not widen the initial stop.

Volatility-Adjusted Position Sizing for Breakout Strategies

Illustration: hypothetical entry 106 and stop 103, with ATR 1.5. Candles are schematic, not market data. With equity $10,000, risk 0.5% is $50. If tick size is 0.01 and tick value is $1 per lot, 300 ticks imply $300 risk per lot; a 0.01 lot step gives 0.16 lots and $48 nominal risk.

MQL4 execution fragment

Place this fragment inside a void function called only after the new-bar, breakout and position checks. RefreshRates before reading Ask and Bid. It assumes a valid broker tick size expressed in price units and tick value in deposit currency; verify both for the symbol. It is not a complete EA.

double atr = iATR(NULL,0,14,1);
double entry = Ask;
double stop = NormalizeDouble(entry-2*atr,Digits);
double distance = entry-stop;
double tickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
double tickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
double step = MarketInfo(Symbol(),MODE_LOTSTEP);
if(distance<=0 || tickSize<=0 || tickValue<=0 || step<=0) return;
double risk = AccountEquity()*0.005;
double lots = MathFloor(risk/(distance/tickSize*tickValue)/step)*step;
if(lots<MarketInfo(Symbol(),MODE_MINLOT)) return;
lots = MathMin(lots,MarketInfo(Symbol(),MODE_MAXLOT));
if(Bid-stop < MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) return;
int ticket = OrderSend(Symbol(),OP_BUY,lots,entry,3,stop,0,"ATR risk",12345,0,clrBlue);
if(ticket<0) Print("OrderSend error: ",GetLastError());

Execution safeguards and testing

Validate lot precision, maximum volume alignment, free margin and broker stop constraints before sending. Some brokers report dynamic stop levels even when MODE_STOPLEVEL is zero. Log failures and avoid blind retries; reconcile open orders first. For the exit rule, use OrderClose at Bid and check the result. Compare fixed-lot and risk-adjusted variants on identical signals, including variable spreads, commission, gaps and slippage. Test multiple volatility regimes and reserve an out-of-sample period. Inspect actual monetary loss per trade rather than only net profit.

See MQL4 symbol properties and OrderSend reference. For broker-specific execution and portfolio limits, contact Custom MT4 strategy Development Services.

Risk disclosure: leveraged trading can cause substantial losses. Stops do not guarantee execution prices. The fragment has not been compiled or backtested.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.