Click here to Login




How to add custom position-based metrics to your trading system

Updated on 2011-07-30





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.










no comments (Log in)

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.