Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.


  • Content Count

  • Joined

  • Last visited

Personal Information

  • First Name
  • Last Name
  • City
  • Country
    United States
  • Gender
  • Biography
    I run a web site called System Trader Success. http://www.systemtradersuccess.com

Trading Information

  • Vendor
  • Favorite Markets
    Futures and ETFs
  • Trading Platform
  • Broker

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. This is really a market study, not necessarily a complete trading system. I would encourage system developers to take this idea and see if they can build it into a complete system. However, you will notice the final strategy code generates a 167 trades which is a good number in my opinion.
  2. I've updated this strategy based upon reader feedback. I created a new post here.
  3. In this article I want to take a look at a reader's recommendation on improving the Double Seven strategy. If you recall, the Double Seven strategy is a long-only strategy for the the broad U.S. indexes. It was created by Larry Connors and was covered in a previous article, "Double Seven Strategy". Recently a reader pointed out a possible improvement to the system which appeared in the "Letters to the Editor" section of Stocks & Commodities Magazine, V. 27:3 (8-9). In short, the recommendation modified the entry and exit signals in an attempt to capture more profit. Changes included the following: Market entry would become a buy stop entry and the exit would become a trailing stop. To be honest, I found the description of the changes not 100% clear and my testing was not promising. However, the concept of a buy stop and trailing stop are worth looking into. First, let's provide a quick review of the Double Seven strategy. The Original Rules As a reminder, here are the original rules for taking long trades which are executed on a daily chart: The instrument must be above its 200 day moving average If the instrument closes at a seven-day low then buy at market If a long position is open and the instrument closes at a seven-day high then sell at market Testing Environment I coded the above rules in EasyLanguage and tested it on the S&P cash market going back to 1983. Before getting into the details of the results let me say this: all the tests within this article are going to use the following assumptions: Starting account size of $100,000. Dates tested are from 1983 through June 30, 2014. The number of shares traded will be based on volatility estimation and risking no more than $2,000 per trade. Volatility is estimated with a five times 10-day ATR calculation. This is done to normalize the amount of risk per trade. The P&L is not accumulated to the starting equity. There are no deductions for commissions and slippage. There are no stops. Please note we are not adding our profits to our trading account! We are always trading a small percentage of our starting capital. Thus, the results demonstrated here are very conservative and it would be easy to generate much higher returns. Here is the position sizing formula used:Shares = $2,000 per trade / 5 * ATR(10)For an example of what the trades will look like on a daily chart, below is an image of a couple of trades. As the market makes a seven-day low, a long trade is entered. Open trades are then closed at the next seven-day high. Double Seven Results Based upon the standard rules we get the following results trading the S&P cash market. Modification of Entry Signal The recommendation within Stocks & Commodities Magazine recommended..."Set a sell-stop 0.1 below the close of the seven-day high, and keep moving it below the close each day until you are sold out." I modified this a bit. In essence, we have a classic trailing stop and it makes a lot of sense given we are attempting to capture as much profit as possible when the market recovers from a pull-back in an overall bullish regime. Presumably during a strong market we can expect price to occasionally go beyond our traditional seven-day high exit. A trailing stop may very well capture more profit. Of course some of the trades will "give back" some of the profit as price must fall to hit our seven-day stop, but the handful of runners should provide us with more P&L to offset these setbacks. The only way to really see if this will work is to test it. For my test I used the seven-day low instead of the close. Below are the results with our new modified seven-day low trailing exit. We can see we make slightly more net profit but it comes at a price. Our profit factor falls as does the percentage of winning trades. We decrease our consecutive winners while increasing the number of consecutive losing trades. We do have a slightly larger average profit per trade, but we obtain this with less efficiency as seen by our profit factor. Viewing the equity curve you can clearly see the choppiness of this system. Sure it makes more money, but it's not a clean looking equity curve when compared to our standard Double Seven Strategy. Why would this be? By introducing our trailing stop we are causing a number of trades to get stopped out that ultimately turn in our favor. This leads to more trades when compared to the original rules as well. Recall the original rules have no hard stop - only dynamic exit at a new seven-day high. By adding our trailing stop we immediately place a hard stop at the low of the past seven-days. Introducing this stop 'hurts' our system. Can we try something else? Maybe what we can try is only introducing the trailing stop when... 1) a new seven-day occurs; and 2) we have positive P&L.This will delay adding the trailing stop. Price will be free to meander or make new lows instead of taking us out at a nearby stop level. If price happens to move lower before we add our trailing stop then makes a new seven-day high and our open position P&L is negative, we'll call this a losing trade and simply exit at the market. However, if we have positive open position P&L at a seven-day high, we'll activate our tailing stop. Below are the results. This looks a lot better. We are making significantly more profit and doing it will decent efficiency based upon the profit factor value. We do take some significant heat based upon the drawdown value. Overall, the equity curve looks decent as we make more profit per trade. Another Modification of Entry Signal The recommendation within Stocks & Commodities Magazine recommended..."Set a buy-stop 0.1 above the close of the seven-day low, and keep moving the buy-stop down above each day’s close until you are bought in."The idea is we can often enter at a lower price if the market continues to fall dramatically over the next day. I tested this with not much promise. To me, setting a buy-stop at a level .01 above the close of the bar does not make a lot of sense. Often when setting a buy stop to enter the market you set it above a recent significant high. What comes to mind is the daily high. So, that's what I did next. When the market markets a new seven-day low, I then place a buy-stop at the high of the bar. Price must then hit that high in order for a new position to be opened, confirming some strength on the bullish side. Please note, we are adding these new entry rules but keeping our original exit. This is because I want to see how these new rules changes the system without the interference of our new exit. This significantly reduced profitability. Clearly, buying into the weakness is better than waiting for bullish confirmation. While it may "feel better" to wait for bullish confirmation before opening a long trade, the performance metrics clearly state you should be buying into weakness. In short, the original rules produce much better results. Conclusion This experiment was not really a test based upon the rules provided by the Stocks & Commodities Magazine reader. However, it was inspired by it. Thus, it's possible the reader's solution may be better than what I've come up with here. I really don't know. However, I think we can see some basic tenants of trading the S&P during a bull market that many readers of this website will be familiar with. 1) Buy into weakness with a market order. 2) Hold a trade to gain more profit. These are well known tenants of the S&P and this strategy test just highlighted them once again. Other things that could be tested include buying with limit orders and exiting into strength based upon a different indicator such as a 2-period RSI. In closing, we found that our best results were realized by only modifying our exit rule to include a trailing stop. Downloads You can download the EasyLanguage source code here.
  4. I've written several posts on this forum highlighting simple trading models that could be the basis for a profitable trading system on the S&P market. These ideas would be suitable either for the ETF market or the Emini futures market. This article will explore yet another simple trading model. Recently I was inspired by a post at Quantifiable Strategies titled, "How To Make Money From The Close Until Tomorrow’s Open in SPY/S&P 500" by Oddmund Grotte. This brief blog post builds up the work of Rob Hanna at Overnight Edges to test another simple S&P model. I thought I would create the model in EasyLanguage and put it through my own testing. The Overnight Edge The overnight edge is an S&P market edge that I, along with many other people, discovered years ago. I've written about this market edge in a previous article on my website, "The Overnight Edge". This particular model is going to take advantage of that edge by going long at the close of the day and closing the trade at the next day's open. The dominate question we will be answering today is, when should we buy. Obviously buying at the close of every single day is not a realistic strategy. So, we wish to eliminate the unproductive trades in favor of finding the highest probability set-ups. That is, what types of days produce the biggest nightly returns? Baseline Model Rules SPY closes at new 20 day low Close is above 200 day simple moving average Go long at the close Exit at tomorrow’s open Below is a snapshot of a few trades taken on the daily chart of the S&P Emini. Testing Environment I coded the above rules in EasyLanguage and tested it on the E-mini S&P futures market. Before getting into the details of the results let me say this: all the tests within this post are going to use the following assumptions: Starting account size of $25,000 Dates tested are from September 11, 1997*through December 31, 2012 One contract was traded for each signal The P&L is not accumulated $30 was deducted per round-trip for slippage and commissions There are no stops Baseline Results Below is the equity graph and the performance results of the baseline model. Testing the Robustness of the Lookback Period The baseline rules call for a 20-day new low. Is this just an outlier? Or, is this parameter robust for a wide range of values? When looking at a trading model, it's important that the parameters demonstrate robustness across a wide range. That is, the system should remain profitable over many different values. To test the robustness of this input, I will use TradeStation's optimization feature which will allow me to quickly test a range of values. I will test the range 2 - 30. The results of my test are below. The x-axis displays the number of days for the new low while the y-axis displays the net profit. [caption align=aligncenter" width=607] Lookback vs. Net Profit[/caption] We can easily see a clear trend. The shorter the lookback period the more profit. Notice that a lookback period of 4*days is probably an outlier. It's enticing to simply pick a small lookback period like 3*or 5, but from experience I know more profit often comes at a price. Often*that price is deep drawdown, larger losing streaks and prolonged periods of no new equity highs. Let's look at these results another way. Another way to look at the results is to compare the profit factor vs. the lookback period. See the bar chart below. The x-axis displays the number of days for the new low while the y-axis displays the profit factor. We can see that our profit factor has an opposite trend when compared to the new profit bar graph. In other words, as we make more net profit, we do so with less efficiency. Sure we are making more money when we have a lookback period of 3 when compared to a lookback period of 20. But we also have more losing trades. This can be confirmed by the next bar graph. Let's also take a look at the number of trades. See the bar chart below. The x-axis displays the number of days for the new low while the y-axis displays the number of trades. Once a again there is a clear trend. There are fewer trading opportunities as you increase the lookback period. This makes sense. The higher the lookback period the less likely you are to experience that new low. So, more profit does come at a cost. It will be up to you to determine what is appropriate for your trading situation. For me, I would like to have fewer trades and less net profit. This comes with, what I consider, the benefit of fewer losing trades, more net profit per trade, and less drawdown. In short, I prefer the quality trades over the quantity of trades. It appears we can improve the*net profit of our model by reducing the lookback period for the new look. More on that later. Testing the Robustness of the Regime Filter The regime filter in this model is a simple moving average. We are using the "standard" 200-day*simple moving average. This is a very common period for daily charts. It's commonly understood that price is generally bullish when it's above this moving average and bearish when below it.*Again, to*test the robustness of this filter*I will use TradeStation's optimization feature.*I will test the range 60*- 250. The results of my test are below. The x-axis displays the number of days for the lookback value*while the y-axis displays the net profit. Clearly the longer the lookback period the more net profit we generate. Our "standard" 200-day lookback value performs well, but it's not the best. The best value is 250 in this study. Many values will perform similarly. This gives me confidence the regime filter is not overly optimized and is robust. Weak Close Filter In the original blog post by Oddmund Grotte he introduced a price based filter that required the close of the current bar to be within the lower half of the daily range. If price closes in the lower half of the daily range it is presumed we are looking for a weak close. A strong close would be when the close is the upper half of the daily range. The calculation to determine if the close is within the lower half of the daily range looks like this: Weak Close=(c-l)/(h-l) < 0.5 With this additional filter we are confirming weakness before opening a new long position. The results of our trading model with the new filter are below. The filter did a fantastic job of removing unproductive trades. You can see this because we are making more net profit with fewer trades. This pushes up the average profit per trade. We also reduce our drawdown which increases our profit factor. The only thing concerning is our trade size is small. The baseline had 61 trades, which is not very many trades. With our filter we reduce the trades to 55. But we know how to increase the number of trades by reducing the lookback period of the "new low". We'll do that later. For now, there is one other input value I want to test. Testing the Robustness of the Close Filter Once again let's take a detailed look at the percent range used in the Close Filter. If you will recall, we are looking for a close in the lower half of the daily range. But is this just a fluke value? Will other values produce similar results? The bar graph below depicts taking trades at or above the given x-axis value. For instance, the far left bar*produces a net profit around $4,700. The value on the x-axis at this bar is 0.1. This states that all this profit is accumulated above this value. By the time we reach 0.45 there is no more profit to accumulate. Thus, we can see the accumulated*profitable trades occur when the daily close falls within the lower 40% daily range. Put another way, we want to open a long position when the daily close is within the lower 2/5 of the daily range. Combining Our Findings Let's now combine a couple of our findings. First, let's increase the number of trades by reducing the lookback period on locating a new low. Let's try to keep the profit factor around 2.0, so we'll use a lookback period of 5*instead of the default 20. I will then change the weak close filter to a value of 0.40 from the default 0.50. I will make no change to the*simple moving average regime filter which is at 200. Below are the results. Not too bad for a few lines of code. Remember this model does not have any stops nor does in reinvests profits. In short, this is not a trading system but an interesting model which could evolve into a complete trading system with some work. Downloads You can download the EasyLanguage code and TradeStation Workspace for this strategy here.
  5. Going back to the start of SPY (1993) a buy-and-hold strategy based upon the same risk position sizing would produce... Net Profit: $165,933 Profit Factor: N/A Avg. Trade Net Profit: $165,933 Total Return: 165% Annual Rate of Return: 5.09% Clearly much better results if you entered in 1993 and rode those bear markets where you will see 40% drawdowns. Also, dividends are not included. Since the year 2000 things would look like this for the buy-and-hold: Net Profit: $3,220 Profit Factor: N/A Avg. Trade Net Profit: $3,220 Total Return: 3.2% Annual Rate of Return: .24% Since the year 2000 things look like this for the Double Seven Net Profit: $13,732 Profit Factor: 1.49 Avg. Trade Net Profit: $140.12 Total Return: 13.7% Annual Rate of Return: .96%
  6. I would if it was a trading system, but it's not a trading system. Note, it does not even have stops! What this article demonstrates is a potential market edge. However for the sake of commissions and slippage, below are the SPY results of adding... 2% Stop Loss Deducting $20 + $.01 per share per round trip. Net Profit: $33,232 Profit Factor: 1.96 Avg. Trade Net Profit: $216.37 Total Return: 33.32% Annual Rate of Return: 1.50%
  7. It's time to look at another simple trading system which can be found in the book, ”Short Term Trading Strategies That Work” by Larry Connors and Cesar Alvarez. In this article we are going to look at the Double 7 strategy. This is a simple strategy that can be applied to the major market indices such as DIA, DOW and QQQ. It can also be applied to the futures markets. The rules of this system are very simple. The instrument must be above its 200 day moving average. If the instrument closes at a 7-day low - buy. If a long position is open and the instrument closes at a 7-day high - sell. The trading system follows two basic concepts we have talked a lot about on this website. Namely when trading the major market indices, like the S&P, an effective strategy is to buy pullbacks in a major up trend. This system does just that. The major up-trend is defined by price being above the 200-day moving average. A pull-back is defined as a close below the lowest-low over the past seven days. Once a trade is entered, we simply look for a new seven day high to exit. Super simple. Below is an example of some trades on the S&P Cash Index. Click the image for a larger view. Looking at the trading rules, you will also notice it's a long-only system. Later in this article I will also reverse the rules and test it on the short-side. But for now, let's look at the performance for the long-only system. At this point I'm going to test it on the S&P cash index ($SPX.X for TradeStation). Unless otherwise stated, all the tests performed in this article will be based on the following assumptions: Starting account size of $100,000. The number of shares traded will be based on volatility estimation and risking no more than $2,000 per trade. Volatility is estimated with a five times 20-day ATR calculation. This is done to normalize the amount of risk per trade. The P&L is not accumulated to the starting equity. There are no deductions for commissions and slippage. There are no stops. Here is the position sizing formula used: Shares=$2,000 per trade / ( 5 * ATR(20) * Big_Point_Value ) This looks very promising. Keep in mind, the system has no stops. Is The 7-Day Optimized? Let's look at changing the 7-day look-back period for two reasons. First, I would like to see if the default seven value is optimized. Secondly, I would like to know if other nearby values are used, would the system remain viable. In short, I would like to test the robustness of the look-back period. For example, if we change the 7-day low value to six, I don't want to see the system's equity curve drastically change. Likewise, if we increase the 7-day low value to eight, I don't want to see a drastic change in results. The neighboring values around seven should still produce positive results. In fact, it would be great to see the system remain profitable over a wide range of values. I will use TradeStation's optimization feature to optimize the look-back period over the values 2-20 in increments of one. Keep in mind this single input value controls two look-back periods. The first is the entry look-back and the second is the exit look-back. As the trading system is defined, both these variables use the same value. The results of the test are in the graph below. You can click the image to see a larger view. The x-axis contains the look-back period while the y-axis contains the trading systems total P&L. This looks great. Any value you choose produces positive results. Each change in the look-back period also does not drastically change from neighboring values. The default value of seven is near the peek, which is six, but it's not the most optimal number. It's also important to keep in mind we will be using the default value of seven for other instruments as well and it's highly unlikely the bar graph for those instruments would look exactly like what we have here. In any event, I think this brings a lot of confidence to the look-back period. Is The Regime Look-Back Optimized? Just as we did for the look-back period for our entry trigger, let's perform the same type of test on the regime look-back period. Again, I will use TradeStation's optimization feature to optimize the look-back period over the values 20-200 in increments of ten. The results are in the graph below. You can click the image to see a larger view. The x-axis contains the look-back period while the y-axis contains the trading systems total return. This looks great as well. All values produce positive returns. In general, the longer the look-back period the more profit the system generates. While I did not study the numbers just beyond 200, I feel confident that a 200-period look-back is not optimized. Taken both these tests we can feel confident that this system does not appear to be optimized and it's robust given a wide variety of input values. Going Short The original system is a long-only system. Let's try to use the current rules to short the market. We can do this by simply reversing the rules. In other words, we will modify the regime filter to only open trades when price is below the 200-day moving average. Trades will then open when price makes a new 7-day high and close when they make a new 7-day low. The instrument must be below its 200 day moving average. If the instrument closes at a 7-day high - sell short. If a position is open and the instrument closes at a 7-day low - buy to cover. I created a separate trading system to study only the short-side. The results of the system can be seen in the equity graph below. This is not so great. Most of the time the equity curve is below the zero line. It's choppy and ugly. Clearly the market participants' psychology during a bear market is different than simply a mirror image of those found in a bull market. One would think shorting new highs in a bear is a good idea, and maybe it is, but this system is not successful at capturing profit. Taking a wild guess simply from past experience, I have found that exiting quickly during bear markets tends to work better than in bull markets. Thus, maybe a modification of the exit rules to only hold a trade until the first profitable day or only hold for a maximum of three days may produce significantly better results. However, such modifications are best left for another day. To further test our shorting idea, let's now look at testing a range of look-back periods just like we did during our bull market. If our shorting concept is truly flawed, I would expect to see not much improvement in modification of our look-back period. In fact, since my wild guess is we need to exit quickly to remain profitable, I would expect to see greater losses as we continue to increase our look-back period. Likewise, I would expect to see greater profit as we shorten our look-back period. I will optimize the look-back period over the values 2-20 in increments of one. The results are in the graph below. You can click the image to see a larger view. Just as I expected. In general the shorter the look-back period, the more profitable. However, since this is our first look at the Double Seven Strategy, I don't want to over complicate it by introducing a shorting component. We'll keep it simple for now and apply our long-only strategy to several major market ETFs. Double Seven Strategy Confident the long-only trading rules are robust and appear to hold potential, let's now test this system on several major ETFs. Let's test, SPY, QQQ, DIA, and IWM. For this test we are going to use all the same trading assumptions and position sizing as we did above except for the following modifications. $50,000 starting account Risk 2% of account equity per trade P&L is not reinvested Conclusion The Double Seven Strategy does produce positive results across the four major market ETFs we tested. Is this system tradable with real money as is? Probably not. Remember, there are no stops. However, this does appear to be a great start to a viable system. I would imagine if some of the larger losing trades could be eliminated by some type of stop method, this system could be viable with real money. Downloads You can download the source code here.
  8. The vast majority of technical indicators perform a computation on the price or volume of an individual security.Â* While these indicators can provide valuable insights, most traders ignore the most effective type of technical indicators.Market Breadth IndicatorsMarket breadth indicators do...
  9. With Christmas just around the corner I thought it would be fun to see how the S&P behaves in the days just before Christmas. Do the days just before this holiday tend to be bullish, bearish or neutral? To test the market behavior just before the Christmas holiday I will use the S&P Cash index back to 1964. I will create an EasyLanguage strategy that will enter a trade X days before Christmas and close that trade on the opening of the first trading day after Christmas. Each trade is scaled based upon a 2% risk of a $50,000 trading account. To define risk I will use three times multiple of the 10-day ATR. Returns are not compounded and slippage or commissions are not deducted from each trade. Stops are not utilized in this study. Ten Days Before Christmas First let's look at the ten days before Christmas. What happens if we enter a trade X days before Christmas and close that trade on the open after Christmas? By using TradeStation's optimize feature I can systematically test each day over the historical data. The results of each test is the generated P&L for each iteration and is depicted in the bar graph below. Looking at the graph each bar on the x-axis represents the number of days before Christmas. It appears the 10 days before Christmas all show positive P&L. In general, the longer your holding period before Christmas the better. Ten Days After Christmas Using a similar trading system I will not look at entering a trade on open of trading day following Christmas and holding that trade for X days. Below is a bar graph showing the days 1-10 after Christmas. Again, each bar represents P&L and the x-axis is the number of days the trade is held. Historically, all days after Christmas in our study have returned positive results. Unlike the 10-days before Christmas, in this case it appears there is not much gain for holding beyond 5-days. The Christmas Trade Based on the information above which seems to show a strong bullish biased for the days immediately before and after Christmas, I'm going to create another strategy that will open a trade five days before Christmas and closes that trade five days after Christmas. I picked five days simply because it was the middle value (1-10) for the days before and after Christmas we tested. The results are as follows: How does the overall market regime affect the performance of this system? I decided to test this strategy against a bull or bear market. I used a 200-day simple moving average to divide the market into a bull or bear regime. I first tested taking trades only when the market is within a bull regime (above the 200-day SMA) then tested taking trades when the market is in a bear regime (below the 200-day SMA). The results show the Christmas edge holds up well for both regimes. Conclusion There certainly does seem to be a very strong bullish tendency around Christmas. Can you take advantage of this in your trading? Perhaps. Remember, the code provided below this article is not a complete trading system, but an indicator to help me gauge the market behavior around the Christmas holiday. If you have trading systems or trade a discretionary method around these days before and after Christmas you might use this knowledge to ignore short signals, or modify your exit. The EasyLanguage code used to generate the Christmas Trade can be downloaded here.
  10. The way I would handle this is to use a boolean flag to indicate when it's appropriate to trade or not. The following code example was not compiled. I just typed it up so, there may be a syntax error. But it should give you a good starting point. Variables: OK_To_Trade(false); OK_To_Trade = ( Time > 0200 ) And ( Time < 1400 ); If ( OK_To_Trade ) Then Begin // Insert trade entry logic End;
  11. In the September 2012 issue of Futures magazine, author Neil Rosenthal began a multi-part series on system development. During the first series Neil uses MetaTrader 4 (MT4) to code a simple system and demonstrates how he uses Excel to analyze the results as the first step to building a trading system. After discovering a market edge – what I call a key concept – Neil demonstrates his process of finding an initial hard stop value for his system. I found his method similar to what I use. I thought it would be helpful if I recount his method here. While many people focus on the specifics of a trade entry, trade exit is also vitally important. After you have discovered what you think is a solid “key concept” the next question you may wish to explore is: Where should the initial stop be placed? Within Neil’s article he calls this his ISL (initial stop loss). The Trading System Because we not focusing on a specific trading system I’m going use Neil’s idea of using a random entry method. That is, upon the open of the market a virtual coin will be flipped. If the coin comes up heads, we go long. If it comes up tails, we go short. This will take the focus off the trading system and place the emphasis on the true point of this post, how to determine where to place your ISL. Indeed this process is applicable to all system trading development. I’m going to trade this on Euro currency futures market and will use the 830 open (Central) as the time to open a new trade and the 1500 close (Central) to close the trade. Trades will be executed and managed on a 5-minute bar chart. Below is the TradeStation code that will act as the foundation of our trading system. If you are familiar with the steps I use to develop a trading system, you will recognize this stage of development as the “Baseline” system. This Baseline system will act as our stake-in-the-ground or reference point to compare the modified version against. vRandomNumber = Intportion( Random(100) ); If ( vRandomNumber >= 50 ) Then buy("LE") next bar at market Else sellshort("SE") next bar at market; The Results The system was executed over a five-year period ending July 31, 2012. No slippage or commissions were deducted from the results. The test generated 1,269 trades. The number of short trades (625) accounted for 49% of the trades and the number of long trades (644) accounted for 51% of the trades. As expected the number of winning trades is near the 50% mark at 51%. You can see that this system actually produced a positive net profit of $27,200 with an average trade of $21.43. If we factor slippage and commissions the system would appear to be a break-even system. We can probably improve the average profit per trade by limiting what we lose on trades that move against us. This is the purpose of having an ISL. By using an Excel spreadsheet to analyze the maximum adverse excursion (MAE) for our winning and losing trades we can help narrow down a proper value for our ISL. MAE is the amount a trade moves against us. For example, if we open a trade that immediately climbs to a profit of $100, then falls to $75 into the red before we finally close the trade at our $250 profit target, our MAE would be $75. So we now know we wish to examine the MAE of our system, but how do we do that? Trade Recorder Function Fortunately, I created an EasyLanguage function called TradeRecorder which does exactly what we need. By placing this function within our strategy code all our required trade information is sent to an Excel formatted file on our hard drive. From there it’s just a mater of cut-and-pasting our trade information into another Excel spreadsheet to analyze our results. Please read this article for a more complete description on what TradeRecorder can do. Data Analysis Now that we have all the trades in an Excel file I can take this data and cut-and-paste it into another spreadsheet called Trade Analysis, which is available at the bottom of this post. This spreadsheet is nothing fancy but will compute what we are looking for. Using the sort feature in Excel I can separate the winning and losing trades. Then I can use Excel’s built in functions to generate the mean and standard deviation of the MAE values. Below are the values generated by Trade Analysis for our example run of our trading system. In our example trading system we can see winning trades have a mean MAE of around 19 ticks. This suggests that a stop value smaller than this value will likely result in stopping-out of winning trades. In other words, the stop value would not be large enough. On the other hand, if we look at our losing trades we can see the mean MAE is 72 ticks. Such an extreme move against us is unlikely to produce a positive trade and we should be looking at cutting our losses. Notice how losing trades move strongly against our position while winning trades take much less “heat”. With this information we already have a ballpark idea on where to place our ISL. Furthermore, the same analysis can be done with the maximum favorable excursion (MFE) to help us locate a proper profit target to test. But more on that later. While it may be tempting to place a stop just beyond our 19 tick mean, a more optimal number can be found by using optimization. We are not done yet on determining our ISL. However, it will have to wait for a future post. Video Below is a video that explains in detail on how to use the Trade Recorder function with the Trade Analysis spreadsheet. These two tools can be used to help you determine your ISL for systems you develop. Both these tools are available as a free download at the bottom of this post. Downlaods The trading system code and an excel spreadsheet used in this post is available here.
  12. In this post I would like to explore a calendar based market edge. This edge is the the familiar seasonality of buying the S&P in the fall and selling in the spring. We all have heard about this one, but does it hold up to reality? SEASONALITY BIAS First, I would like to test the popular trading idea of buying the S&P in October and selling in May. I will test this on the cash market going back to 1983. A fixed number of shares (100) was used for all trades. Slippage or commissions were not taken into account. The EasyLanguage code looks like this: Inputs: iShares( 100 ), BuyMonth(10), SellMonth(5); If ( Month( Date ) = BuyMonth ) And ( MP = 0 ) Then Buy(“Buy Month”) iShares contracts next bar at market; If ( Month( Date ) = SellMonth ) Then Sell(“Sell Month”) iShares contracts next bar at market; From here we can plug into the input values the buy month (October) and sell month (November). Doing this we generate the following equity graph. It sure looks like these months have a long bias. Those are some nice results, but are these the best months? We can use TradeStation’s optimization feature on the BuyMonth and SellMonth input values to test all possible combinations. The number of possible combinations are 144. I performed the optimization and was not surprised to find the best combination of BuyMonth and SellMonth based on net proft turned out to be our original inputs. The worst combination turns out to be the exact opposite setup. Buy in May and sell in October. While this article focuses on the long side of trading only, it’s interesting to note that this period may be a time to foucus on short strategies. Below is the equity graph of the worst performing months. From 1983 to 1987 this period was producing positive results. That equity peak is 1987 and that year should be familiar. That was the year we had the massive one day market crash on October 19th known as Black Monday. The Dow Jones Industrial Average dropped 22% in one day. Since that event the behavior of market participants has been altered. This is not unlike the radical market changes which occurred after the 2000 market peek where much of the trending chacteristics of the major markets was replaced by mean reversion tendencies. So far the basic seasonality study looks interesting. However, keep in mind we do not have any stops in place. Nor do we have any entry filter that would prevent us from opening a trade during a bear market. If the market is falling strongly when our BuyMonth rolls around we may not wish to puchase right away. Likewise we have no exit filter to prevent us from exiting when the market may be on a strong rise during the month of May. It’s conceivable that the market may be experiencing a strong bull run when our usual SellMonth of May rolls around. SHORT-TERM TREND FILTER In order to avoid buying and selling at the wrong times I’m going to introduce a 20-period simple moving average (SMA) to act as a short term trend filter. This filter will be used to prevent us from immediently buying into a falling market or selling into a rising market. For example, if our SellMonth of May rolls around and the market happens to be rising (trading above the 20-period SMA), we do not sell just yet. We wait unit price closes below the short-term SMA. The same idea is applied to the buying side, but reversed. We will not go long until price closed above the short-term SMA. Within EasyLanguage we can create a buy/sell confirmation flag called BuyFlag and SellFlag which will indicate when the proper go-long or sell conditions appear based upon our short-term trend filter. if ( MinorTrendLen > 0 ) Then BuyFlag = Close > Average( Close, MinorTrendLen ) Else BuyFlag = true; If ( MinorTrendLen > 0 ) Then SellFlag = Close < Average( Close, MinorTrendLen ) Else SellFlag = true; The MinorTrendLen variable is actually an input value which holds the look-back period to be used in the SMA calculation. You will notice there is an additional check to see if the look-back period is zero. This is done so we can enable or disable this short-term filter. If you enter zero for the look-back period, the code will always set our BuyFlag and SellFlag to true. This effectively disables our short-term market filter. This is a handy way to enable and disable filters from the system inputs. Below is the equity graph with our short term filter applied. We smoothed out the equity curve a bit by reducing those drawdowns that took place during 2000 and 2008. We can see this in the slightly improved performance results. While we made slightly less in net profit, we increased our profit factor a lot and reduced our maximum intraday drawdown. LONG-TERM TREND FILTER What would happen if we also combined our short-term filter with a long-term filter? Using a 200-period SMA as a long-term filter is common practice for me. A long-term filter is used to divide the market into two major camps: bullish and bearish. It’s designed to indicate the major market trend and the dominate trading psychology so I can have my automated system adapt accordingly. If we are in a long-term bear market, why should we even attempt to purchase? During this times we may be much better off sitting on the sidelines. This seems to make sense and often adding a 200-period SMA to your trading system can make a big difference. In summary, our long-term filter is designed to keep us out of bear markets and the short-term filter is to help us better time our exact entry and exit locations. Within EasyLanguage we can create a long-term market filter by creating a boolean flag called MajorTrend which will indicate when the proper major market trend is in our favor. If ( MajorTendLen > 0 ) Then MajorTrend = Close > ( Average( Close, MajorTendLen ) ) Else MajorTrend = true; Before we make a purchase we verify our long-term and short-term flags. If ( LongMode And MP = 0 And BuyFlag And MajorTrend ) Then Buy("Season Buy") ishares contracts next bar at market Else If ( ShortMode And SellFlag ) Then Sell("Season Sell") next bar at market; Utilizing the long-term filter we reduced the number of trades, smoothed out the equity curve, reduced drawdowns and increased the average net profit per trade. Overall, a significant improvement. COMBINING OUR TWO FILTERS The next step is to combine both the long-term and short-term filters. Below is the summary showing all our different systems. The combined long-term and short-terms filters perform better than our baseline system and the short-term filter. However, when compared to the long-term filter only, it’s not as good. It seems simply applying a regime filter to our seasonal strategy produces the best results. CONCLUSION It certainly appears there is a significant seasonal edge to the S&P market. The very trading rules we used above for the S&P cash market could be applied to the SPY and DIA ETF market. I’ve tested those ETFs and they produce very similar results. The S&P futures market also produces similar results. Keep in mind this market study did not utilize any market stops. How can this study be used? With a little work an automated trading system could be built from this study. Another use would be to apply this study as a filter for trading other systems. For example, based upon our seasonality study using the long-term filter only we come up with this general filter: Take Long Trades Only When The closing price is above the 200-day moving average The current month is either October,November,December,January,February,March,April,May This general filter could be applied to both automated trading systems or even discresionary trading. It may not be much help for intraday trading, but it may. Further testing would be needed. Anyway, just being aware of these major market cycles can be helpful in understanding what’s going on with today’s markets and where they may be going in the near future. Hope you found this study helpful. VIDEO DOWNLOAD The strategy code used in this article is available as a free download here.
  13. This strategy development tool was designed for TradeStation. It's coded in EasyLanguage and it's my first version. I thought a few people on this forum may find it useful. The tool is a simple strategy to assist me in testing various stops and targets. My program is not completely unique. It’s actually based off an existing TradeStation strategy, called _Stops&Targets. I’ve taken this program and modified it with several other exit techniques. The code is available for download at the bottom of this article and is called _Stops&TargetsAdvanced. This strategy can be inserted into any chart to help you quickly test various exit techniques. Below is an image of the _Stops&TargetsAdvanced strategy applied to a chart. You can see this strategy is running in parallel with another strategy called MA Simple. MA Simple is a moving average cross over system that only generates entry signals. All exit signals are generated by the _Stops&TargetsAdvanced strategy. My code has the same stops and targets available in TradeStation’s original version, but I’ve expanded the capabilities to include the following nine new stops: Bar Count – Exit a position based on the number of bars since the position was opened. ATR Hard Stop – Exit a position based on the average true range of the market. This is a fixed stop loss. In other words the stop does not advance as a position moves in your favor. However, the value of the stop loss is updated on each bar close to adjust for the current market ATR. ATR Trail – Trailing stop based on the average true range of the market. Square root ATR Trail – This stop was explained in the article ATR Square Root. Noise Tolerant Stop – This technique was demonstrated in the article A Noise Tolerant Money Management Stop and provides a linear regression based stop which is also a non-optimized based exit. Moving Average – Exit a position based upon when price crosses beyond a simple moving average. RSI – Exit a position based on an RSI value. Day Of Week– Exit a position based upon the day of the week. By using this stop you can close all positions on a specific weekday, such as Friday. Time of Day– Exit a position at a specific time during the day. This is only used with systems that trade intraday. Next I will explain the input values for these nine new stops. ExitToTest – This indicates which stop to test. At the time of this writing there are nine stops to test. Simply enter the digit (see above for the correct digit) of the stop to activate. NumBars – The number of bars to exit a position since the entrybar. ATRLen – The number of bars to use in ATR calculation. ATRMult – This number is the ATR multiple. The value is multiplied by the ATR to generate a final value. NTStop_N – The look back period for the noise tolerant stop. MALen – The look back period to use for the moving average based exit. RSILen – The look back period to use for the RSI based exit. iDayOfWwek – The day of week to exit. 1 for Monday and 5 for Friday. ExitTime – The time of day to exit a position. Time should be expressed in military time. Video The video explains the code and how to use these stops in much more detail. A future modification I would like to add would be to base exit decisions on a different time-frame. Currently all exit decisions are based on the same time-frame in which trades are executed. It’s a common practice to base exit decisions on a higher time-frame. Download The Code The code is available here. You can freely change it by adding new stops or modify the existing stops. Please note however, this tool is for backtesting. It has not been designed or tested on live markets.
  14. Yes, the devil is always in the details.
  15. With the new month of August 1st just behind us I was wondering how does the first trading day of each month historically perform? What I want to look for are potential market edges in the S&P futures market, and SPY ETF. I created a simple EasyLanguage strategy to explore the first-of-the-month phenomena. Using a 5-minute bar chart I created a strategy called “First Of The Month”. It simply goes long at the market open (835 Central actually since the order is placed at market open and executed on the next bar) and closes the trade at the market close (1500 Central). The system has no stops and no slippage or commissions were deducted. The test was conducted from the year 2000 until June 1, 2012. Below is an equity graph of the results. It did get off to a very choppy start and the last 20 trades or so are in a strong drawdown. However, we can see that buying on the first of the month and selling at the close appears to have an edge. Remember this is not a trading system, but a study to see if we can find a potential edge to exploit. So far this looks interesting, but let’s take this further. I then used the EasyLanguage strategy to test each month independently. I was curious to see which month(s) might hold the best edge. By optimizing the “test month” input parameter over the values 1-12 we get the following graph: Reading from left to right we have each bar representing a calendar month. January on the far left and December on the right. We can see the months of February, March, April and May are strong. Also the two months of July and October are positive performing months. December and June show a lot of weakness. Shorting on the first of those months may prove profitable, but that’s for another day. Anyway, maybe someone on this list may find this study helpful. The EasyLanguage code for this market study can found here.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.