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.
Sum of profits of all trades won so far. When oversampling or phantom trades are used, WinLong or WinShort can be higher than WinTotal.
Pips of all won trades minus pips of all lost trades, volume neutral.
Sum of losses by all trades lost so far. The accumulated balance, i.e. the return of all closed trades is WinTotal - LossTotal. WinTotal or LossTotal can be modified by script for simulating additional wins or losses
in the backtest.
Open profit of all currently winning trades.
Open loss amount of all currently losing trades. The accumulated equity, i.e. the current profit of all open and closed trades is WinTotal - LossTotal + WinValTotal - LossValTotal.
Realized component profit so far; WinLong-LossLong+WinShort-LossShort.
Unrealized component profit so far; WinValLong-LossValLong+WinValShort-LossValShort.
Sum of returns of all closed trades; WinLong-LossLong resp. WinShort-LossShort.
Sum of returns of all closed, plus value of all open trades; BalanceLong+WinValLong-LossValLong resp. BalanceShort+WinValShort-LossValShort.
Maximum profit of a trade so far.
Maximum loss of a trade so far.
Number of profitable trades so far. The average return per winning trade is WinTotal/NumWinTotal.
Number of lost trades so far. The average return per trade is (WinTotal-LossTotal)/(NumWinTotal+NumLossTotal).
Current number of losses in a row, or 0 if the last trade was a winner.
Current number of wins in a row, or 0 if the last trade was lost.
Accumulated loss of the current loss streak, or 0 if the last trade was a winner.
Accumulated profit of the current win streak, or 0 if the last trade was lost.
Number of currently open winning trades with the current asset and algorithm, including phantom trades.
Number of currently open losing trades with the current asset and algorithm, including phantom trades.
Number of currently open trades with the current asset and algorithm, including phantom trades.
Numbers of currently open trades with all assets and algorithms.
Number of currently pending trades, i.e. trades that have just been entered, or that have not yet reached their Entry Stop or Limit within their EntryTime period. NumPendingTotal includes pending phantom trades in Virtual Hedging mode, as they also trigger real trades.
Number of rejected open or close orders in live trading, due to lack or market liquidity, broker connection failure, market closures, holidays, or other reasons.
Open net lot sum of real trades and phantom trades for virtual hedging with the current asset. The net lot sum is the difference of long lots and short lots. LotsPool is also valid when no virtual hedging is used.
ResultLong .. ResultLong
ResultShort .. ResultShort
Arrays containing the last 20 trade results as difference between entry and exit prices. The  element contains the result of the most recent trade. Result/PIP gives the profit or loss of the trade in pips (disregarding the trade volume). These arrays can be used for equity curve trading.
int for numbers that count something, otherwise var.
- 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.
- 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.
- 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.
- Arbitrary metrics can be calculated by enumerating trades with for(open_trades) or for(all_trades) and summing up the desired value.
- Trade statistics are updated on every bar. They 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.
// suspend trading after 4 losses in a row
if(LossStreakShort >= 4 || LossStreakLong >= 4)
Lots = -1; // phantom trades
Lots = 1;
Trade parameters, Balance, Lots, for(trades), strategy statistics, performance report
► latest version online