How to add custom position-based metrics to your trading system
Updated on 2011-07-30 04:19:18
|
After you backtest or optimize a trading system and in the simulation report form, you can display the complete list of trades/positions taken (long/short) by the simulation by selecting "Trades" tab (Next to "Statistics"). Several fields are already defined: Symbol, Trade Type, Entry date, Exit date, Performance, Number of bars held, MAE (Maximum Adverse Excursion), MFE (Maximum Favorable Excursion), Scale-in, Scale-out, Exit type...
Using the money management tool, you can add custom metrics to this "Trades" table. You can for example display the relative strength value of the stock on signal date, or the average distance between the stock price and its moving average during the holding period.
Steps:
- Select a trading system then click on "Update"
- In trading system editor, select "Money Management" tab then click on "Add a New Money Management Script"
- Click on "Update Script" to open the money management editor
- Select "OnClosePosition" event
- Type the following script:
MMExitPosition pos = Functions.GetPositionDetails();
TimeSeries rsi = Data.ParseFormula("a = rsi(14);").GetTimeSeries(pos.Symbol, "a");
Functions.AddTradeMetric("RSI", rsi[pos.BarsSinceEntry]);
The script will be executed each time a new position is about to be closed.
Line 1: Gets position details
Line 2: Calculates the RSI time-series for the position's symbol
Line 3: Gets the RSI value on signal date and adds it as a new metric
Note that that "rsi[0]" references the current bar RSI value while "rsi[pos.BarsSinceEntry]" references the RSI value N bars ago where N = pos.BarsSinceEntry.
|