Find Elusive MACD Divergences Easily - Back · PDF fileFind Elusive MACD Divergences Easily...

13
1 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm. Find Elusive MACD Divergences Easily By using a Custom TradeStation ® Workspace After following these instructions, you will have Charts displaying MACD lines and histogram which highlight price/indicator divergences Color-coded price bars indicating buy and sell signals similar to the backtested strategy Scans to show which stocks in your symbol list got a buy signal and a sell signal TradeStation strategy implementing the best of the strategies tested by BackTesting Report o Note: Implementation modified to backtest one market at a time. The TradeStation Workspace applies what you learned in the companion BackTesting Report. You can further your education about MACD by Seeing the strategies in action on your favorite charts Tweaking the strategy to add your own rules Check results over your own dates and stocks with Strategy Performance Report Forward testing by tracking buy and sell signals as they occur in the future To understand MACD Divergences and their hypothetical past performance see the Backtesting Report titled “Finding Big Bottoms with MACD Bullish Divergences”. Before actually investing with these strategies, you are strongly advised to read the MACD BackTesting Reports, consider the risk of loss, maybe even consult a professional for advice. Ultimately, you make your own decisions about your own money. Install TradeStation If you don’t already have TradeStation, you will need to download and set it up. Please see www.tradestation.com for more information. The custom software from BackTesting Report supports version 8.6 Build 2525 or later. If you insist on an earlier version of TradeStation, see the last section of this document for instructions on building a workspace from scratch and copying the source code from text files. HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

Transcript of Find Elusive MACD Divergences Easily - Back · PDF fileFind Elusive MACD Divergences Easily...

1 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

Find Elusive MACD Divergences Easily

By using a Custom TradeStation® Workspace

After following these instructions, you will have Charts displaying MACD lines and histogram which highlight

price/indicator divergences Color-coded price bars indicating buy and sell signals similar to the backtested strategy Scans to show which stocks in your symbol list got a buy signal and a sell signal TradeStation strategy implementing the best of the strategies tested by BackTesting Report

o Note: Implementation modified to backtest one market at a time. The TradeStation Workspace applies what you learned in the companion BackTesting Report. You can further your education about MACD by Seeing the strategies in action on your favorite charts Tweaking the strategy to add your own rules Check results over your own dates and stocks with Strategy Performance Report Forward testing by tracking buy and sell signals as they occur in the future To understand MACD Divergences and their hypothetical past performance see the Backtesting Report titled “Finding Big Bottoms with MACD Bullish Divergences”. Before actually investing with these strategies, you are strongly advised to read the MACD BackTesting Reports, consider the risk of loss, maybe even consult a professional for advice. Ultimately, you make your own decisions about your own money.

Install TradeStation

If you don’t already have TradeStation, you will need to download and set it up. Please see www.tradestation.com for more information. The custom software from BackTesting Report supports version 8.6 Build 2525 or later. If you insist on an earlier version of TradeStation, see the last section of this document for instructions on building a workspace from scratch and copying the source code from text files.

HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

2 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

Install BackTesting Report Custom WorkSpace and EasyLanguage Scripts

1. Download the file BTR8_TradeStation.exe After agreeing to license terms, download and unzip according to the instructions below. This package contains two file types. Import the BTR_MACD_DIVS.ELD file into TradeStation and put all the .tsw files in the TradeStation MyWork folder. The instructions below apply to the MACD Divergence BTR8_TradeStation.exe files you download in this step.

a. (Firefox: Save the file to your desktop and then double-click it to Run.)

b.

c. First browse for location and pick an easy temporary location like the Desktop

d.

3 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

e.

2. Open TradeStation 3. Import the ELD files into TradeStation (before opening the workspace):

a. Choose File->Import/Export EasyLanguage from the TradeStation menu b. Choose “Import EasyLanguage file (ELD,ELS,ELA)” and click Next

4 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

c. Browse to find BTR_MACD_DIVS.ELD on Desktop from step 2:

d. Click Next to Import all Analysis Types:

e. Don’t replace any TradeStation built in functions, just import stuff named BTR_ and a function called XavgRadarScreen

5 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

f. IMPORTANT: If it asks to replace any other functions, answer No.

4. Put all the workspace files (BTR_MACDH_Div.tsw, BTR_MACDH_Div.tsw, BTR_MACDH_Div_RadarScreen.tsw, BTR_MACDH_Div_RadarScreen.tsw) into C:\Program Files\TradeStation (version)\My Work

6 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

5. On the TradeStation menu, click File->Open WorkSpace and choose BTR_MACDL_Div.tsw, or BTR_MACDL_Div_Pwr.tsw or BTR_MACDH_Div.tsw. The workspace will appear with a large chart window open and three small iconified EasyLanguage documents at the bottom.

Figure 1-TradeStation Screenshot of MACDH_Div workspace. Note that EasyLanguage source is now available in the TradeStation Development Environment, not the workspace.

Figure 2-TradeStation Screenshot of MACDL_Div workspace.

7 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

Figure 2 - TradeStation Screenshot of MACDL_Div_Pwr workspace.

Understanding the MACD Divergence Workspaces and Strategy On the price chart, buy signals are green, and sell signals are red. The neutral-colored bars are ignored in this strategy, so if you are already in a position you hold and if not just stand aside. The blue arrows and lines are the TradeStation strategy running, in this case just backtesting. The stop price for the life of the trade is calculated based on the average true range (ATR) on the day of the buy signal. It is displayed above the price for the life of the trade. To reposition it for readability, left click to select it and drag it to where you want it. If it won’t go where you want it, right click and select Snap Mode to turn it off. The middle indicator is the MACD. The BTR_MACDH_Div strategy sports the standard 12,26,9 lines and histogram. The BTR_MACDL_Div_Pwr strategy relies on the 12,26,9 MACD Lines and the slower 19,39,9 MACD, which is plotted as Appel’s Histogram. The BTR_MACDL_Div strategy is based on the standard MACD lines. You may plot the MACD line as Appel’s Histogram by selecting the MACD line, right-click, choose Format ‘MACD’, click the Style tab, select Plot of MACD and Type of Histogram. The bottom indicator is volume. A buy signal only takes place if volume is above 500,000 shares. If you change the timeframe on the chart, you probably want to change this parameter in the strategy.

8 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

TradeStation Alerts are enabled on the ShowMe analysis technique. TradeStation will audibly tell you when a divergence is detected on the last bar of the chart. The settings can be changed on the Alerts tab of the Format Analysis Technique dialog box. For more information, see the TradeStation documentation on the use of alerts.

Using the TradeStation Scanner to Find MACD Divergences

You can use the custom Indicators in this package with the TradeStation Scanner to detect MACD Divergences occurring in a list of symbols. Follow the TradeStation instructions for setting up the scanner. For the scan criteria, select one of the indicators in this package. For example, BTR_MACDL_Div to find MACD lines divergences or BTR_MACDH_Div to find MACD histogram divergences. Set the criteria to “Display”, as shown in Figure 4 below.

Figure 4 – Scanner Criteria Setup (TradeStation Screenshot)

The scan results are displayed as a column of numbers. “-9999” indicates no divergence detected. A positive number indicates a positive divergence and the number is the position size calculated using the risk amount and the ATR stop distance given as inputs (defaults are $1000 and 3 ATR respectively). A red “0.00” indicates a negative divergence.

Scanning for MACD Divergences with RadarScreen

Three workspaces are set up to use TradeStation’s RadarScreen to scan a symbol list for MACD and MACDH divergences. This is in a separate workspace because RadarScreen consumes the computer’s resources and places unique requirements for custom EasyLanguage indicators. To scan the market, open either the BTR_MACDH_Div_RadarScreen, BTR_MACDL_Div_RadarScreen or the BTR_MACDL_Div_Pwr_RadarScreen workspace. The workspace comes configured with the components of the S&P500 as a symbol list to scan,

9 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

however, you can insert any symbol list for which you have data. Just select a row on RadarScreen, right click, choose Insert Symbol list and pick from the list or simply type a symbol into a blank row. The third column in the RadarScreen row presents the results of the scan for MACD(H) divergences. A white “-9999” indicates no divergence detected. A green number indicates a positive divergence and the number is the position size calculated using the risk amount and the ATR stop distance given as inputs (defaults are $1000 and 3 ATR respectively). See Figure for an example of a positive divergence flagged by the BTR_MACDH_Div indicator in Radarscreen. A red “0.00” indicates a negative divergence. See Figure for an example of a negative divergence flagged by the BTR_MACDL_Div_Pwr indicator in Radarscreen.

Figure 5 - Radarscreen buy signal (TradeStation Screenshot)

While the strategy considers a trade open, text is printed on the chart showing the stop loss value. Sometimes this text may be partially hidden. If so, simply left click, hold, and drag it to where you can see it.

10 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

Figure 6 - RadarScreen Sell Signal (TradeStation Screenshot)

Known Issue: The results of the RadarScreen scan and the strategy on the chart do not always agree. When there is a difference, the chart strategy reflects the results in the MACD Divergences BackTesting Report. RadarScreen required significant code changes, making that implementation different from the backtested one.

Advanced Instructions

Changing Parameter Settings

To change parameter values of the strategy: 1. Right click on the chart 2. Choose Format Strategies 3. Click the Format button 4. Change parameters as desired

11 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

Parameter definitions and defaults are documented inside the EasyLanguage documents:

BackTesting

The strategy back test is enabled. The TradeStation results summary is available from the menu: View->Strategy Performance Report. See TradeStation documentation for complete information on how to read the strategy report.

Creating the Workspace from Scratch

If you are somehow stuck on an earlier version of TradeStation than 8.4, follow these steps to build a workspace from scratch, copy in the source code from text files, and insert the strategies and analysis techniques. Save the Workspace frequently as you go along.

1. Open TradeStation

12 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

2. File->New-> Workspace 3. Open a chart window by selecting the Chart Analysis icon from the toolbar. 4. Format the symbol

a. Bar chart b. Daily c. 5-15 years back d. I prefer a Light, bland color for basic bars so the paint bars stand out.

5. Right click on the chart and choose Insert Analysis Technique-> Indicator->MACD 6. Right click on the chart and choose Insert Analysis Technique-> Indicator->Volume 7. Right click on the chart and choose Insert Analysis Technique-> Indicator->Moving

Average Exponential and set Length to 12 on the Input tab 8. Right click on the chart and choose Insert Analysis Technique-> Indicator->Moving

Average Exponential and set Length to 26 on the Input tab 9. Right click->Format Window->Status Line

a. Check box for Show Status Line b. Select and add

i. Analysis Techniques and Strategies ii. Symbol, Date, Net chg, and anything else you want to see

10. To add the strategy so you can see buys and sells on the chart: a. Open New EasyLanguage Document by clicking that icon on the toolbar

i. Select strategy and name it according to the text file name, for example BTR_MACDH_Div (don’t include the .txt part)

b. Outside TradeStation, i. open BTR_MACDH_Div.txt in notepad

ii. CTRL-a to select all, CTRL-c to copy c. In the New EasyLanguage Document, do CTRL-v to paste d. Click the green check bar on the toolbar to verify the EasyLanguage code e. Right click on the chart and choose Insert Strategy

i. Choose BTR_MACDH_Div from the list ii. On the Format Strategies tab, Click the “Properties for All” button

1. In the lower left corner, set the “Maximum Number of Bars Study Will Reference” to 201

2. In the upper left corner, set the commission assumption to 0.005 per share or set your own value

11. To mark the bars when a divergence is detected, install the Show Me a. Open New EasyLanguage Document by clicking that icon on the toolbar

i. Select Show Me and name it according to the text file name, for example BTR_MACDH_Div_SM (don’t include the .txt part)

ii. If the new window is not blank, do CTRL-a, then delete to remove all b. Outside TradeStation,

i. open BTR_MACDH_Div_SM .txt in notepad ii. CTRL-a to select all, CTRL-c to copy

c. In the New EasyLanguage Document, do CTRL-v to paste

13 Copyright 2008-2011 Own Mountain Trading Company. TradeStation and EasyLanguage are trademarks of TradeStation Group, Inc. Material intended for educational purposes, not investment advice. http://www.backtestingreport.com/termsofuse.htm.

d. Click the green check bar on the toolbar to verify the EasyLanguage code e. Right click on the chart and choose Insert Analysis Technique->ShowMe and

choose BTR_MACDH_Div_SM from list 12. To color the bars when a divergence is detected, install the Paint Bar

a. Open New EasyLanguage Document by clicking that icon on the toolbar i. Select Paint Bar and name it according to the text file name, for example

BTR_MACDH_Div_PB(don’t include the .txt part) ii. If the new window is not blank, do CTRL-a, then delete to remove all

b. Outside TradeStation, i. open BTR_MACDH_Div_PB .txt in notepad

ii. CTRL-a to select all, CTRL-c to copy c. In the New EasyLanguage Document, do CTRL-v to paste d. Click the green check bar on the toolbar to verify the EasyLanguage code e. Right click on the chart and choose Insert Analysis Technique->PaintBar and

choose BTR_MACDH_Div_PB from list 13. Be sure and save the workspace 14. Repeat to make a workspace for each strategy. 15. If the Strategy, Paint Bar, and Show Me don’t overlap in the bars they select, check to be

sure that the correct code was pasted into each document. These file names are very similar and easy to mix.

To plot Appel’s Histogram:

a. Insert Analysis Technique-> Indicator->MACD b. Select it , right click, and choose Format MACD

i. On the Inputs tab, change settings if desired ii. On the Style tab, change MACD to Histogram

iii. On the Color tab, change MACDDiff to black (background color)