The following system variables can be used to obtain trade statistics separately per asset, algorithm, and long/short trade direction. They can be evaluated in real time while trading, or at the end of a simulation cycle for calculating statistics in [Test] mode. All parameters are read/only. Most come in three flavors:

**...Long**: Results of all long trades with the current asset and algorithm. Including phantom trades, but not including pool trades.

**...Short**: Results of all short trades with the current asset and algorithm, including phantom trades, but no pool trades.

**...Total**: Results of all trades with all assets and algorithms, not including phantom trades.

In [Test] mode the **...Long** and **...Short** results are from the current sample cycle only, which allows to produce statistics distributions of sample cycles. If the ALLCYCLES flag is set, the **...Long** and **...Short** results are summed up from the all sample cycles. The **...Total** results are always summed up.

A set of overall strategy statistics is available after the end of a simulation, and can be evaluated in the objective or the evaluate function.
For calculating various statistics of the last N trades, use the
results function.

- The parameters are part of the
**GLOBALS**struct and the**STATUS**structs. They are defined in**include\variables.h**. - The parameters are only affected by trades opened with the current Zorro instance. Trades opened manually or with other platforms on the same account do not affect the trade statistics parameters.
- The parameters are updated once per bar. Therefore they can be inaccurate when trades are opened or closed immediately before reading the variables, but are correct again at the next bar.
- Every algo and asset call changes the component-dependent
**...Long**and**...Short**statistics variables. They are set to the statistics of the selected asset and algorithm identifier. The**...Total**statistics variables are unaffected by algo and asset calls. - In a TMF or trade loop,
the asset is automatically set to the asset of the trade, but the algo is
not. For evaluating component-dependent statistics of a trade, select the
trade algo by
**algo(TradeAlgo);**(even when no different algos are used). - If a backtest or training runs over several bar cycles, the
**...Long**and**...Short**statistics variables are taken from the last bar cycle, while the**...Total**statistics variables are taken from the average of all bar cycles. - Win/loss metrics can be calculated from the above parameters. For
instance,
**AvgWin = WinValTotal/WinTotal; AvgLoss = LossValTotal/LossTotal; WinRate = WinTotal/(var)LossTotal**(check divisors for zero!). Trade-dependent metrics can be calculated by enumerating trades with for(open_trades) or for(all_trades), or with the results function. Asset-dependent metrics can be calculated with a for(assets) loop that enumerates all assets used in the system. - Trade statistics are reset when the
strategy is restarted. For preventing this, store them at the end of a live session and resume
them in
the next session with
**setf(SaveMode,SV_STATS)**.

// suspend trading after 4 losses in a rowif(LossStreakShort >= 4 || LossStreakLong >= 4)

setf(TradeMode,TR_PHANTOM);// phantom trades

else resf(TradeMode,TR_PHANTOM);// normal trading

► latest version online