Please check first this Trading System Tools page for a global overview insight of Investor/RT backtesting features.
Introduction
A trading system is composed of one or more trading rules. Each trading rule is in turn composed of a trading signal and an associated action such as buy, sell, sell short, etc. Trading signals are logical expressions (true or false statements) written in the Investor/RT Language (RTL). RTL is the language used to compose custom indicators and trading signals in Investor/RT. A trading system can be applied to a single symbol or a set of instruments listed inside a Quotepage
The Trading System Builder Interface
A trading rule is composed of (minimum) 4 components (highlighted in solid blue rectangle) : a trading signal, a corresponding action, together with an indication of the associated Rule quantity and Rule Price. The Rule Marker is optional (see more below). The middle section of the Trading System Builder window is used for this purpose. A list of available trading signals appears on the left. Moving right, several actions are listed that can be associated with a particular signal to form a rule. To the right of the actions are window controls for specifying the quantity (applicable to buy, sell short, and certain other actions) and the price at which to perform the desired action (last, open, high, low, a V# variables etc.).There is also a control for picking an (optional) "chart marker" to be used when viewing a trading system in a chart.
The periodicity is a global setting: it could be daily, weekly, 1-minute, or any other non time based periodicity available in I/RT (renko, range bar, tick bar, volume bar, PnF, tick reversal bar, delta reversal bar, etc). At present Investor/RT requires that all rules in a trading system have the same periodicity, but a signal may include a Mixed Periodicity Data Indicator that will refer to data based on another bar periodicities (or even instrument).
Please also note that 2 checkboxes on this main setting window (that can be setup for each individual trading rules) are only relevant when the Trading System is used in the Context of the Trading System Indicator (and won't have any influence in the backtest mode)
- The "Intrabar" checkbox : when checked, the corresponding trading rules, under a live data feed, is being evaluated during the completion of the bar, not only when the bar is completed.
- The "Signal Action" which allows linking to a given trading rule a specific set of actions, ie typically the execution of one (or more) pre-defined trading orders
To create a trading system, use the Object Manager. Choose Trading System as the Object type, then click the New button. The Trading System Definition window will appear. A menu of existing trading systems, if any, appears at the top of the window. Choose a system from the menu or click the "New" button to add a new system. Investor/RT will ask for a name for the new trading system. Enter a name up to 31 characters in length.
Designing a very simple system with 2 Trading Rules
In our simple case, we will consider a very basic "Long only" MACD based system running on Daily bars, and opening / closing a 20 ES contracts positions at the Close price of the bar.
If no trading signals appear in the list, you must define the signals you wish to use in the trading system. Click the "New" button inside the "Define Trading Rule" area of the window to add a new trading signal. A signal setup window will appear for building the signal using RTL. For example, you may define the signal:
MACD.1 < 0 AND MACD > 0
When prompted, setup the MACD as an oscillator with the desired periods. Save the signal under the name "MACD_BUY". This is a simple signal that triggers whenever the MACD oscillator crosses from below zero to above zero.
Similarly, you could add a "MACD_SELL" signal using the RTL formula:
MACD.1 > 0 AND MACD < 0
When you close the signal setup window, the two new trading signals will appear in the signals list on the Trading System Builder window. Create rules by picking a signal and an action, specifying a quantity and a price if appropriate and clicking the "Add Rule" button. The newly added rule will appear in the list at the bottom of the setup window. For example, choose MACD_BUY as the signal, "BUY" as the action and enter a quantity of 500 at the "last" price. For now, set the periodicity for Daily data. After clicking "Add Rule" the new rule will read:
Daily: if MACD_BUY then BUY 500 at Last price
Similarly, add a rule to SELL when the MACD_SELL signal is triggered. As a Trading Rule Quantity, you may, in this case, select either "All" or 500. While still picking the Close of the bar as the exit price, this yields a new rule:
Daily: if MACD_SELL then SELL 500 at Last price
These two rules actually make up a complete (but simplified) trading system. There is a rule for going long and another rule for exiting the long position. Both rules depend upon the MACD indicator. We can now backtest the system on past data as soon as you have completed some required inputs in the setup window (symbol selection, max position size, etc)
A simple tip: in case you already have a long list of signals in your database, start all the names of your new signals related to a given trading system with the same prefix, such as 01_xxxx, so that you can use the integrated signal filter tools to display only the relevant signals in the dedicated Builder window.
Important: every time you do modify one of the parameter settings (action, price, quantity..) attached to an existing trading rule already present in the list of system rules, never forget to push the "Modify rule" button so that this modification is saved inside the Trading Rule definition. Similarly, do not forget to "Save" the whole system definition before running a backtest.
Trading Rule Actions
So far, we have illustrated the use of BUY and SELL actions in trading rules. Both actions specifically apply to initiating and exiting a Long Position. The rules to initiate and exit a Short position would be SELLSHORT and COVERSHORT. There are eleven actions available for forming trading rules. Each action is listed below with a description:
- BUY - buy to open a long position, specify quantity and price type
- SELLSTOP - sell to exit a long position, specify the selling price type
- BUYMORE - buy to add to a long position, specify a quantity and price type
- XLREVERSE - eXit Long position (SELL) and open a short position (SELLSHORT), specify a quantity to short and a price type.
- SELL - sell to exit a long position, specify quantity and price type
- SELLSHORT - sell to open a short position, specify quantity and price type
- BUYSTOP - buy to exit (cover) a short position, specify the price type
- SELLMORE - sell more to add to a short position, specify a quantity and price type
- CSREVERSE - exit short position (Cover Short) and open a long position (BUY), specify a quantity to buy and a price type.
- COVERSHORT - buy to exit (cover) a short position, specify the price type
- CONFIRM - a special action that causes I/RT to confirm the signal by testing the next rule in sequence. The rule following a CONFIRM rule will only be tested if the CONFIRM rule is signals "true". Any number of CONFIRM rules can be stacked in succession. Once any CONFIRM rule tests "false", rule testing continues with the next "non-CONFIRM" rule in sequence.
- NONE - No Action is being triggered. This rule is typically used to initialize or update V# variables through SET statement
- TEST - This is also a No Action, typically used during the system development phase (for update signals used for intermediate reporting purpose), and that i being skipped if the trading system is not run in Test-Mode (The corresponding checkbox is available in the Setup window)
Please notice that :
- BUY and SELL SHORT rules are only tested when the trading system is flat
- BUYMORE, SELL & SELLSTOP rules are only tested when the system is long
- SELLMORE, BUY & BUYSTOP rules are only tested when the system is short
- The SELL and SELLSTOP actions do essentially the same thing, as do COVERSHORT and BUYSTOP. The actions are provided to clearly distinguish between rules for exiting a position pre-maturely (i.e. a stop loss rule) and rules for exiting normally when the trading system issues a trading signal.
- By default, both REVERSE rules can be both used to open a new position or reverse an existing one. If you include a CSREVERSE (ie Cover Short and go long) rule in your trading system and you do not want the rule to initiate new long position then add the expression (POS_STATE = POS_SHORT) AND... to the beginning of the rules' trading signal. This will ensure that the CSREVERSE rule will trigger an action only when you are already short.
Review this support page for more details on Trading rules settings (ie Rule actions, Rule Quantity and Price possible inputs) together with the use of SHOW statement and NOTE tokens as diagnostic tools and a list of all backtesting dedicated tokens (such as POS_STATE, POS_SIZE, etc) returning critical information on the current system status, allowing to manage more complex trading actions (adding to a psoition, taking partial profit, etc) or allowing the user to implement Position Sizing strategies.
Visual Rule Markers
Each trading rule has a visual marker that can be associated with it by clicking on the marker control box in the Trading System Definition window. First, click on a rule to select it for modification. Then change the marker and click "Modify Rule" to record the change. You can also change the action, quantity, and periodicity of a rule in the same way. To view the signals for the selected rule, click the "Chart Rule" button. A chart window will appear with markers showing each bar where the rule's trading signal tested "true". Similarly, clicking the Chart System button shows a chart of the entire list of trading rules. It is important that you specify distinct markers and/or marker colors for each trading rule so they will be distinguishable in the chart window.
Important notice: these native signal marker options are now rarely used as the implementation of the "Trading System Indicator" is a much more efficient way of displaying Trading Rules signals on a regular multi pane chart.
The Trading System backtesting setup window
Backtesting setup options are selected in a separate window called the backtest Setup window. Click the "Setup Backtest" button from the main Trading System window to access this Setup window.
At the top of the window, specify a ticker symbol or a quote page on which to apply the Trading System.
The "Maximum Position Size" settings are used when going long or short or adding to long or short positions to ensure that no more than the maximum shares or contracts are purchased or shorted during any particular trade. Reminder : you can setup the "margin" requirement for a given future instrument through the Preferences > Instrument > Future Type Setup settings window.
Enter the commission and fees to apply on entry and exit of trades during the backtest.
Use the "Backtesting Period" controls to specify the time period over which to run the backtest. Investor/RT will attempt to load data for the specified period from the database but may use less data if historical data is unavailable for a portion of the requested period. A space is provided for user comments.
Secondly, we must select the key backtesting output options in the bottom section of the backtest setup window :
Backtest performance cash instrument and chart
Each time InvestorRT performs a backtest, InvestorRT automatically creates a cash instrument reflecting the performance of the trading system, with the corresponding ticker symbol being $xxxx, where xxxx is the name of the trading system. By checking the “Account Balance Chart” check box, a default line chart will automatically open, with the values shown representing the bar-to-bar dollar gain/loss during the backtest. If you prefer to have a single customised chart template that is used for all trading system account balance charts, this can be achieved by creating a specific default chart format as explained on this page. Since the account balance cash instrument can be used in any traditional chart (like a future instrument), you can, for example, add other instruments, as well as technical indicators, so that you can compare the price action and technical indicators visually with the evolution of the performance of the trading system.
- Single instrument backtest : In this case, if the backtest is performed on a single instrument, the line will show the gain/loss trading that issue over time. If you add a volume indicator for $xxxx (where xxxx is the trading system name), the volume will be equal to 1001 when the backtest position is long, 999 when the position is short, 1000 when the system is flat
- Multiple instrument backtest : If the backtest is performed on a quote page containing many instruments, the line will reflect to aggregate gain/loss amount for all issues. Note that when multiple instruments are tested, the line chart will have data points only for those bars where all instruments were tested. For example, if you backtest with a test period of "last 2 years" and some instruments have the full two years of data on file while others have less data on file, the performance line will begin at the point in time where all instruments have data on file. If you add a volume indicator for $xxxx, the volume shown for each "bar" in the performance chart will be the number of positions that were open during the backtest at that time.
Backtesting reports
Investor/RT provides exhaustive backtesting reports options, providing detailed reports with each individual trade results, but also consolidated reports with the overall trade system performance metrics.
- Report formatting: All these reports will be stored in text and/or Excel formats in the InvestorRT > admin directory. They are best viewed in a "mono-spaced" font so that the report columns line up properly. InvestorRT use a standard mono-space font to display these reports regardless of the user font setting in Setup: Preferences: General. Indeed, all backtesting reports are displayed without word wrap to avoid distorting the report formatting. If you change the font or increase the font size (using the menu control in the upper left corner of the report) you may resize the report window wider to see the full text of each line in the report.
- About the Consolidated report: When running a backtest on a quote page of instruments, a consolidated report, showing the aggregated results of the backtest across all instruments tested, appears at the beginning of the report, followed by the summary reports for each instrument tested.
- About the Divider option: The backtest setup window has a new menu with five choices for the type of output divider to be used when producing reports. The default is a long line of asterisks. Options include long and short lines of asterisks or hyphens, or just a blank line between report sections.
- About the Comments section: Comments are stored with the trading system for future reference. Click OK to return to the Trading System Definition window or click the BackTest button to run the BackTest. For convenience, there is a backTest button on the Trading System Definition window as well.
See Also
- Trading System Tools overview
- Trading Rules settings & Backtesting tokens
- Optimization feature
- Walk Forward Testing feature (aka "Realization")
- Trading Systems & Backtesting video series
- System Deployment with the Trading System Indicator
- The Trading Rule Indicator (semi-automated trading)
- Order executions with Investor/RT