Trade Mode, Phantom Trades, Equity Curve Trading

Phantom trades are "what-if" trades that are not sent to the broker. Instead the win or loss of a phantom trade is calculated from the price curve and the current slippage and trading costs. It is recorded in the Short/Long statistics, but not in the Total statistics. This way the performances of phantom and real trades can be evaluated separately. Phantom trades are used for equity curve trading or for Virtual Hedging.

Equity curve trading is a method of limiting losses by skipping unfavorable market periods. The strategy monitors the equity curves of any component of a portfolio strategy. When unusual losses are recognized, real trading with that component is suspended. For detecting whether it's worth to resume trading, the subsequent trades are then entered in phantom mode until their returns indicate that the market is getting profitable again. In this way the strategy switches in and out of phantom mode dependent on the market situation.

Several methods can be used for determining if the market it profitable or not. In the example below, the equity curve is permanently compared with its own long-term average by lowpass filtering. It the equity is below average and still falling, trading switches to phantom mode; it goes back to normal as soon as the equity curve is rising again. Other methods may be based on the balance instead of the equity curve, or on the ratio of winning to losing trades.

Equity curve trading does not improve the performance when there is no clear distinction between profitable and unprofitable market periods or when the strategy filters unprofitable periods anyway. But it can often improve the perception of a live trading system, and can prevent losses by expiration of market inefficiencies. An example of a system that suddenly became unprofitable is the 'Luxor' strategy in the script examples; here equity curve trading would have saved the day by stopping trading in December 2011.

Phantom trades and the overall trade behavior can be controlled with the following variable:


Determines with the flags listed below how trades are placed. Use setf and resf for setting and resetting flags.


TR_PHANTOM Enter trades in phantom mode. The trades are simulated and not sent to the broker API.
TR_BSTOP Enter trades as bracket orders with a stop loss at distance Stop*StopFactor on NFA accounts, if supported by the broker API (see remarks). 
TR_GTC Enter trades in GTC (good-till-cancelled) mode, if supported by the broker API. Keeps the order active until filled or cancelled by the broker.
TR_AON Enter trades in AON (all-or-nothing) mode, if supported by the broker API.
TR_POS Check the position before exiting trades, and cancel the trade when the position was zero. GET_POSITION must be supported.
TR_FILLED Treat the trade as completely filled when the trade status is unavailable by the API.
TR_FRC Do not round stops and limits to the PIP value; for broker APIs that support any limit value.




Example (equity curve trading):

// don't trade when the equity curve goes down
// and is below its own lowpass filtered value
function checkEquity()
// generate equity curve including phantom trades
  vars EquityCurve = series(EquityLong+EquityShort);
  vars EquityLP = series(LowPass(EquityCurve,10));
  if(EquityLP[0] < LowPass(EquityLP,100) && falling(EquityLP))
    setf(TradeMode,TR_PHANTOM); // drawdown -> phantom trades
    resf(TradeMode,TR_PHANTOM); // profitable -> normal trades

See also:

NFA, Hedge, Fill, broker arbitrage, setf, resf
► latest version online