- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- EURUSD - Trends, Forecasts and Implications (Part 1)
- Optimizing sortino ratio in OnTester() using genetic algorithms?
create an equity indicator
It's not so easy. We need to ask OP how he would like to calculate equity: per tick -> per second -> per bar -- in the order of lowering accuracy. Indicator will definitely show equity per bars.
Not to mention that there can be a multi-symbol trading strategy which implies more difficulties.
It's not so easy. We need to ask OP how he would like to calculate equity: per tick -> per second -> per bar -- in the order of lowering accuracy. Indicator will definitely show equity per bars.
Not to mention that there can be a multi-symbol trading strategy which implies more difficulties.
Hi, Im trying to gather Equity per trade, something like equity drawing during testing, my idea is:
In OnTrade()
1) catch deal in / deal out
2) store current equity in buffer
When test passed, then calculate differences and for them: %return and stdev.
Hi, Im trying to gather Equity per trade, something like equity drawing during testing, my idea is:
In OnTrade()
1) catch deal in / deal out
2) store current equity in buffer
When test passed, then calculate differences and for them: %return and stdev.
This is not accurate calculation of equity - you don't catch possible big price movements during existence of your positions, which is essential for Sortino, not to mention that stopouts can be easily overlooked.
This is not accurate calculation of equity - you don't catch possible big price movements during existence of your positions, which is essential for Sortino, not to mention that stopouts can be easily overlooked.

- www.mql5.com
Yes, I agree, it looks I should sample equity at least by bar or minites/second.
input group "Optimisation" sinput bool fixedRiskOptimisation = true; bool isTester = false; double returnsCurve[], startEquity, lastEquity; int returnsCurveSize = 0; // Track size of returnsCurve to avoid ArraySize() calls int returnsCurveCapacity = 1000; // Pre-allocated capacity int dayCount = 0; //+------------------------------------------------------------------+ //| Optimized update return curve function | //+------------------------------------------------------------------+ void updateReturnCurve() { // Check if we need to resize the array if(returnsCurveSize >= returnsCurveCapacity) { // Double the capacity for efficient growth (amortized constant time) returnsCurveCapacity *= 2; ArrayResize(returnsCurve, returnsCurveCapacity); } double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY); if(returnsCurveSize == 0) { lastEquity = startEquity; } // Add the new value to the array returnsCurve[returnsCurveSize] = fixedRiskOptimisation && isTester ? currentEquity : // Equity Curve MathLog(currentEquity); // Returns Curve // Increment size counter returnsCurveSize++; // Update lastEquity for next calculation lastEquity = currentEquity; }
Then in OnTesterInit do isTester = true;
This gives you updateReturnCurve() to call as frequently as you want to record either Equity if(
fixedRiskOptimisation && isTester
) when your ideal equity curve is exponential rise (ie with dynamic position sizing in live trading, determined in your volume calculation according to
fixedRiskOptimisation
) but you want a straight line for calculation of eg R2 in Tester
or
log(equity) to enable trading with dynamic volume but a straight line returns curve eg for calculation of R2 in live trading.
The curve is, of course, represented by returnsCurve[] - my naming reflects the development of this which is a small portion of my optimisation include file

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use