by Bill Brower on February 28, 2017 | Categories: Uncategorized |
At the request of our members, I am making the code to the Feb 27, 2017 Webinar available here. You can click on the link below and download the code.
Code to LBE_DJIA_Woofers Strategy
Code to LBE_DJIA_Woofers Strategy
by Bill Brower on January 6, 2017 | Categories: Uncategorized |
There are literally thousands of ways to trade for a living. Very few traders bother exploring even a small percentage of those possibilities. With few exceptions I know of no other software than Tradestation for developing and testing your ideas. If you manage to become proficient at the programming language behind Tradestation you can explore and test ideas for the rest of your life. It seems a no-brainer to become at least somewhat adept at the programming language.
One concept which by far has attracted the greatest interest is scalping. I define scalping as targeting anywhere between 1 and 5 ticks of profit on a trade. It is probable that in most cases that range could be expanded from 1 to 10 ticks. The allure of repeatedly capturing a small profit goes hand-in-hand with the risk of capturing small losses. The difficulty is to find an edge that allows the profits to outweigh the losses. This is made more difficult by the burden of overcoming slippage and commission on each trade. Longer-term strategies anticipate much larger trades and the slippage and commission burden is more easily absorbed. The hurdle for scalping strategies is often underestimated because there is a myth that limit orders avoid slippage. The real definition of slippage includes all losses that a trader may incur including failure to get filled on entries and on profit target exits, power outages, loss of Internet connection, failure on the part of Tradestation to properly fill your trades, Tradestation rejected orders, and canceled or rejected orders by the exchanges. If your back testing assumes no slippage, then you have no buffer in your historic back test for the risk. It is sadly not uncommon to find traders back testing scalping strategies without properly accounting for slippage. You would have to have an unbelievably successful strategy to capture profits in any scalping strategy in light of the true slippage.
Unfortunately it gets even worse for scalpers. Although Tradestation data appears to be live and in real-time, time is all relative. All you need to do is go on YouTube and search for “nanex high frequency trading model” to see what the professionals are up to. For them, 1/3 of a 1000th of a second is an eternity. They are placing bids and orders with such speed that it is difficult to imagine. In Tradestation the lowest timeframe of trading is using one second bars. For the professionals, this is simply laughable because it is so slow. But it gets much worse. By the time Tradestation has received the data from the exchanges and displayed it on your screen, anywhere between 2 and 5 seconds has elapsed since the tick was time stamped by the exchange. By the time your strategy fires a trade and it is placed on the exchange servers by the Trademanager even more time has elapsed. No doubt this is often a cause for the exchange canceling some orders. However, it gives professional traders a golden opportunity to get in front of your out of date order and fill it if they know it’s going to be a loser or avoid it if they think it will go your way. There is no way to compete with them at this level.
The solution is to pick longer time frames for your trading opportunities. You should be thinking of hours or even days for the duration of your trade. In this case at least you have a chance and the hurdle for slippage and commission will be more easily overcome by your average trade size. Leave scalping to the Tooth Fairy.Read More
by Bill Brower on September 17, 2016 | Categories: Uncategorized |
Curve fitting in strategy performance is when the historic back-test looks much better than the real-time performance. Here are some basic ideas to keep in mind when developing a trading strategy.
1) The ultimate objective is to have a smooth equity curve.
2) Find a way to avoid curve fitting.
3) Measuring return without measuring risk is meaningless.
4) Simple is usually better than complex.
While there are many other issues that could be discussed in regards to strategy development, these 4 are very basic. Let’s take them one at a time.
Smooth Equity Curve
When it comes to an equity curve, there are many tools that have been developed to assist in this process. For instance, the Tradestation strategy performance report includes the RINA index which does a fair job of accounting for things that could degrade an equity curve. The Pessimistic Return-to-Risk Ratio that I developed and have published in the LBE book is even better. Perhaps the best tool is to visually inspect the equity curve. Some traders believe that you should test your strategy on an in-sample dataset and when you have developed it to your satisfaction, you test it on an out-of-sample data set. If the out-of-sample data set results are satisfactory then you can be sure you have a robust strategy. The flaw with this concept is that the trader continues to modify the concept and test it again and again and again until eventually the out-of-sample dataset is satisfactory. I would argue that the trader should have used the entire dataset to begin with and looked at the equity curve to be sure that the behavior across the entire timeframe was uniform and satisfactory because that is essentially the result he has attained by throwing out all of the bad results. Either way, there is a likelihood that the result is a curve fit.
It is very difficult to avoid curve fitting because we do not have sufficient quantities of daily data to generate a lot of trades. An example of a way to avoid curve fitting would be to require that the same strategy with the same parameter settings be used on all symbols traded. In fact this was how I built and developed trading strategies for a portfolio of 36 futures symbols between 2008 and 2010. This resulted in over 2000 trades in the historic back-test. It is difficult to curve fit a strategy with that many trades. If you plan to trade stocks, you probably have far more opportunities to take trades and if you carefully select trading opportunities you might even be able to run your strategy with the same parameter set and generate more than 2000 trades. However there is a bit of difficulty with stocks because they are so highly correlated so there may be 2000 trades but in reality you may have only 200 unrelated trading opportunities. Sorting that out could be very difficult. You could drop the timeframe down to a lower level and look to day-trade but, you might be stepping into a difficult arena where professional traders with access to high-frequency data lines and vast sums of money can outgun you. Still there are places that you can trade where the high-frequency traders and the big firms don’t like to play. For instance the Russell 2000 future is generally considered too illiquid for those types of firms.
Any measure of a strategy performance must include both return and risk. To any seasoned trader this seems totally obvious but there have been countless clients of mine that have been enamored by a measure of a strategy’s return. That could be net profit, percentage of winning trades, average winning trade, or a number of other measures. A successful trader needs to understand that trading is more about managing risk than measuring profit. It is like a poker game where your goal is to find a way to keep your seat at the table. In my experience a very good trading strategy is likely to have the same annual return as risk. So if you plan to make 15% annually you are likely to have a 15% drawdown during the year. Usually drawdowns are greater than expected by any testing measure you can perform so, when you’re drawdown exceeds the 15% you may be knocked out of the game.
Building a trading strategy should always start with the simplest algorithms and build-up to more complex. A common error is to combine more than one concept in the 1st go. This means there is no way to measure to what extent one concept is positively influencing the performance. You should always be able to quantify the extent to which each element is positively contributing to the performance and this can only be done by testing the components one it time or at least testing 1 component and then testing that component with another to see if the 2nd component improves the result. This is true even for the simplest concepts like profit targets, stop losses and trailing stops. The more components that are added to a trading strategy the easier it is to end-up with a result that is totally curve fitted. For instance, when you add a profit target and optimize it, you may find that only a small percentage of the trades are impacted. Let’s say you had a strategy that took 200 trades and the profit target affects 15 trades. By any measure, 15 trades is not a significant data sample to generate reliable statistics. Therefore it is a curve fit. I suspect that most traders don’t understand the risk of this kind of curve fitting.
While the main focus of the EasyLanguage Learning-by-Example training program is to teach you the programming language, a good deal of the material will be presented in a way to teach you good practices in strategy development. Some of these exercises are specifically directed at strategy development and teach you how to measure performance of individual algorithms in an objective way. You will also be learning techniques that will help you avoid curve fitting and allow you to build more robust trading strategies. Some of these techniques include learning how to use the Pessimistic Return-to-Risk Ratio, using random entry/random exit routines for bench testing algorithms and even measuring performance using Portfolio MCS.
by Bill Brower on September 1, 2016 | Categories: Uncategorized |
Black hat hackers seeking computers for the purpose of enslavement in their bot army look for unprotected or poorly protected machines that allow easy entry of malware and Trojan programs. The white hat hackers actually invite these malware programs into specially configured computers to catch the malware so that it may be examined and defeated. They call those machines honeypots.
The Tradestation strategy optimizer can behave like a honeypot trapping the unaware user by providing the appearance of astonishingly good results. I have seen this happen many times over the years. I even have one client who has spent years modifying and tweaking the very same strategy and running it through the optimizer attempting to eke out slightly better performance. Yet every time he tries to trade the strategy, he quits in frustration at the subpar performance. The strategy takes literally thousands of trades, so there is no problem with curve fitting issues. The problem is that the average profit per trade on the S&P 500 E-mini is only $15, and that is without any allowance for slippage. He argues that there is no slippage because he uses limit orders for entries and exits.
The problem is that there is always slippage even with limit orders. Slippage is a catchall category to allow for unexpected events, not just to provide for the difference between where you thought you were going to get filled and the actual fill. Slippage must cover failing to get filled at your limit order price to exit a profitable trade. It covers the failure to get filled on entries that clearly moved to your profit target exit. It also covers data errors, internet connectivity issues, and Tradestation execution issues. So in reality my clients program which shows phenomenal profitability in the strategy performance report, is really phenomenally unprofitable.
He has been caught in the optimization honeypot. When that happens, the results appear irresistibly good. The reason this happens is because when the optimization is run without allowance for reasonable slippage, Tradestation identifies parameter settings that maximize net profit, at the expense of minimizing average profit per trade. So for years my client has been focusing on tweaking parameter settings that generate a mirage of high net profit. If he had instead included some reasonable slippage, the optimizer would have directed him toward completely different parameter settings. This would have had a dramatic effect on the actual strategy development because he would be focusing his efforts to maximize the performance of a completely different set of trades than the ones he has been looking at. I am not only talking about a vast amount of time and effort on his part but also significant investment cost in programming his strategy. His explanation was that he made an overall allowance for slippage at the end of his optimization and this was the same thing as allowing some slippage on every trade. That was his fatal flaw. They are not the same. There is no way for him to be directed to an alternate set of parameter settings so his focus for strategy development was always in the wrong direction.
The optimizer is indeed a very powerful tool and very useful in the right hands. Like any tool it is open to abuse and misuse. I think perhaps more often than not it is misused by most who have ever worked with Tradestation developing strategies. Most of them are no longer trading or even using Tradestation. Don’t allow yourself to be mesmerized by bogus results generated by the optimizer. Always allow for reasonable slippage even if you are using limit orders.Read More
by Bill Brower on August 10, 2016 | Categories: Uncategorized |
Measuring Return without Measuring Risk is Meaningless
Frequently I hear a trader or say something like “my strategy wins 85% of the time” or “it made $280,000 over the last 10 years” or “it has a profit factor of 4.1”. I have never heard someone measure their performance by saying something like “my strategy has a 50% chance of returning $36,000 per year with a 1% chance of a $50,000 drawdown per year”. Do you see the difference? The last statement quantifies return and risk whereas the 1st 3 statements ignore risk altogether. It always surprises me that traders, even seasoned traders, can fall into that trap. New traders are particularly dazzled by strategy returns and almost always gloss over the potential risk. The Tradestation strategy performance report does have some statistics that consider both return and risk but it takes some digging to find them. While all of them have some weaknesses, the Rina Index is probably the best. Don’t find yourself falling into the trap of measuring return without measuring risk. You can find more information about this on my prior blog “Measuring Strategy Performance” from May 27, 2016.
by Bill Brower on July 7, 2016 | Categories: Uncategorized |
Although you can find numerous helpful videos on Youtube related to the use of TradeStation, perhaps the best source of videos is from TradeStation itself. There are all kinds of instructional videos including many tutorials that show you how to use the platform. Even experienced users will learn from their videos. You can access the entire list, which is quite extensive, through their App Store. From the Charting menu, select INSERT/INDICATOR and hit the Import button at the bottom. Select to import from the App Store. A browser will load and take you there. Then search for VideoStation which is a free application that you can download. Follow the instructions from that page to complete the download. Then whenever you want to see any of their instructional videos, you simply need to go to the menu and select FILE/NEW/TRADING APP WINDOW and select VideoStation from the list of available applications.Read More
There are 2 settings that can be applied to strategy testing to control the number of shares or contracts to trade. You can trade a fixed number of shares or a fixed dollar amount. The setting is accessed from the Charting menu under Format/Strategies and selecting the button called “Properties For All” where you will see a small window containing the controls (see below). If you are trading stocks you will want to select the setting “Dollars Per Trade” if you are back-testing. This is necessary to compensate for the way that stocks are back adjusted for stock splits. As an example if you plot Apple (AAPL) daily data going back 20 years you will see that the price 20 years ago is listed at 93 cents. While it never actually traded at that price, the back-adjust for stock splits pushes the price down toward zero. So if you were testing a fixed number of shares, say 100, and made a 10% gain you would net about $9.30. This would then be combined with trades occurring more recently when prices were around $100 and a 10% gain would net $1,000. Obviously you would not combine the results in any meaningful way because they are scaled differently. (more…)Read More
by Bill Brower on May 30, 2016 | Categories: Uncategorized |
The MaxBarsBack (MBB) setting is usually set to automatically detect the required lookback for indicators but strategies are by default set to a lookback of 50. Before you become proficient at TS you are bound to be baffled by the issues of MBB.
Here is one example. You write two pieces of code; one is a system and the other is an indicator. They both use an exponential moving average of 50 bars. When you place them both on the same chart of data, you notice at the beginning of the chart the system is taking trades that appear to be inconsistent with the indicator. The problem is the MBB. Since the exponential moving average indicator only requires a MBB of 2, it begins its computations and displaying results on the second bar of the chart. The system begins computing on the 51st bar of the chart because the default lookback is 50. (more…)Read More
by Bill Brower on May 27, 2016 | Categories: Uncategorized |
I am frequently queried about the best way to determine how good a strategy is. TradeStation provides a lot of metrics on their “Strategy Performance Report” but most of them do a lousy job of measuring “goodness”. If I had to define “strategy goodness”, it would include a list of properties as follows:
o High net profit
o Lots of trades
o No outlier big win trade
o High percent of profitable trades
o Small drawdowns
o Short drawdowns
o Staying in market as little as possible
o Smooth equity curve
The problem with most of the metrics provided by the TS “Strategy Performance Report” is that they measure the goodness of only one of the properties listed above. This can distort your perception of the performance. The most common mistake is looking at “net profit” which is the standard metric used to rank performance in the “Optimization Report”. However, a high net profit often comes at the price of having one big outlier winning trade. You can spot this problem most easily be looking at the equity curve. (more…)Read More
by Bill Brower on May 22, 2016 | Categories: Uncategorized |
Drawing trend lines on a chart has always been a significant body of work for technical traders. Since very early on, TradeStation came equipped with drawing tools that made it easy to manually apply trend lines to charts as well as to create them automatically from the code of an indicator or other analysis technique. Applying them manually to a chart gives you the freedom to apply them to price bars or even indicators in a subgraph. This is commonly done to show the occurrence of divergence. However, this becomes a problem to do mechanically from the code in an analysis technique because trend lines are assumed to be plotted on price bars in Data1. An exception to this is the feature of OOEL to allow trend lines to be plotted on price bars in Data2 or other data series. However, that is still not the same thing as applying a trend line to an indicator in subgraph 2. (more…)Read More
by Bill Brower on May 13, 2016 | Categories: Uncategorized |
Market prices are determined by traders issuing market orders. That is to be distinguished from those using limit orders. A trader that absolutely must get filled immediately issues a market order. The market seen by traders is composed of a bid price and an ask price. This is known as the bid ask spread. Market orders always get filled at an unfavorable price by the execution on the opposite side of the bid ask spread. So a market order to buy will be filled at the ask price or higher and a market order to sell short will be filled at the bid price or lower.
If we wish to track volume and distinguish between up volume and down volume we would look to see whether fills take place at the bid or ask prices. So if 100 shares are purchased at the ask price that would be classified as up volume because the trader issued a market order to buy and was forced to cross the spread and get filled at the ask. The opposite would be true for a market order to sell short which would get filled at the bid price and is consequently considered down volume. (more…)Read More
by Bill Brower on May 12, 2016 | Categories: Uncategorized |
Beginning with TradeStation 2000i and carried along in versions of TS5.0 through TS8.6, there was a command that allowed the programmer to access the name of the strategy that was running in a chart window. That command was getstrategyname. This was particularly useful to traders that wished to perform strategy testing and save the test results say from an optimization with custom code to a file. For reasons that have never been revealed, TradeStation decided to abandon this command and disabled it. So it was that for several years there was no way to access the name of the strategy from within Easylanguage. (more…)Read More
© 2020 Inside Edge. All Rights Reserved.