Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

ASQ Risk Analytics Engine - library for MetaTrader 5

Emmanuel Nana Nana
Published by:
Muharrem Rogova
Views:
176
Rating:
(2)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This is what quant desks run after every trading session — and now it's free. ASQ Risk Analytics gives your EA Monte Carlo simulations, Value at Risk, Kelly Criterion position sizing, and 12+ risk-adjusted performance metrics. Feed it your trade history and it tells you exactly how risky your system is, how much to risk per trade, and whether you should keep trading at all.

Architecture


ANALYSIS MODULES:
- Monte Carlo simulation — 1,000 to 10,000 bootstrap runs. Expected return, expected max drawdown, probability of ruin, and 95% confidence intervals for both return and drawdown
- Value at Risk (VaR) — Historical VaR at 95% and 99% confidence. Expected Shortfall (CVaR) at both levels. Daily, weekly, and monthly VaR scaling
- Position sizing — 7 methods: Fixed, Percent Risk, Kelly Criterion (full), Half Kelly (recommended), Optimal F, ATR-Based, VaR-Constrained. All normalized to broker lot limits
- Risk-adjusted ratios — Sharpe, Sortino, Calmar, Sterling, System Quality Number (SQN), Ulcer Index, Ulcer Performance Index, Recovery Factor, Payoff Ratio, K-Ratio
- Performance metrics — Win rate, profit factor, expectancy ($), expectancy (R), max consecutive wins/losses, total return, annualized return
- Risk assessment — 6-level risk classification (Minimal to Extreme), risk score 0-100, trading recommendation engine, probability of ruin at configurable thresholds, consecutive loss probability calculator

CONVENIENCE:
- LoadFromAccount() — one call loads all closed trades from account history. No manual loop needed. Symbol filter and max trades supported.

DEMO SCRIPT INCLUDED:
Drag onto any chart — reads your account history and generates a full institutional risk report in the Experts log:
— Performance summary (trades, win rate, PF, expectancy, return)
— Risk ratios (Sharpe, Sortino, Calmar, SQN, Ulcer, Recovery Factor)
— Monte Carlo results (expected return, expected DD, P(ruin), 95% CI)
— VaR/CVaR at 95% and 99%
— Position sizing comparison (Kelly, Half Kelly, Optimal F, VaR-constrained)
— Consecutive loss probabilities (3 through 10 in a row)
— Risk of ruin at 10/20/30/50% drawdown thresholds
— Final assessment with trading recommendation
USAGE:
#include "ASQ_RiskAnalytics.mqh"
CASQRiskAnalytics risk;
risk.Initialize(_Symbol, pipValue);
risk.LoadFromAccount();              // Load all closed trades
risk.Calculate();                     // Run everything
Print(risk.ExportAnalytics());        // Full report
risk.CalculatePositionSize(balance, stopPips);
double lot = risk.GetHalfKellyLot(); // Recommended sizing

Place both files in the same folder — compiles instantly, no subfolder setup needed.

This is the open-source risk engine behind Quant Cristina on the MQL5 Market. Same math, same accuracy — the Market version adds the premium multi-strategy trading framework and on-chart dashboard.

FILES:
- ASQ_RiskAnalytics.mqh — Library (915 lines)
- ASQ_RiskAnalytics_Demo.mq5 — Demo script (136 lines)

MetaTrader 5, all brokers, all instruments, all timeframes.
Free and open-source. 1,051 lines of production MQL5.
Zero external dependencies. Pure MQL5 mathematics.

AlgoSphere Quant — Precision before profit.
https://www.mql5.com/en/users/robin2.0
ASQ Indicator Manager ASQ Indicator Manager

Centralized indicator handle management library for MetaTrader 5 EAs.

Pivot point Pivot point

Line to change direction

ASQ Trade Frequency Controller ASQ Trade Frequency Controller

Runtime trade frequency adjustment library for MetaTrader 5.

ASQ Telegram Notifier ASQ Telegram Notifier

Professional Telegram integration library for MetaTrader 5 EAs.