When Mining for Data, Make Sure You Have Accurate Data
Take a look at these results with no execution costs.
These results were derived by applying a simple algorithm to the natural gas futures for the past 15 or so years. I wanted to see if there was a day of the week that produced the best results with the following entry and exit techniques:
- Long entries only
- Open range break out using a fraction of the N-day average range.
- Buy in the direction of the moving average.
- Yesterdays close must be above the X-day moving average of closing prices.
- Yesterday must have a wider range than a fractional multiple of the average range.
- A fixed $stop and $profit used to exit trades.
- Other exits
- Exit at low of prior day.
- Exit at the close of today – so a day trade.
Here is a list of the parameters that can be optimized:
- daysOfWeekToTrade(1) : 1 – Monday, 2 – Tuesday…
- mavLen(20): moving average calculation length.
- volLen(10): moving average calculation length for range.
- volMult(0.25): average range multiplier to determine break out/
- volComp(.5): yesterday’s range must be greater than this percentage.
- stopLoss(500): stop loss in $
- profitTarget(1000): profit objective in $
- daysInTrade(0): 0 get out at end of day.
- llLookBack(2): pattern derived stop value – use the lowest low of N-days or the stop loss in $, whichever is closer.
Here is the code:
Why Is This Algorithm Wrong? It’s Not It’s the Data!
The algorithm, speaking in terms of logic, is accurate. The data is wrong. You cannot test the exit technology of this algorithm with just four data points per day – open, high, low, and close. If this simple algorithm cannot be tested, then what can you test on a daily bar basis accurately?
- Long or short entry, but not both.
- If the algorithm can enter both long and short, you need to know what occurred first. Doesn’t matter if you enter via stop or limit orders. Using a stop order for both, then you need to know if the high occurred first and got you long, and then later the low and got you short. Or just the opposite. You can test, with the benefit of hindsight, if only one of the orders would have been elected. If only one is elected, then you can proceed. If both then no-go. You must be able to use future leak to determine if only one of the orders were fillable. TS-18 allows future leak BTW. I say that like it’s a good thing!
- L or S position from either a market or stop, and a profit objective.
- If a long position is entered above the open, via a stop, and then the market moves even higher, you can get out on a sell limit for a profit.
- Same goes for the short side, but you need to know the magnitude of the low price in relation to the open.
- L or S position from either a market or limit and a protective stop.
- If short position is entered above the open, via a limit order, and the market moves even higher, you can exit the short position at a loss via a buy stop order.
- Same goes for the long side, but you need to know the magnitude of the high in relation to the open.
- Long pyramid on multiple higher stop or lower limit orders, but not both.
- The market opens and then sells off. You can go long on a limit order below the open, then you go long another unit below the original limit price and so on…
- The market opens and rallies. You can go long on a stop order above the open, then you can go long another unit above the original stop price and so on…
- Short pyramid on multiple lower stop or higher limit orders.
- Same as long entries but in opposite direction.
Can’t you look at the relationships of the open to low and open to high and close to high and close to low and determine which occurred first, the high or the low of the day. You can, but there is no guarantee. And you can’t determine the magnitude of intraday day swings. Assume the market opens and immediately moves down and gets you short via a stop order. And from looking at a daily chart, it looks like the market never turned around, so you would assume you had a profit going into the close. But in fact, after the market opened and moved down, it rallied back to the open enough to trigger a protective stop you had working.
The entry technique of this strategy is perfectly fine. It is only buying in the direction of a breakout. The problems arise when you apply a profit objective and a stop loss and a pattern-based stop and a market on close order. After buying did the market pull back to get you stopped out before moving up to get you out at profit objective? Did the market move up and then down to the prior lowest low of N days and then back up to get you long? Or just the opposite? In futures, the settlement price is calculated with a formula. You are always exiting at the settlement price with an MOC or setExitOnClose directive (daily bar basis.)
No Biggie – I Will Just Test with LIB (Look Inside Bar. That should fix it, right?
It definitely will increase accuracy, because you can see the intraday movements that make up the daily bar. So, your entries and exits should be executed more accurately. But you are still getting out at the settlement price which does not exist. Here are the results from using LIB with 5-minute bar resolution.
We Know the Weakness, But What Can We Do?
Test on a 5-minute bar as Data1 and daily as Data2. This concept is what my Hi-Res Edition of Easing Into EasyLanguage is all about. Here the results of using a higher resolution data and exiting on the last tick of the trading day – a known quantity.
These results validate the LIB results, right? Not 100%, but very close. Perhaps this run makes more money because the settlement price on the particular days that the system entered a trade was perhaps lower than the last tick. In other words, when exiting at the end of the day, the last tick was more often higher than the settlement price.
In my next post, I will go over the details of developing an intraday system to replicate (as close as possible) a simple daily bar-based day trading system. Like the one we have here.