{"id":693,"date":"2007-07-21T18:25:29","date_gmt":"2007-07-21T18:25:29","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/07\/21\/system-design-pitfalls\/"},"modified":"2007-08-18T23:36:14","modified_gmt":"2007-08-18T23:36:14","slug":"system-design-pitfalls","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/07\/21\/system-design-pitfalls\/","title":{"rendered":"System-Design Pitfalls"},"content":{"rendered":"
When you are designing a real-time trading system, many things can go wrong. This post is intended to alert you to some of the potential pitfalls. However, that is all it can do. Only experience can teach you how to prevent them. Be aware that even the most experienced designers will make some of these mistakes repeatedly. <\/p>\n
Since documenting all potential pitfalls with coding examples would consume too much time and space, they are, for now, only briefly commented on. Most of them will trigger a user response of “Oh yeah, that happened to me!”. If you need a more detailed explanation you can post questions in a comment to this post <\/p>\n
No rules exist to prove that a trading system is free from coding or logical errors. However, two indicators are fairly reliable in suggesting you may have a problem:<\/p>\n
1) Your profits are simply too good to be true. In this case you have no choice but to work through the code line by line, trying to find lines of code that look into the future. If that doesn’t reveal any errors, then you would have to inspect the plotted signals and trade list trade by trade.
\n2) Your system is very profitable trading Long but not Short, or Short buy not Long. When this happens, you may have an error in either the Long or Short parts of your code, and comparing the two sections will often reveal the problem (this only works for reversal systems). However, it could also be that your code is correct but that your trading principle is overly trend sensitive. This would almost certainly get you in trouble when the trend reverses. In this case no other cure exists than to re-think the basic system.<\/p>\n
When designing high-frequency trading systems, i.e., those whose trade durations are in minutes, everything changes, and many traditional procedures fall apart. Internet delays, data delays, bad data (spikes), temporary system freezes (Windows sometimes has a mind of its own!), lagging status reports, TWS problems, etc., all become critical issues that will prevent you from obtaining a close match with the Backtester.<\/p>\n
Many of these problems will only surface when you start trading real money. Hence, the final stages of developing a trading system should always involve trading real money. Here is where the Interactive Brokers account simulator (paper-trading account) may be an indispensable tool since you can test your system in real time without committing real dollars. But, since the market does not see your trades, even paper-trading results will differ from trading real money. In general, the faster you trade, the greater your real-trading results will deviate from your backtest results. You should also be aware that commissions play a much greater role on performance of high-frequency trading systems because trade profits are smaller.<\/p>\n
No matter how you go about it, troubleshooting a complex trading system will almost always be a tedious and boring job that could keep you busy for several days or weeks. If you find that certain problems continue to resurface, they are likely related to your personal development style, and you may be able to write some code that checks for these specific problems. See the Debugging<\/a> category for some ideas.<\/p>\n The list below, which is not exhaustive, is presented to caution you that many areas can lead to problems. Some are obvious, while others may be expanded on as needed and time allows. <\/p>\n – High\/Low precedence (contrary to EOD where the Backtester is unable to determine which came first, the entry\/exit or the high\/low, in realtime there can be no ambiguity in price precedence). Edited by Al Venosa<\/p>\n","protected":false},"excerpt":{"rendered":" When you are designing a real-time trading system, many things can go wrong. This post is intended to alert you to some of the potential pitfalls. However, that is all it can do. Only experience can teach you how to prevent them. Be aware that even the most experienced designers will make some of these […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[65],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/693"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=693"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/693\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=693"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n– Data Delays (real-time data may be delayed for various reasons and time periods (Internet delays, lack of quotes, packets vs. ticks, etc.).
\n– Low Liquidity (there may be no-volume trading periods).
\n– Data Holes (bars with no trades).
\n– Data Spikes (high spikes without volume may trigger trades).
\n– Data Padding (a bar without data may be padded).
\n– Premature Padding (the last bar may be a padded bar).
\n– Data Accuracy (prices you receive aren\u2019t always accurate).
\n– Random Slippage (you will rarely get the expected price).
\n– Breakout slippage (you will rarely get the Breakout price of your system).
\n– Survivorship Bias (companies that didn\u2019t do well and stopped trading won\u2019t be in your database, i.e., you are working above average stocks).
\n– Lucky Trades (a series of lucky trades may look like good performance).
\n– Parameter Over-Optimizing (optimized parameters are rarely stable over time).
\n– Design Over-Optimizing (frequent testing is like running an optimization and may be leading to false conclusions).
\n– Out\u2013of-Bound Prices (with PriceBoundChecking turned ON, AmiBroker forces the trade price within the High-Low range, this may hide pricing errors).
\n– Price Rounding (prices may be rounded or truncated by the broker).
\n– Wrong Use of >= and <= (when using both <= and >= in the same statement, only the first equal condition will ever be seen).
\n– Comparing Floating Point Numbers (calculated values can have many decimal places, either round values or use the AlmostEqual()).
\n– Chart Justification (make sure you are looking at the Last bar!).
\n– System Mortality (no system will work forever).
\n– Sharing Trading Systems (sharing systems with other traders may result in over-trading a system).
\n– Being Duped by a Trend (a rallying ticker may make your system look like the HG (holy grail).
\n– Tricking AmiBroker (AmiBroker has its limits; it is possible to write esoteric code that will produce wrong results).
\n– Order Visibility (placing your order for every trader to see may influence the orders they place).
\n– Making the Market (extreme example: if you place a MKT order during a no-trading period you will change the chart).
\n– Window\/Pane Execution Order (when passing variables between panes or windows do not assume that they execute in a fixed order, more).
\n– Trading at the Open (order execution at the start\/end of day is different from midday because of volatility and data delays).
\n– IB Data Snap Shots (snapshots are only representative of prices traded).
\n– Trade Delays (make sure you understand your trade delays when backtesting).
\n– EOD and Intraday Gaps (There is no time interval in RT gaps).
\n– Time Zones (make sure your computer and database timezones are properly set).
\n– Very Short Time-Frames (prices jump and are less contiguous).
\n– Setting LMT Prices (consider rounding for faster order executions).
\n– 24-Hour vs. RTH (Regular Trading Hour) Backtesting (extended hours can rarely be traded like RTH due to huge bid\/ask spreads and low volume).
\n– Static Variables Naming (use unique names for your static variables).
\n– Incorrect Computer Time (computer time offset from market time can cause real problems).
\n– Look-Ahead Problems (not all look-ahead coding problems are obvious).
\n– Buy\/Sell Precedence in a Loop (be aware that AB and custom AFL loops enforce a Buy\/Sell priority).
\n– RT Candle Discrepancies (RT Candles may be different from later backfills, especially in the opening print).
\n– Bars Loaded (consider bars-loaded with respect to execution speed and loops).
\n– Signal lifetime (signal strength quickly decays over bars in high frequency trading).
\n– SameBarExits (Sell signals may act as a qualifier for Buy signals).
\n– Designing systems based on High and Low triggers (these may fill in the Backtester but not in real trading). more…<\/a>
\n– Using the wrong CommissionMode and\/or CommissionAmount can make any system look good, or bad…
\n– Using zero TradeDelays is OK if you code the delays in your system’s code, else you may be looking into the future.<\/p>\n