Trade statistics

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.
 

WinLong

WinShort

WinTotal

Sum of profits of all trades won so far. When using oversampling or phantom trades, WinLong or WinShort can be higher than WinTotal

PipsTotal

Profit of all won trades minus loss of all lost trades, in volume neutral PIP units. For converting a component profit to a profit in average PIP units, multiply it with PipsTotal/(WinTotal-LossTotal).

LossLong

LossShort

LossTotal

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. The current profit factor, clipped at 10, is ifelse(LossTotal > 0,WinTotal/LossTotal,10).

LossGlobal

Sum of losses by all trades of all Zorro instances that have set the ScholzBrake and are trading real accounts on the same PC. This variable is only available in [Trade] mode. It is increased by any loss, and updated to the other Zorro instances once per bar and on any trade.

WinValLong

WinValShort

WinValTotal

Open profit of all currently winning trades.

LossValLong

LossValShort

LossValTotal

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.

PipsValTotal

Open profit of all open trades in volume neutral PIP units. For converting a component open profit to a profit in average PIP units, multiply it with PipsValTotal/(WinValTotal-LossValTotal)

ProfitClosed

Realized component profit so far; WinLong-LossLong+WinShort-LossShort.

ProfitOpen

Unrealized component profit so far; WinValLong-LossValLong+WinValShort-LossValShort.

ProfitTotal

Realized and unrealized total profit so far; WinTotal-LossTotal+WinValTotal-LossValTotal.

BalanceLong

BalanceShort

Sum of returns of all closed trades of the current component; WinLong-LossLong or WinShort-LossShort.

EquityLong

EquityShort

Sum of returns of all closed, plus value of all open trades of the current component; BalanceLong+WinValLong-LossValLong or BalanceShort+WinValShort-LossValShort.

WinMaxLong

WinMaxShort

WinMaxTotal

Maximum profit of a trade so far.

LossMaxLong

LossMaxShort

LossMaxTotal

Maximum loss of a trade so far.

NumWinLong

NumWinShort

NumWinTotal

Number of profitable trades so far. The average return per winning trade is WinTotal/NumWinTotal.

NumLossLong

NumLossShort

NumLossTotal

Number of lost trades so far. The average return per trade is (WinTotal-LossTotal)/(NumWinTotal+NumLossTotal). The number of closed trades is NumWinTotal+NumLossTotal.

LossStreakLong

LossStreakShort

LossStreakTotal

Current number of losses in a row, or 0 if the last trade was a winner. Can be reset by script.

WinStreakLong

WinStreakShort

WinStreakTotal

Current number of wins in a row, or 0 if the last trade was lost. Can be reset by script.

LossStreakValLong

LossStreakValShort

LossStreakValTotal

Accumulated loss of the current loss streak, or 0 if the last trade was a winner.

WinStreakValLong

WinStreakValShort

WinStreakValTotal

Accumulated profit of the current win streak, or 0 if the last trade was lost.

NumWinningLong

NumWinningShort

Number of currently open winning trades with the current asset and algorithm, including phantom trades.

NumLosingLong

NumLosingShort

Number of currently open losing trades with the current asset and algorithm, including phantom trades.

NumOpenLong

NumOpenShort

Number of currently open trades with the current asset and algorithm, including phantom trades.

NumLongTotal

NumShortTotal

NumOpenTotal

NumOpenPhantom

Numbers of currently open trades with all assets and algorithms.

NumPendingLong

NumPendingShort

NumPendingTotal

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.

NumRejected

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.

LotsPool

LotsVirtual

LotsPhantom

Open position of the current asset, positive when long and negative when short. The variables hold the difference of long and short open lots of real trades (LotsPool), virtual trades in virtual hedging mode (LotsVirtual), and phantom trades (LotsPhantom). Only for the underlying, not for positions of options and combos. Open account positions can be read from the broker API with the GET_POSITION command, 

 

Type:

int for numbers that count something, otherwise var.

Remarks:

Example:

// suspend trading after 4 losses in a row
if(LossStreakShort >= 4 || LossStreakLong >= 4)
  setf(TradeMode,TR_PHANTOM); // phantom trades
else   resf(TradeMode,TR_PHANTOM); // normal trading

See also:

Trade parameters, Balance, Lots, for(trades), strategy statistics, performance report, results

 

► latest version online