Before You Begin—Creating Scan Definitions Details of Creating a Trading Strategy for Backtesting Exit Triggers and Tactics: |
BENEFITS OF BACKTESTINGSo why is it important or useful to backtest your trading strategies? Backtesting enables you to prove your ideas before you risk real money. Once you have a proven trading strategy, you can begin to trade with confidence. And confidence is key to keeping your emotions in check. When you have confidence you can stay in winning trades longer and get out of losing trades sooner. OverviewSo how does backtesting work in Lighthouse Trader? Your task is to define a “strategy” for buying and selling stocks. Once you have defined your strategy, which may focus on either “long” trades or “short” trades, you specify a few settings, such as the date-range to evaluate, commission fees, and position sizes. Lighthouse Trader does the rest—presenting you with a detailed analysis of the profitability of your strategy in just seconds. The first step is to sit down and think through what sort of trading strategy you would like to test. Write it down on paper in clear and concise language that you can refer back to in the following steps. Now you are ready to enter your strategy into Lighthouse Trader. Begin by creating a “scan definition” that identifies stocks that meet your requirement for entering new trades. To do this, you utilize the “Scan / Rank” feature of Lighthouse Trader. For example, you could easily create a scan that identifies stocks that have been above their 9 day exponential moving average for eight out of the past ten days (ie. stocks in a strong up-trend) and then have dropped for three to five consecutive days followed by a rise above yesterday’s high. Save this definition, giving it a name such as “My strategy: long entry trigger”. Next, create a second scan definition that will identify when it is time to exit the trade. For example, you could create a scan that “triggers” when stocks fall below their 20 day exponential moving average. Save this second scan with a name like “My strategy: exit trigger”. Now we go to the “Backtest” feature of Lighthouse Trader and “compose” our trading strategy by combining our two saved scan definitions into one strategy. To do this, click the “Backtest” button to open up a new backtest window. Then click on the “Compose Strategy” tab near the top. Now click the “Add Entry Condition” button. You will see your two saved scan definitions in the list at the left. Highlight the scan definition named “My strategy: long entry trigger”. In the box at the lower left corner of the window, highlight the entry tactic named “Enter at the open or close”. In the box at the lower right corner of the window you will see the options available for the entry tactic you have just highlighted. For our example, we want to enter the trade on the day following our entry trigger event. So click on “close of trigger day” and choose “open of day following trigger day” from the drop down list of alternatives. Finally, click the “OK” button to accept our choices and add the new entry condition to our strategy. Now click the “Add Exit Condition” button. In the popup window that appears, highlight the “always armed” arming condition.This means that your exit condition remains in effect throughout the entire life of the trade. In the list of triggers, highlight the trigger named “My strategy: exit trigger”. In the list of exit tactics at the lower left corner of the window, highlight “Exit at the open or close when trigger occurs”. You will see the options for this exit tactic in the box at the lower right corner of the window. The default settings of “close of trigger day” and “100 percent” are what we want. Finally, click the “OK” button to accept our choices and add the new exit condition to our strategy. Our strategy is complete. In the right-hand box you will see the entry and exit conditions we have just defined. So now we will save this strategy to make it available later on. Click the “Save” button Now click the “Final Selections” tab near the top of the window and choose a date range. In the “Available long strategies” drop down list box, choose “My long strategy”. Then click the “Run” button. Depending on the number of symbols you analyze, and the complexity of your trading strategy, the results should appear in less than a minute, probably in just a few seconds. So, to review, the basic steps to backtest your strategy are:
Before You Begin—Creating Scan DefinitionsIn Lighthouse Trader’s backtesting tool, a “trading strategy” is defined as the combination of an optional “strategy prerequisite” condition, an entry condition, and one or more exit conditions. Each of these three types of conditions are based upon “scan definitions” which you have previously created using Lighthouse Trader’s “Scan / Rank” tool. A large part of the work of defining a backtest trading strategy is done in the “Scan / Rank” tool of Lighthouse Trader. If you are not already familiar with how to create a “scan definition” using the “Scan / Rank” tool, you should first become comfortable with this step. The “scan definitions” you create in the “Scan / Rank” tool are referred to as “triggers” in the Backtest tool. This is because they tell the backtest engine when a trade entry or trade exit is triggered. But really, the backtest “triggers” are nothing more than “scan definitions” you previously created in the “Scan / Rank” tool of Lighthouse Trader. This is why it is important for you to learn how to use the “Scan / Rank” tool before you begin to use the Backtest tool. When you create scan definitions for use with backtesting, you must remember to save them. Give them titles that will make each of them easily identifiable later on. They will then appear in the Backtest tool, in the various lists of available triggers. When you create new scan definitions, you may need to restart the Backtest tool, in order for new scan definitions to appear in the lists of available triggers. Creating a Trading Strategy for Backtesting—the DetailsSo now let’s run through the process of defining and running a backtest session once more, this time digging down into the details. If you haven’t already, click the “Backtest” button along the left edge of lighthouse trader to open a new backtest window (did you know you can run multiple backtest sessions in parallel?). If this is the first time you have run the backtest tool, you will need to create a “trading strategy”. So click on the “Compose Strategy” tab near the top of the window. This is where we combine previously created scan definitions and other items to produce a new trading strategy. You will now see two large box areas. The box on the left is labeled “Saved Strategies”. It lists any strategies (both long and short) which you have previously defined. The box on the right is labeled “Strategy Definition”. This is where you build your new trading strategy. Strategy PrerequisitesLet’s focus on the right-hand box (the “Strategy Definition” box). The first heading is titled “Strategy Prerequisites”. This is an optional part of a trading strategy definition. “Strategy Prerequisites” allow you to define general market conditions which must be true before your trading strategy is permitted to enter any new trades. They define the conditions for which your trading strategy “applies”. To specify a strategy prerequisite, click the “Add Strategy Prerequisite” button. In the dialog box that appears, highlight the scan definition (or “trigger”) you wish to use. For example, you might want to choose a scan definition which requires the closing price to be above its 200 day moving average. Remember, you must create these scan definitions before-hand, using the “Scan / Rank” tool. Near the bottom of this dialog box is a field where you must enter a ticker symbol. Typically you will enter the symbol for an index, such as the S&P 500, but you may enter any stock symbol you wish. When you run a backtest, the scan definition which you have just highlighted will be evaluated for each day for the specified symbol and if it returns a false, no new trades will be entered on that day. As another example, you could define a trigger (aka “scan definition”) in the “Scan / Rank” tool that requires the closing price to be above its 30 day moving average, and then save this scan definition with the title “Above 30 day moving average”. Now, in the backtest tool, under the “Compose Strategy” tab, click the “Add Strategy Prerequisite” button and highlight your “Above 30 day moving average” scan definition. For the required symbol, you could enter the symbol for the S&P 500 index (if you are using Yahoo! data, the symbol would be “^GSPC”; if you are using eod-free data, the symbol would be “SP500”. When you backtest your trading strategy with this “prerequisite”, new trade entries will only be allowed when the S&P 500 index is above its 30 day moving average. You may add more than one strategy prerequisite to your trading strategy. In this case, all of the strategy prerequisites must be true on a given day in order for new trades to be entered on that day. If you do specify any strategy prerequisites, then new trades are permitted on every day within the date-range you specified for your backtest session. Of course, new trades must meet the conditions you have defined in the “Entry Triggers and Tactics” section below. Entry Triggers and TacticsThe next heading in the “Strategy Definition” box is labeled “Entry Triggers and Tactics”. This is where you will specify the precise conditions under which a new trade should be entered. To define an entry condition, click the “Add Entry Condition” button. Then highlight one of the scan definitions (aka “triggers”) in the list of available triggers at the left. This trigger will be evaluated for each stock for each day in the date range you choose to examine. You must also specify how you want to enter new trades. To do this, highlight one of the entry tactics in the list of available entry tactics in the lower left corner of the dialog box. When you highlight an entry tactic, optional settings (aka “parameters”) for that entry tactic appear in a box at the lower right corner of the dialog box. To change one of these optional settings for your entry tactic, click on the value column for that parameter and enter a new value. When you are satisfied with your entry condition, click the “OK” button to close the dialog box and add your new entry condition to the strategy definition. Your new entry condition will appear in the “Strategy Definition” box, beneath the “Entry triggers and tactics” heading. Here is a list of the available entry tactics you may choose from.
Exit Triggers and TacticsThe third and final heading in the “Strategy Definition” box is labeled “Exit Triggers and Tactics”. Here you may specify one or more triggers that determine when to exit all or a portion of the trade. Three elements are needed to completely define the timing and manner of trade exits.The combination of these three elements is referred to as an “exit condition”.
Defining your exit condition is quite simple. While on the “Compose Strategy” tab of the Backtest task, click the “Add Exit Condition” button. You will see three list boxes along the left side of the dialog box. You simply highlight one item in each of these three lists to fully define your exit condition. Before we go into a detailed discussion of these three elements of your exit condition, here are a few important facts about exit conditions. You may add any number of “exit conditions” to your trading strategy. Each exit condition will be composed of an arming condition, an exit trigger, and an exit tactic. Simply click the “Add Exit Condition” button repeatedly to add multiple exit conditions to your trading strategy. For each trade, all of your exit conditions will be evaluated for each day in the trade (subject to the arming conditions you specified for each exit condition). Exit conditions are evaluated in the order in which you list them under the “Exit Triggers and Tactics” label. Each exit condition may exit all or part of the original trade position size. When an exit condition has “triggered”, thus exiting all or part of the trade, it becomes inactive for the remainder of that trade. Of course, if the entire position is exited, the trade is complete and no further analysis of exit conditions is necessary. But if your exit condition exits only a part of the position, then you must define one or more additional exit conditions that are responsible for exiting the remainder of the position. For example, it is a common trading practice to exit one-half of your position when the price has moved in your favor by as much as your original amount of risk, and then exit the remainder of the position some time later. In this case, you would need to define at least two exit conditions—the first exit condition would cause the exiting of 50% of the original position when price hits a predetermined profit level, and a second exit condition that determines when to exit the remaining portion of the trade. The number of shares sold (or “exited”) when an exit condition is triggered, is determined by the “exit tactic” you choose. Remember that every exit condition must include an “exit tactic”. We will discuss “exit tactics” in just a moment. Let’s take a more detailed look at each element that goes into your exit condition. Arming ConditionsAs mentioned above, every exit condition must include one “arming condition”. An “arming condition” determines when your exit condition is applicable, being essentially a prerequisite condition that must first be true before we even bother to evaluate the remainder of this exit condition. Arming conditions allow you to combine multiple trade exit conditions to implement more powerful (and potentially more profitable) trade strategies. To choose an arming condition, simply highlight one of the available arming conditions in the box at the top-left corner of the dialog box. (Remember that we have already clicked on the “Add Exit Condition” button to display this dialog box.) In the descriptions which follow, remember that an exit condition is defined by the combination of an arming condition, an exit trigger, and an exit tactic. The exit condition is said to be “active” when its arming condition is satisfied or “true”. When the arming condition has been “satisfied”, Lighthouse Trader evaluates the trade-exit trigger to determine if it is time to exit the trade. Conversely, if the arming condition has not been satisfied, the trade-exit trigger is not evaluated and we will continue to remain in the trade. These are the choices you have for an arming condition.
Trade Exit TriggersA “trade exit trigger” is the heart of the exit condition. It determines when, and at what price, the trade will be exited, subject to the arming condition mentioned above. Once the associated arming condition has been satisfied, the management of the trade is in the hands of the trade-exit trigger. To specify a trade-exit trigger, simply highlight one of the triggers (aka scan definitions) from the list of “triggers” in the dialog box. (Remember that we have already clicked on the “Add Exit Condition” button to display this dialog box.) For each exit condition, you must also specify an “exit tactic”. This is described in the following section. Exit TacticsAn “exit tactic” tells Lighthouse Trader what to do when a trade exit is signaled. It determines whether to exit the stock at a closing price, an opening price, or some trigger price (defined in your scan definition), and how many shares to sell (expressed as a percentage of the original position size). Every exit condition must have an associated exit tactic. To specify an exit tactic, simply highlight the exit tactic you wish to use from the list of available exit tactics in the dialog box. (Remember that we have already clicked on the “Add Exit Condition” button to display this dialog box.) Note: the “Exit after N Days” exit tactic is slightly different from the other exit tactics in that it does not require a trigger condition. That is because the exit will be triggered unconditionally after the required number of days have passed. So, for this exit tactic, the trigger condition will be ignored, and need not be specified. When you highlight an exit tactic, optional settings (aka “parameters”) for that exit tactic appear in a box at the lower right corner of the dialog box. To change one of these optional settings for your exit tactic, click on the value column for that parameter and enter a new value. When you are satisfied with your exit condition, click the “OK” button to close the dialog box and add your new exit condition to the strategy definition. Your new exit condition will appear in the “Strategy Definition” box, beneath the “Exit triggers and tactics” heading. Here is a table describing each of the available exit tactics.
Saving Your Trading Strategy—the long and short of itPerhaps you have been wondering how you tell the system whether to use your trading strategy for long trades or short trades. This choice is made when you save your trading strategy. After you have specified the triggers and tactics that comprise your trading strategy, you must save your strategy. To do this, you click the “Save” button User Interface ReferenceThe “Compose Strategy” tabbed window also has several smaller buttons beneath the “Saved Strategies” and “Strategy Definition” boxes. Here is what they do.
Let’s review what we have learned about Lighthouse Trader’s backtesting feature.
Back to top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
home | free trial | download | purchase | data | user guide | resources | contact us
terms & conditions | privacy policy | add a link to Lighthouse Trader from your web site
Website designed by: Clayjar Creative LLC
Copyright © 2005-2008 Lighthouse Trader LLC. All rights reserved.
[1] Lighthouse Trader LLC is not affiliated with TD Ameritrade and neither endorses nor is endorsed by TD Ameritrade.
TD Ameritrade is solely responsible for the timeliness, accuracy, and availability of their data.