RiskGuard Toolkit Library

RiskGuard Toolkit Library for MQL5 developers - version 1.01
  • Questions before buying? Message me privately and I will show you how the functions fit into your own EA.
  • Need an example for your use case? Ask by private message - integration help is included.
  • Send a screenshot of your order and receive one of my free products as a thank-you.

Stop rewriting the same risk code in every Expert Advisor

Every serious EA needs the same boring but critical pieces: a lot size that matches the risk you intend, a stop that respects volatility, a spread filter, a session window, a daily loss limit and a pre-trade check that the order will actually be accepted. Writing these again for each project wastes hours, and small mistakes (a lot not normalised to the volume step, a stop inside the stops level, a forgotten margin check) are exactly what makes Market validation fail or live accounts misbehave.

RiskGuard Toolkit is a compact, compiled MQL5 library that gives you all of it in 16 tested functions. Import it once and call what you need - from a single lot calculation to a full one-line "can I trade now?" gate that explains why when the answer is no.

What you get

Position sizing. RG_LotsByRiskPercent and RG_LotsByRiskMoney return a lot size that loses exactly the risk you choose if the stop is hit, with the symbol's minimum lot as a floor. Pass 0 as the stop distance and a sensible volatility-based stop is used automatically. RG_NormalizeLots rounds any lot to the broker's step and clamps it to the allowed range. RG_MoneyPerLot tells you what one full lot loses over any price distance, with a fallback for symbols whose tick value is reported as zero.

Volatility tools. RG_ATR returns an ATR value on any symbol, timeframe and period safely (0 when history is missing, never an array error). RG_ATRStopPrice gives you a ready stop price for a buy or sell from an entry price, timeframe, period and multiplier.

Market filters. RG_SpreadPoints and RG_SpreadOK handle spread checks; RG_InSession supports trading windows, including overnight windows that wrap past midnight.

Validation-grade order checks. RG_StopsValid checks SL/TP against the stops level, RG_MarginOK compares the required margin with free margin, and RG_OrderLimitOK respects the account order limit and the symbol volume limit - the same checks MQL5 Market validators look for.

Daily protection. RG_TodayClosedProfit sums today's closed result including swap and commission, optionally filtered by magic number; RG_DailyLossOK tells you whether the daily loss limit has been reached.

One-call gate. RG_CanTrade runs spread, session, daily loss, stops, margin and order-limit checks in one call and fills a reason string such as "OK" or the exact cause of refusal, ideal for logging and on-chart status.

Housekeeping. RG_Version returns the library version so your EA can log it.

How to use it

1. After purchase, copy RiskGuardLib.ex5 into your terminal's MQL5\Libraries folder.
2. In your EA or script, declare the functions you need inside an #import "RiskGuardLib.ex5" ... #import block (the signatures are listed below).
3. Call them like any other function, for example: lots = RG_LotsByRiskPercent(_Symbol, 1.0, 0); then if(RG_CanTrade(_Symbol, true, lots, sl, tp, 30, 7, 20, 3.0, magic, reason)) send your order, otherwise Print(reason).
4. Compile your EA. That is all - no DLL, no file access, no extra resources.

Function signatures

string RG_Version()
double RG_NormalizeLots(string symbol, double lots)
double RG_MoneyPerLot(string symbol, double priceDistance)
double RG_LotsByRiskPercent(string symbol, double riskPercent, double slDistance)
double RG_LotsByRiskMoney(string symbol, double riskMoney, double slDistance)
double RG_ATR(string symbol, ENUM_TIMEFRAMES tf, int period, int shift)
double RG_ATRStopPrice(string symbol, bool isBuy, double entry, ENUM_TIMEFRAMES tf, int period, double mult)
int RG_SpreadPoints(string symbol)
bool RG_SpreadOK(string symbol, int maxPoints)
bool RG_InSession(int startHour, int endHour)
bool RG_StopsValid(string symbol, bool isBuy, double price, double sl, double tp)
bool RG_MarginOK(string symbol, bool isBuy, double lots)
bool RG_OrderLimitOK(string symbol, double lots)
double RG_TodayClosedProfit(long magic)
bool RG_DailyLossOK(double maxLossPercent, long magic)
bool RG_CanTrade(string symbol, bool isBuy, double lots, double sl, double tp, int maxSpread, int startHour, int endHour, double maxDailyLossPct, long magic, string &reason)

Parameter notes

riskPercent - percent of equity to risk per trade. riskMoney - fixed account-currency amount to risk. slDistance - stop distance in price units; 0 uses an automatic volatility stop. maxPoints / maxSpread - maximum spread in points, 0 disables the filter. startHour / endHour - server-time window; equal values mean always open. maxLossPercent / maxDailyLossPct - daily loss limit as a percent of balance, 0 disables it. magic - magic number filter, -1 counts every trade. reason - receives "OK" or the cause of refusal.

