Lighthouse Trader - Home

       
 

Technical Analysis Software for the Stock Market

     

Home

Free trial

Download

Purchase

Data

Documentation

Resources

Contact us

 
 

PIcture of family at seashore

Before You Begin—Creating Scan Definitions

Details of Creating a Trading Strategy for Backtesting

Strategy Prerequisites

Entry Triggers and Tactics

Exit Triggers and Tactics:
       Arming Conditions
       Trade Exit Triggers
       Exit Tactics

Saving Your Trading Strategy

User Interface Reference

Summary

 

BENEFITS OF BACKTESTING

So 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.

Overview

So 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 Save button and enter a title like “My long strategy”. Click the “long strategy” radio button to indicate that we should use this strategy to find long trading opportunities (as opposed to shorting stock).  Enter a complete narrative description of your strategy. Then click the “OK” 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:

  1. Create "scan definitions" to identify when to buy and sell a stock.
  2. Combine your entry and exit scan definitions into a trading “strategy”.
  3. Choose the date range, symbols to evaluate, and strategy to test.
  4. Click "Run" and review the results.

Before You Begin—Creating Scan Definitions

In 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 Details

So 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 Prerequisites

Let’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 Tactics

The 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.

Entry Tactic

Action

Enter at the open or close

This entry tactic has one user-settable parameter. You may choose either “close of trigger day” or “open of day following trigger day”. If you choose the “close” option, the new trade will be entered at the closing price on the day that your entry trigger event occurred. If you choose the “open” option, the new trade will be entered at the opening price of the day following the day on which your entry trigger event occurred.

Enter at trigger price

If you choose this entry tactic, the new trade will be entered at a “trigger price” which is defined within the entry trigger itself.  Click here to learn how to specify the trigger price within your entry trigger (aka scan definition).

The new trade will be entered on the day on which your entry trigger event occurred.

Exit Triggers and Tactics

The 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”.

  1. An “arming condition”.
  2. An “exit trigger”.
  3. An “exit tactic”.

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 Conditions

As 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.

Mode

Meaning

always armed

This is the default setting. When this mode is chosen, the exit condition is always active. In other words, the “arming condition” is assumed to be satisfied, and the position will be exited as soon as the trade-exit trigger occurs.

first time only

When this mode is chosen, the exit condition is active for the first day (or bar) of the trade. It then becomes inactive for all remaining days of the trade.

Use this mode to establish an initial stop-loss price for your trade.

Usually, you will combine this arming condition with the "Adjust stop-loss price when trigger occurs" exit tactic.  In this case, your exit trigger (ie. scan definition) must define a "trigger price" which will be used as the initial stop-loss price for the trade.

one time only

When this mode is chosen, your exit condition will be evaluated for each day (or bar) of the trade, until the associated exit trigger (aka scan definition) “fires”. After firing once, this exit condition becomes inactive, and is ignored for the remainder of the trade.

Typically you use the "one time only" arming condition when you wish to define the conditions for making a partial trade exit.

paired

The “paired” arming condition lets you pair together two exit conditions to act as a single unit.

Here is how the paired arming condition works.

The first exit condition of the pair is evaluated for each day (or bar) of the trade until it fires. Once the first exit condition has fired, it is then ignored for the remainder of the trade. At this point, the second exit condition of the pair will be evaluated.

Once this has occurred, the second exit condition will then be evaluated for every remaining day of the trade, starting with the day that the first exit condition fired.

To pair together two exit conditions, simply choose the "paired" arming condition for both of the exit conditions and then ensure that they appear in the "Strategy Definition" box in the proper order.

If you make a mistake and enter your exit conditions out of order, you can change the order using the up-arrow and down-arrow buttons beneath the "Strategy Definition" box. Simply highlight the "arming condition" line for the exit condition you wish to move, and click the up-arrow/down-arrow buttons until the exit condition is positioned properly.

You may have any number of paired exit conditions in your strategy. To do this, simply add your exit conditions in the proper order, specifying "paired" for each one. The first two exit conditions will make up the first pair. The next two "paired" exit conditions will be combined to form the second pair, and so on.

The important factor to keep in mind is that the order in which the paired exit conditions appear in the "Strategy Definition" box determines how they will be evaluated.

Use the "paired" arming condition when you wish to define an exit condition that becomes effective later on in the trade, after the trade has reached a certain profit level, for example.

Trade Exit Triggers

A “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 Tactics

An “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.

Exit Tactic

Action

Exit after N days

This exit tactic will cause all or part of a trade to be exited after a user-specified number of days. 

The date of entry is considered “day zero”.  Hence, if you specify “1” for the number-of-days parameter, it will exit your trade on the day following the entry date.  Weekends and holidays are ignored.

You may specify a percentage of the original position size to exit when this tactic “fires”.  By default, it will exit 100% of the position.

You may also choose whether to exit at the open or the close on the N-th day.

Exit at the open
or close when trigger occurs

This exit tactic will cause all or part of a trade to be exited when an exit trigger event occurs. 

This exit tactic has two user-settable parameters.

You may choose whether to exit the position at the close of the day on which the trigger event occurs, or at the open of the day following.

You may also specify a percentage of the original position  to exit when this tactic fires. By default, it will exit 100% of the position.

