Optimal F for MQL5 (after Ralph Vince) - MetaTrader 5 library
I could not find the MQL5 code for the Kelly criterion, so I decided to write it myself; but it turned out that the Kelly criterion only applies to the Bernoulli distribution. This means it only works with fixed profits and losses, i.e. fixed stops and take profits, but I rarely do this.
Therefore, based on the work of Ralph Vince's book "Mathematics of Money Management" and borrowing concepts from Python codes I found online, I created this MQL5 library for Optimal f.
I've included tests to verify that my code gives the same results as the examples in Ralph Vince's book. That is: +9, +18, +7, +1, +10, -5, -3, -17, -7 .
NOTE: I set GEOM_MEAN_MIN_TRADES = 0 to run unit tests.
NOTE: This only calculates the best f. It does not show how position size is calculated. This is partly up to you.
NOTE: This code is for testing and inspiration only. Please understand the math before using this feature on a live trading account! If you don't know what you are doing, your account will most likely be wiped out.
Attachment download
📎 test_-_optimalf.mq5 (1.82 KB)
📎clsoptimalf.mqh (4.05 KB)
Source: MQL5 #19326
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •