ATS Risk Library: Advanced Lot Sizing and Trading Guards
Info
The ATS Risk Library: Advanced Lot Sizing and Trading Guards is a Library for MetaTrader 5 that ats risk library is a single include file, ats_risklib. mqh, containing five classes.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use ATS Risk Library: Advanced Lot Sizing and Trading Guards
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
ATS Risk Library is a single include file, ATS_RiskLib.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: calculate lot size based on risk percentage - another powerful library for MetaTrader 5 traders.
ATS Risk Library is a single include file, ATS_RiskLib.mqh, containing five classes. You integrate these classes into your Expert Advisor (EA); the library itself does not open, modify, or close trades.Also recommended: asq risk analytics engine: comprehensive risk assessment for trading strategies - similar library with strong performance on MetaTrader 5.
The Classes
CAtsSizer - Lot size calculation based on stop distance
Supported Modes: Fixed lot size, Percentage of balance, Percentage of equity, Fixed monetary amount.
This class ensures the lot size is floored to the volume step. It strictly avoids rounding up. If the calculated risk results in a lot size smaller than the broker's minimum lot, the Lots() function returns 0.0, and LastReason() will explain why. Rounding up to the minimum lot is a common practice that can lead to an EA risking more than the intended percentage on smaller accounts.
Includes optional lot capping and a free margin check (OrderCalcMargin).
CAtsDayGuard - Daily trading limits
Features: Daily loss limit as a percentage of the day-start balance and/or a fixed monetary amount (whichever is more restrictive is applied), an optional daily profit target, and a maximum number of trades per day.
Configuration: You can specify the server hour at which a new trading day begins and whether open profit/loss should be included in the daily calculation.
Persistence: Day-start balance and lock levels are saved using GlobalVariables, ensuring that restarting the terminal mid-day does not reset these limits.
Status Indicators: Remaining(), Used(), and Level() (indicating OK, WARNING, or LIMIT REACHED) are available for displaying on a panel.
CAtsDrawdownGuard - Maximum overall loss management
Modes: Static (loss calculated from the initial balance), Trailing on equity, or Trailing on balance.
Options: Includes an option to
You may also like: kelly-va p s risk engine for metatrader - excellent alternative for library users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include "ATS_RiskLib.mqh"
int g_pass = 0;
int g_fail = 0;
void Check(const string name, const bool condition)
{
if(condition)
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.