# Strategy statistics

The following system variables can be evaluated after the end of a simulation in the objective or the evaluate function. There is another set of trade statistics that can also be evaluated during the simulation. These variables allow designing custom 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.
## 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.
## MarginMax

Maximum margin sum of open trades during the simulation period, in account currency units.
## 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.
## SpreadCost

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

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

Total win or loss by rollover interest during the simulation period, in account currency units.
## CommissionCost

Total loss by commissions
during the simulation period, in account currency units.
## 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.
## ReturnStdDev

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

Ulcer Index in percent; average drawdown divided by peak equity.
## R2

R2 coefficient; the similarity of the equity curve with a straight line ending up at the same profit.

## DrawDownBars

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

Maximum length of a drawdown in bars.
## LossStreakMax

Maximum number of losses in a row.
## NumOpenMax

Maximum number of simultaneously open trades.
## InMarketBars

Total number of bars with open trades.
## InMarketSum

Sum of the durations of all trades, in bars. 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, set at the end of the simulation period.

## Results

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)Results[Bar]** is the end result.
### 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 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, including phantom trades.
- 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
**Results** or **ResultsDaily** arrays.
- All statistics are reset when the strategy is restarted. For preventing this, they could be copied into global variables or saved in a file that is loaded at start of the strategy.

### 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 * 252/Day);
printf(TO_REPORT,"\nMy Sharpe: %.2f",MySharpe);
}

### See also:

Trade statistics, for(trades), NumBars, performance report

► latest version online