Voir comment télécharger gratuitement des robots de trading
Retrouvez-nous sur Facebook !
Rejoignez notre page de fans
Un script intéressant ?
Poster un lien vers celui-ci -
laisser les autres l'évaluer
Vous avez aimé le script ? Essayez-le dans le terminal MetaTrader 5
Bibliothèque

Risk Lot Sizing Library - four risk bases, tick-value scaling, margin cap, daily limit - bibliothèque pour MetaTrader 5

Jevon Naldo Yoshield
Jevon Naldo Yoshield
I build MetaTrader 5 tools and use them on my own charts. Seven are on the Market.
Order Entry Panel places orders from the chart. Smart Risk and Lot Size Panel turns the risk I set and the stop distance into a lot size. Prop Firm Guard and Drawdown Lock enforces a prop-firm daily loss limit.
Vues:
74
Publié:
MQL5 Freelance Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance
Diagram of the sizing chain: risk money, money per lot at a 250-point stop, a 0.40 lot floored to the 0.01 step, then the 70 per cent free margin cap.

Position sizing is the arithmetic that turns a stop distance and an account balance into the cash amount a trade is allowed to lose. The library does it in one static call: risk money over what one lot loses at your stop, floored to the volume step, capped against free margin.

The four risk bases

  • RISK_FIXED_LOT - the risk value is a lot size; the stop is not read.
  • RISK_PERCENT_BALANCE - a percentage of the account balance.
  • RISK_PERCENT_EQUITY - a percentage of the account equity.
  • RISK_FIXED_AMOUNT - a cash amount, used as the money to risk.

How the lot is produced

  • The two percent modes multiply the account value by the risk divided by one hundred; the fixed-amount mode uses the value unchanged.
  • Stop points times point, over tick size, times tick value, gives the loss of one full lot.
  • Risk money over that loss gives the raw lot.
  • The normaliser floors to the volume step, clamps to the symbol's minimum and maximum, and takes decimals from the step.
  • The margin cap measures a buy at the ask and cuts the lot to fit 70 per cent of free margin.

The daily loss base

  • The base is the balance at the first call, printed to the Experts log, and reset when the calendar day of TimeCurrent changes.
  • The allowed loss is the base times the percentage; equity down by that much is a breach, and it prints an alert line to the Experts log. A base or a percentage of zero or less reports no breach.
  • A balance base against an equity reading means floating profit and loss move the number.
  • The loss and profit getters share that base and equity, and neither returns a negative.

What you supply

  • The symbol, which fixes the volume step, the lot limits, the tick size, the tick value and the margin test.
  • The mode, which decides what the risk value means: lots, a percentage or a cash amount.
  • The stop distance in points, from your own prices; it never reads your order.

Where it stops

  • A stop or risk of zero or less, an invalid tick size, tick value or point, or a zero money per lot returns the minimum lot.
  • That return is silent, and a result below the minimum is raised to it, so an unaffordable risk is exceeded, not refused.
  • The base is memory only: no file, no global variable, so a restart or re-init resets it to that moment's balance.
  • The day turns over on the calendar day of TimeCurrent, which is server time, not an hour you set.
  • The margin cap is per call, on the buy side, absent in fixed-lot mode, and skipped when the margin call fails.
  • It does not compute the stop, choose the symbol or convert currencies; it uses what you pass and the reported tick value.

Good to know

  • Both files are needed: RiskManager.mqh includes Common.mqh by a quoted include, so keep them in one folder under MQL5/Include.
  • The class is version 1.10; Common.mqh carries the four-mode enum and the lot normaliser.
  • No DLL, no trade call: it returns a lot size and a bool and places nothing.
TradeGuard - Reliable Order Execution: No Duplicates, Safe Retries, Restart Recovery TradeGuard - Reliable Order Execution: No Duplicates, Safe Retries, Restart Recovery

A one-file library that handles how an EA trades: pre-trade checks, normalisation to broker limits, safe retries, one order per signal, isolation by magic number and state recovery after a restart. Lot by risk, daily loss limit and equity floor included. Verified in the Strategy Tester.

Rolling VWAP Deviation Regime Filter Rolling VWAP Deviation Regime Filter

A regime-classification oscillator that measures how far, and how persistently, price deviates from a rolling volume-weighted VWAP in standard-deviation units, separating trending conditions from ranging ones.

Auto Fibo Extended Auto Fibo Extended

Auto Fibo Extended is a MetaTrader 5 indicator designed to automatically identify significant swing highs and swing lows and draw Fibonacci Retracement and Extension levels directly on the chart.

Close All Positions Panel Close All Positions Panel

Close all positions panel for MT5: seven buttons to close all, buys, sells, winners, losers, the chart symbol or delete pending orders, on Gold (XAUUSD), forex or any symbol, for manual trades and any EA. Open source code.