Loading…

Equity Curve Statistics

Two equity curves can post the exact same total return and still be completely different things to trade with - one climbs steadily, the other sits flat for weeks and then jumps on one outlier period. TotalReturnPct and CAGR cannot tell them apart, because both are end-point measures that do not look at the path in between. EquityLinearityR2 does. It runs a linear regression of the equity curve against sample index and reports the R-squared - 1.0 for a perfectly straight line, well below that for anything lumpy. It is the single most useful number in this header for comparing two curves with similar headline returns, and it is the reason this header exists rather than just exposing MeanOf and StdDevOf on their own. This header deliberately does not compute drawdown or Sharpe/Sortino - those live in the companion DrawdownCalc and RiskRatios libraries in this same catalogue, in more depth than a shared header could manage without duplicating logic three times over. What is here is the return series itself and the shape statistics that come directly from it: periodic returns, mean and standard deviation, annualised volatility, CAGR, a return-based profit factor, and the longest winning/losing streaks. Every function takes a plain array of equity SAMPLES in chronological order - balance or equity at the close of each period, whatever interval the caller chose. The annualising functions (CagrPct, AnnualizedVolatilityPct) take the sampling frequency as an explicit parameter rather than assuming daily bars, because assuming wrong there produces a number that is off by a scaling factor and still looks entirely plausible - the kind of bug that survives because nothing about the output looks broken. Self-contained: no dependencies beyond the standard library, no DLLs. Notes and limitations - StdDevOf is a POPULATION standard deviation (divides by n, not n-1). The full equity history is treated as the complete record being described, not a sample drawn from a larger unknown population. - AnnualizedVolatilityPct uses the square-root-of-time convention, which assumes returns are roughly independent period to period. A strategy with strong serial correlation - grid or martingale styles especially - understates its true risk under this measure. - ProfitFactorFromReturns returns a large sentinel value (999999.0), not infinity, when there are gains and no losing periods at all. Treat any value at or near that sentinel as "no losses yet observed", not as a precise ratio. - CagrPct and AnnualizedVolatilityPct both require the caller to state the correct periodsPerYear. Passing the wrong frequency does not error - it silently scales the result, so double check the sampling interval matches what was actually used to build the array. - No drawdown, Sharpe or Sortino here by design - see DrawdownCalc and RiskRatios in this catalogue. - No thread or state concerns: every function is pure and operates only on the arrays passed in. - No money-per-point or contract-size calculation appears anywhere in this header - it is pure return-series arithmetic on whatever units the caller's array is already in, so the tick-value/contract-size scaling this catalogue's house style calls out for money calculations does not apply.

Script · MT5 · v1.0 · Free

About Equity Curve Statistics

Equity Curve Statistics is a script for MetaTrader 5. It has 1 setting, such as Periods per year. MQL source code included.

Files in the download: EquityStats.mq5.mqh, EquityStats.txt, EquityStatsDemo.ex5, EquityStatsDemo.mq5.

Settings

SettingDefaultWhat it does
Periods per year252.0Samples per year implied by the curve (252 = daily, trading days)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria