Risk Manager Hotkey Position Sizer
- ユーティリティ
- Botond Halasz
- バージョン: 1.20
- アクティベーション: 5
Risk Manager is an MT5 Expert Advisor that opens a market order with a precisely sized lot at the cursor’s vertical level as Stop-Loss, using a single hotkey. Side is detected automatically: SL below price → BUY, SL above price → SELL. Risk is computed in account currency via OrderCalcProfit, so it works correctly on FX, metals, indices, and crypto.
Why traders use it
- Eliminates mental math and lot calculators.
- Turns any discretionary setup into a consistent, risk-fixed execution in one keystroke.
- Removes sizing errors across different symbols and brokers.
How it works (under the hood)
- The EA continuously reads your mouse Y-position on the chart and converts it to price using a robust linear mapping built from ChartTimePriceToXY.
- Horizontal movements do not change the SL level; only vertical changes matter.
- When you press the hotkey (default S), the EA:
- Infers the side strictly vs current bid/ask (rejects SL inside the spread).
- Computes the SL distance, then the exact loss per 1.0 lot with OrderCalcProfit.
- Calculates the position size that corresponds to your RiskPercent and rounds it down to broker step so risk is never exceeded.
- Places the market order with SL and TP using the chosen risk-reward (RR).
- A compact HUD (top-left via Comment()) shows:
- Balance, % risk, risk in currency
- Cursor SL price and inferred side
- SL distance in pips
- Computed lots and Risk/1lot
- Entry/SL/TP and status messages (e.g., SL inside spread, Stop < min, Open failed: trade disabled)
Key features
- Y-only cursor reading: stable SL regardless of X position.
- Automatic side detection: below price→BUY, above price→SELL.
- True account-currency risk via OrderCalcProfit (instrument-agnostic).
- RR toggle: primary RR (e.g., 1:2) or alternate RR (e.g., 1:3).
- Lot rounding down to volume step; honors min/max volume.
- Broker constraints respected: stop-level, spread buffer, slippage setting.
- One-position-per-symbol option.
Inputs
- SL_Hotkey — Key to fire the trade (default S).
- RiskPercent — % of balance to risk per trade (default 1.0).
- RiskReward — Primary risk-reward, e.g., 2.0 = 1:2.
- RiskRewardAlt — Alternate risk-reward, e.g., 3.0 = 1:3.
- UseAltRR — If true, uses the alternate RR.
- OnePositionPerSym — If true, skips if a position on this symbol already exists.
- SlippagePoints — Max deviation in points for market order.
- Magic — Expert magic number.
- ShowHUD — Show/hide the on-chart HUD.
Usage
- Attach the EA to any chart you want to trade; enable AutoTrading.
- Move the mouse cursor to the desired SL price level (vertical axis).
- Press the hotkey (S by default).
- The EA opens the trade with:
- Correct side (BUY/SELL) based on the SL location,
- Lot size sized to RiskPercent,
- SL at cursor level,
- TP at RR × SL distance.
Tip: keep the cursor inside the main price pane when pressing the key. If the SL is too close (inside spread or below the broker’s minimum stop distance), the HUD will tell you exactly why it didn’t place an order.
Requirements & limitations
- Platform: MetaTrader 5 desktop terminal.
- Keyboard/mouse events are required. MT5 mobile and the built-in MQL5 VPS (headless virtualization) do not forward hotkeys/mouse events. Use a normal Windows PC or a Windows VPS with RDP for 24/7 operation.
- Symbol must be tradable. If you see Open failed: trade disabled, check the symbol specification (some brokers restrict crypto or require a symbol suffix).
Best practices
- Keep OnePositionPerSym=true to prevent stacking accidental clicks.
- Choose SlippagePoints appropriate to symbol volatility.
- For backtesting or demo videos, display the HUD so viewers can verify risk and lot math.
- If your broker enforces a large stop-level, place the cursor farther from price so SL clears broker minimum.
Troubleshooting
- “SL inside spread.” The cursor is between bid and ask; move a bit away.
- “Stop < min (… pts).” Broker’s minimum stop distance not met; increase SL distance.
- “Open failed: trade disabled.” Symbol is close-only/disabled/long-only/short-only or wrong symbol name (suffix).
- Lot is very small. Risk too low for the SL distance and instrument contract size; increase RiskPercent or widen SL.
Compatibility
- Works on FX, metals (XAU/XAG), indices, crypto, energies—anything your broker exposes—as sizing is done with OrderCalcProfit.
- Timeframe-agnostic.
- Honors SYMBOL_VOLUME_MIN/MAX/STEP, SYMBOL_TRADE_STOPS_LEVEL, and price digits.
Risk notice
This tool automates sizing and execution at your chosen SL level. It does not predict markets. Use on demo first, understand your broker’s execution and stop rules, and apply sound risk management.
Changelog
v1.20
- Y-only price reading using a linear map from ChartTimePriceToXY anchors.
- Strict bid/ask side inference with spread buffer.
- Account-currency risk via OrderCalcProfit.
- Clear on-chart HUD and detailed status messages.
- Lot rounding down to not exceed risk.
Quick start (1 minute)
- Attach EA, enable AutoTrading.
- Hover the cursor at the desired SL price.
- Press S → order opens with 1% risk and 1:2 RR (defaults).
- Set UseAltRR=true for 1:3 (or adjust RiskRewardAlt).