The screenshots show a small demonstration script built on the library that prints the computed stop, lot size and gate result on the chart without sending any order. Its settings are: risk percent (1.0), ATR timeframe (H1), ATR period (14), ATR stop multiplier (1.5), maximum spread (30 points), session start and end hour (0 / 24), maximum daily loss (3 percent) and magic filter (-1 = all).

Why developers like it

Fewer validation rejections, cleaner code, consistent risk across all your EAs, and a single place to improve when your rules change. Works with any symbol, any account currency and both hedging and netting accounts. Lightweight: no per-tick heavy work, no global state you need to manage.

Build safer robots faster - add RiskGuard to your toolbox today, and write to me if you want help wiring it into your project.

Другие продукты этого автора
Simple SMA Cross EA
AL MOOSAWI ABDULLAH JAFFER BAQER
• Please test the product in the Strategy Tester before purchasing to understand how it works. • If you face any issues, contact me via private message—I’m always available to help. • After purchase, send me a screenshot of your order to receive a   FREE EA   as a gift. Welcome to our collection of Expert Advisors! Each EA is available for just $80, a price set to help the entire trading community succeed. My mission is to provide affordable tools that make trading easier and more accessible t
Hope EA MT5
AL MOOSAWI ABDULLAH JAFFER BAQER
• Please test the product in the Strategy Tester before purchasing to understand how it works. • If you face any issues, contact me via private message—I’m always available to help. • After purchase, send me a screenshot of your order to receive a   FREE EA   as a gift.                                       Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to
Happy and Steady
AL MOOSAWI ABDULLAH JAFFER BAQER
Happiness in Forex Means Winning! What if we made your winnings "Steady Winnings!" This will make you happier! (Forex is risky, you may loose all your capital) We implemented a safe and reliable strategy, that proved itself since 2010 until today! It passed COVID 19 fluctuations without any issues! The idea behind the expert to to be a super scalping expert, attacking few pips at a time. This happens while using big lot size, thus insuring handsome profit. Expert entries are very selective, w
Safe and Steady Profits Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
Safety in Forex trading is the main concern of the traders! There is no use to trade today, and loose everything tomorrow! (Trading is risky, and there are no guarantees for winning)   Here comes the power of our expert! The idea behind it is safety to the investors fund, then comes the profit. Thus this expert wont be the expert that will double your account by xx fold. It will be the expert you can rely on for steady, hassle free profits. To do so, the targets pips are minimal to insure
Penny Collector EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Some users are very comfortable keeping their trades for ages, while other users are happy to get the least and leave :) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)   Check our other products which will be added to the market soon.
Penny Collector Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
5 (1)
Some users are very comfort 2 able keeping their trades for ages, while other users are happy to get the least and leave :) If you cannot wait on your trades, then this expert will be the best for you! The expert tries to enter trades on a high probability of success, and in most cases it do catch the right wave. If not , don't worry because the expert will deal with the situation by itself and will take the trades to profits! (Trading is risky, and there are no guarantees for winning) You
Drag Race Scalper
AL MOOSAWI ABDULLAH JAFFER BAQER
Scalping! What a thrill! Forex trading had been a source of income and thrill at the same time! (Forex is risky, you may loose all your capital) With our new Expert Advisor "Drag Race Scalper" , you will earn both. (Forex is risky, you may loose all your capital) We tried to use a safe, profitable, and fast formula and this is what we ended by! A drag racing scalper! (Forex is risky, you may loose all your capital) In this scalper you would expect few points per trade only. This expert is fo
Against The Surf EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Trading Forex has a million way! One of the innovative ways is to go against the surf! Here we fight the market and work out to get our bread and butter from it :) (Trading is risky, and you may loose!) From here began the idea! Fighting the market. The Expert uses a combination of : Hedging, Grid and trend strategies to operate. This operation allows it to arrive safely even if it worked against the surf! (Trading is risky, and you may loose!) Please find the 99.9% tick data back test res
Cent Collector
AL MOOSAWI ABDULLAH JAFFER BAQER
Cent Collector is the second Expert advisor of the "Collector" Series :) The first was Penny collector :  https://www.mql5.com/en/market/product/61215?source=Site +Profile+Seller And here is the second EA : Cent Collector Those Experts are designed for Scalpers who cannot wait for ages.. As soon as the Expert realizes the profit it cash out and leave. If things went wrong, the Expert will work on managing itself by averaging and will cash out as soon as it could. This version is called Cent
Yen Collector
AL MOOSAWI ABDULLAH JAFFER BAQER
Yen Collector is the Third Expert advisor of the "Collector" Series :) The first was Penny collector :  https://www.mql5.com/en/market/product/61215?source=Site +Profile+Seller The second one was Cent collector:  https://www.mql5.com/en/market/product/65344?source=Site +Profile+Seller And here is the third EA : Yen Collector Those Experts are designed for Scalpers who cannot wait for ages.. As soon as the Expert realizes the profit it cash out and leave. If things went wrong, the Expert will w
Super Hedge Fighter EA
AL MOOSAWI ABDULLAH JAFFER BAQER
5 (1)
**Очень важно: Пожалуйста, отрегулируйте настройку "Расстояние между ордерами". Уменьшите его для достижения оптимальных результатов, лучше всего в пределах от 2 до 10.** Торговля на рынке Forex и в условиях волатильных рынков может быть сложной и рискованной. Ни одна стратегия не будет работать идеально 100% времени! С нашим новым экспертным советником "Super Hedge Fighter EA" вы получите новый взгляд на рынок! Вам больше не придется бояться волатильности, так как она станет источником дохо
Market Master EA
AL MOOSAWI ABDULLAH JAFFER BAQER
2.5 (2)
Очень важно: Пожалуйста, отрегулируйте «Расстояние между ордерами»... Уменьшите его для получения хороших результатов. Большие значения сделают советник гораздо безопаснее. Торговля на Форекс имеет миллион способов! Один из инновационных методов — это идти против течения! Здесь мы боремся с рынком и стараемся заработать на нём свой хлеб с маслом :) (Торговля — это риск, и вы можете потерять деньги!) Идея пришла отсюда! Борьба с рынком. Советник использует комбинацию: хеджирования, сеточной и тре
Magnet Scalper Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
In this EA you will have two sources of income: 1- Direct trades 2- Rebates from your broker. Thus insure to register under an IB that shares with you their revenues Scalping! What a thrill! Forex trading had been a source of income and thrill at the same time! (Forex is risky, you may loose all your capital) With our new Expert Advisor "Magnet Scalper Pro" , you will earn both. (Forex is risky, you may loose all your capital) We tried to use a safe, profitable, and fast formula and this i
Speedy EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Trading using Experts are the best ways to win in Forex! Here are our second Expert Advisor, where you can Set and forget! Time frame: M1 All currency Pairs will work perfectly on the EA Account type: All (If hedging is not allowed, please disable either Sell or Buy) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)   Check our other pro
Diamond EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Minimum deposit is 1000$ , or 1000 Cent = 10$. (Recommended 1500$) Every 1000$ = 0.01 Lot. Please stick to the rules, as we want you to win, win and win! (Trading is risky, and there are no guarantees for winning)                                         Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell
Impala EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Minimum deposit is 1000$ , or 1000 Cent = 10$. (Recommended 1500$) Every 1000$ = 0.01 Lot. Please stick to the rules, as we want you to win, win and win! (Trading is risky, and there are no guarantees for winning)                                         Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell f
EX Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Fox EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)
Good Mood Trading EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Hope EA MT4
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Moderate EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
More Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Nu Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Shooting Star EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Tiger EA MT4
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Treasure EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
LevelGuard Smart SMA EA
AL MOOSAWI ABDULLAH JAFFER BAQER
LevelGuard SmartSMA Master Support & Resistance Trading with Precision LevelGuard SmartSMA leverages the power of moving averages to help you trade confidently across markets. Designed to identify dynamic support and resistance levels, this EA delivers precise trade entries and exits, empowering traders to capitalize on market movements with ease. How It Works Core Strategy: Uses a central SMA (e.g., 50 or 200-period) as a dynamic support or resistance line. Additional SMAs (optional) provide s
Basic SMA Price Cross EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Explore Our Full EA Collection Visit our website for an extensive range of expertly crafted Expert Advisors designed to empower traders of all levels. Whether you're new to trading or a seasoned professional, our tools are tailored to meet your needs. Affordable Trading for Everyone We believe in making trading accessible to everyone. That’s why all our Expert Advisors are priced at just $65 each, helping our community achieve success without breaking the bank. Unlock the Power of Automation Th
Lion’s Roar - Trend Strength Indicator Are you ready to take control of your trading journey? The Lion’s Roar - Trend Strength Indicator is here to help you identify and harness powerful market trends with precision and confidence. Designed with traders in mind, this advanced tool is built on a robust strategy that combines trend direction with momentum validation using the Average True Range (ATR). This indicator is not pre-optimized, giving YOU the freedom to tailor it to your unique trading
Unleash Market Volatility with the Titan Force Indicator! Are you ready to dominate the market by capitalizing on volatility? The Titan Force Indicator is your ultimate trading tool, designed for traders who thrive during periods of heightened market activity. Not Optimized for You – Yet! This indicator is a canvas for your creativity. It's been crafted to let you optimize it according to your unique trading strategies and preferences. Your skills, your edge! How Does the Titan Force Indicator
Фильтр:
Нет отзывов
Ответ на отзыв