Code Library / Risk Management
MQL4 Kelly Criterion Sizing
Kelly Criterion lot sizing based on win rate and R:R ratio.
Language: MQL4 · Category: Risk Management · Tags: Kelly criterion, position sizing, MQL4, optimal, statistics
Source code
double Kelly(double winRate,double avgWin,double avgLoss) {
if(avgLoss==0) return 0;
double R=avgWin/MathAbs(avgLoss);
return MathMax(0,winRate-(1-winRate)/R);
}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL4 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.