# Strategy performance statistics

The following system variables can be evaluated in the
objective
or evaluate function. Some become available only at the end of a simulation
or a live trading session, others are updated at any bar during
the test or session. There is also a set of trade statistics that can be evaluated during the
backtest. The statistics variables can be used for calculating individual performance metrics and printing them to the performance report.

## DrawDownMax

Maximum drawdown, the largest difference between a balance peak and the lowest subsequent equity valley
during the simulation period, in account currency units.
Updated at any bar.
## MAE

Maximum adverse excursion, the largest difference between an equity peak and the lowest subsequent equity valley during the simulation period, in account currency units.
Updated at any bar.
## AEDepth

Current adverse excursion, the difference between the last equity peak and the
current equity value, in account currency units. Updated at any bar.
## MarginMax

Maximum margin sum of open trades during the simulation period, in account currency units.
Updated at any trade.
## RiskMax

Maximum possible loss sum of all open trades during the simulation period, in account currency units.
The possible loss is calculated by the stop loss distance of a trade, or estimated at 10% of the price if no stop loss was used.
Updated at any trade.
## SpreadCost

Total loss by bid-ask spreads
during the simulation period, in account currency units.
Updated at any trade.
## SlippageCost

Total win or loss by simulated slippage during the simulation period, in account currency units.
Updated at any trade.
## RollCost

Total win or loss by rollover and margin interest during the simulation period, in account currency units.
Updated at any trade.
## CommissionCost

Total loss by commissions
during the simulation period, in account currency units.
Updated at any trade.
## ReturnMean

Mean of all bar returns on investment. The bar return on investment is the equity difference to the previous bar, divided by Capital. If **Capital** is not set, the sum of normalized
maximum drawdown and maximum margin is used.
Only available at the end.
## ReturnStdDev

Standard deviation of all bar returns on investment. Can be used together with **ReturnMean** for calculating the annualized Sharpe Ratio and other metrics.Only
available at the end.
## ReturnUlcer

Ulcer Index in percent; average drawdown divided by peak equity.Only available
at the end.
## ReturnR2

R2 coefficient; the similarity of the equity curve with a straight line ending up at the same profit.Only
available at the end.
## ReturnLR

Gross profit by linear regression of the equity curve. Only available at the
end.

## ReturnCBI

The last CBI value based on previously stored backtest
data.Only available at the end.

## DrawDownBars

Total number of bars spent in drawdown, updated at any bar. For the percentage spent in drawdown, divide by the duration of the test, **(Bar-StartBar)**.
## DrawDownBarsMax

Maximum length of a drawdown in bars.
Only available at the end.
## LossStreakMax

Maximum number of losses in a row.
Only available at the end.
## NumOpenMax

Maximum number of simultaneously open trades.
Updated at any bar.
## InMarketBars

Total number of bars with open trades.
Updated at any bar.
## InMarketSum

Sum of the durations of all trades, in bars. Updated at any trade. Can be bigger than the duration of the test when several positions are simultaneously open.
### Type:

**int** for numbers that count something, otherwise** var**. Read/only.

## ResultsAtBar

Array in chronological order containing the sums of wins and losses of all open and closed trades at every bar, in account currency units. **(var)ResultsAtBar[Bar]** is the result
at end of the simulation. Only available at the end.
### Type:

**float*** pointer, or **0** when no results were calculated.

## ResultsDaily

Array in chronological order containing the balance or equity (dependent on the BALANCE flag) at the end of every day, in account currency units. **ResultsDaily[Day]** is the end result. This array is
only available at the end and automatically saved to
a **.dbl** file for the CBI calculation,
and to a **.csv** file for further evaluation.
### Type:

**var*** pointer, or **0** when no daily results were calculated.

### Remarks:

- In [Train] mode the parameters are based on trades with 1 lot
and include phantom trades, unless set up otherwise with
TrainMode.
- More statistics parameters can be retrieved from the
win/loss statistics at the end of the simulation.
- Trade dependent metrics can be calculated by enumerating all trades of the simulation with a
for(all_trades) loop, and summing up the desired
trade parameters. Equity curve dependent metrics can be calculated from the
**ResultsAtBar** or **ResultsDaily** arrays.
- All statistics variables are normally reset when the strategy is restarted
or a new session is started. If the SAV_STATS
flag is set, statistics is continued from the previous session.

### Example:

*// print the annualized Sharpe Ratio to the performance report*
function evaluate()
{
if(NumWinTotal == 0) return;
var MySharpe = ReturnMean/ReturnStdDev;
*// roughly adjust to annual in-market bars*
MySharpe *= sqrt(InMarketBars/NumYears);
printf(TO_REPORT,"\nMy Sharpe: %.2f",MySharpe);
}

### See also:

Trade statistics, Cold Blood Index, for(trades), NumBars, performance report
► latest version online