Adjust stop-loss price when trigger occurs

This exit tactic causes the stop-loss price to be adjusted each time its associated trigger event fires.

Unlike other exit tactics, this exit tactic does not immediately exit the trade when its associated trigger event "fires". It simply adjusts the stop-loss price. For each day we are in a trade, the price is compared to the current stop-loss price, and the trade is exited only if the stop-loss price was hit.

When a stop-loss price is "hit", the entire position is exited.

How this exit tactic works.

At the end of each day (or bar) of the trade, the trigger condition is evaluated (subject to the arming condition you have chosen). If the trigger condition "fires", the stop-loss price is set to the new "trigger price", as specified by the trigger condition. If the trigger condition does not fire, the stop-loss price is left unchanged.

Important note: When the stop-loss price is adjusted, the new stop-loss setting will not become effective until the day after the adjustment.

This is to avoid the potential for inadvertently and unfairly using knowledge of the future when simulating trades.

There is one exception to this rule. On the first day of the trade, the initial stop-loss price will be applied immediately on that day.

How to define a "trigger price".

The "trigger price" is the price that the stop-loss will be set to.  The actual value of the trigger price is specified within the trigger condition (aka "scan definition"). When you create your trigger condition, using the "Scan / Rank" feature of Lighthouse Trader, you must choose one of the filter elements to supply the trigger price. Each filter element which you add to your scan definition will display a dialog box with a checkbox labeled "use as trigger price for backtesting".  Simply check this box for the filter element that you want to provide the trigger price.

For example, in your scan definition, you might want to chose the arithmetic "min" (ie. "minimum") filter element to supply the trigger price. In this case, the trigger price would be the minimum value of the most recent N bars.

For long-side trades, the stop-loss price will only be adjusted upwards, never downwards.

For short-side trades, the stop-loss price will only be adjusted downwards, never upwards.

Exit at trigger price

This exit tactic will cause all or part of a trade to be exited at the specified “trigger price” when its associated exit trigger event “fires”. 

The “trigger price” is actually defined by the exit trigger (aka scan definition). See above for a brief discussion of how to set the trigger price in your scan definition, or click here for complete details on how to set the trigger price within your scan definition.

This exit tactic has one user-settable parameter.

You may specify a percentage of the original position  to exit when this tactic fires. By default, it will exit 100% of the position.

Saving Your Trading Strategy—the long and short of it

Perhaps 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 Save button (located beneath the "Strategy Definition" box). A dialog box appears that allows you to give a title to your strategy, a narrative description of your strategy, and whether to use this strategy for long trades or short trades. Click the following thumbnail to see an enlarged example.
Save Backtesting Strategy Definition - dialog box

User Interface Reference

The “Compose Strategy” tabbed window also has several smaller buttons beneath the “Saved Strategies” and “Strategy Definition” boxes. Here is what they do.

Beneath the “Saved Strategies” box you will see the following button:

Trash-can button

Use this button to permanently delete a strategy you no longer wish to use. First highlight the strategy in the box above, and then click this button. Caution: the strategy will be permanently deleted and you cannot recover it later on.

Beneath the “Strategy Definition” box are the following buttons:
Save button

Use this button to save a newly defined strategy.  When you click this button, a dialog box will appear allowing you to give your strategy a short title, a longer description, and whether your strategy is for long-side or short-side trades.

up-arrow button

down-arrow button

Use these buttons to move exit conditions higher or lower in the list of exit conditions. Exit conditions will be evaluated in the order in which they appear in the list.

small checkbox button

Use this button to modify the user-settable parameters for entry tactics and exit tactics in your strategy definition. Note that not all entry/exit tactics have user-settable parameters.

If you wish to change the scan definition chosen for an entry condition or exit condition, you must delete the entire entry or exit condition. Then you may recreate it by clicking on either the “Add Entry Condition” or “Add Exit Condition” button.

Trash-can button

Use this button to remove an element from your strategy. Simply highlight the strategy prerequisite, entry condition, or exit condition, and then click this button. Entry conditions and exit conditions are displayed with multiple lines. You may highlight any of the lines to delete the entire condition.

Summary

Let’s review what we have learned about Lighthouse Trader’s backtesting feature.

  • A “trading strategy” is comprised of an optional “prerequisite” market condition plus an entry condition plus one or more exit conditions. You define your trading strategy under the “Compose Strategy” tab of the Backtest tool in Lighthouse Trader.
  • A prerequisite market condition is simply a scan definition (created in the “Scan / Rank” tool) that is evaluated for a market index symbol such as the S&P 500. Prerequisite market conditions are optional.
  • An entry condition is comprised of an entry trigger (aka scan definition created in the “Scan / Rank” tool) plus an entry tactic.
  • An exit condition is comprised of an arming condition, a trade-exit trigger, and an exit tactic.  The trade-exit trigger is nothing more than a scan definition you have previously created in the “Scan / Rank” tool.
  • Once you have defined and saved your trading strategy, you return to the “Final Selections” tab of the Backtest tool and specify a date range, and an optional watchlist of symbols to evaluate, along with a few other parameters. You also select which trading strategy to use for long and/or short trades.
  • After you have made the above selections, you click the “Run” button at the bottom of the Backtest window to produce the report showing the profitability of your trading strategy.

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.