Step Three — Defining principles for building a trading system: how to avoid overfitting

Artem Stepanenko
4 min readMar 7, 2024

--

In this article, we advance our journey in crafting a Binance futures trading bot. Building upon our custom library of Japanese candlestick patterns and our foray into data collection and preprocessing, we now delve into the fundamentals of constructing a robust trading system, with a pivotal focus on circumventing overfitting — a crucial step to ensure the reliability and performance of our trading robot.

First and foremost, it is necessary to define the principles of building a trading system, as false and unfounded assumptions embedded in the concept will certainly mislead us from the very beginning. Our task here is to avoid fitting our trading systems to the historical data we have at our disposal. Obviously, picking a beautiful equity curve by combing through millions of available options is not a difficult task, but we are only interested in an option where our trading system will be stable in the future, when applied to new data. For this, we need to initially limit ourselves to a set of rules that reduce the risk of overfitting.

Of the principles that we decided to follow in this project, the key ones are the following:

A) Simplicity of the idea

The very first thing that comes to mind when we talk about how Japanese candlestick patterns could be applied is to use them literally, according to the interpretation embedded in their names and descriptions. For example, if we talk about Bullish Harami or Bullish In-trend Marubozu, their names imply that these patterns give bullish signals, and there are reasons to expect an increase in the asset’s price.

Thus, it would be interesting to assess the strength of the pattern’s signal without tying it to other technical analysis indicators and without overcomplicating the trading system. And if the pattern’s signal allows for a statistical advantage in trading, then it is the robot’s task to use it. If, however, the pattern’s signals do not provide a statistically significant effect, we do not include the use of that pattern in our suite of trading robots.

B) Limited time horizon of the trading signal

Designing a trading system, we proceed from the most stringent scenario for ourselves, considering as a key factor that time series do not allow predicting the direction and dynamics of exchange prices in the long term.

In other words, developing a trading system, we focus on the limited time horizon of trading signals. This is important for accounting for the unpredictability and chaotic nature of market prices in the long term. To reduce risk and increase forecast accuracy, our system uses signals from Japanese candlestick patterns only over short time spans, not expecting accurate forecasts over long periods. In turn, such design implies action of pattern signals within a range of a few trading periods and limited holding of open positions.

C) Identical properties parameters for patterns of the same group

For Japanese candlestick patterns of the same group (for example, all Marubozu or Hammer patterns), we select identical properties parameters, which also helps to reduce the risk of fitting the results to historical data and ensures the universality of the approach.

D) Application to all available trading cryptocurrency pairs

Not limiting ourselves to a narrow (or even wide but limited) list of trading pairs when designing a trading system, we complicate the scenario of fitting the trading strategy for ourselves and set a criterion for searching for pattern parameters that work for most traded instruments.

E) Applicability on all timeframes

This criterion of universality is also designed to reduce the risk of fitting to specific cyclic patterns characteristic of a particular time interval. Different timeframes can demonstrate different price behavior patterns, and a system that works stably within one timeframe may stop working in others. The application of this principle should increase the overall adaptability and resilience of the strategy to changing market conditions without dependency on the influence of time cycles of a specific timeframe.

F) Limiting losses within each trade

The trading strategy should include strict rules for minimizing losses within each trade. Since our patterns do not predict the future but only signal statistical anomalies, it is reasonable to assume that a significant portion of signals will be erroneous. Thus, it is necessary to provide for stop-losses in the trading system. This will protect capital and ensure the resilience of the trading system, preventing significant losses in case of statistically unfavorable market conditions.

G) Continuous testing and validation of the system on current data

An important aspect of our approach is continuous testing with a division of historical data into training and testing samples. It is necessary to ensure that the trading system is not subject to “overfitting” on historical data and is relatively stable on the test sample. This will allow us to ensure that the system adapts to current market conditions, which is key to the stability and efficiency of our trading bot.

This may not be the most exciting article, but probably the most important one: without defining the principles we will follow, testing any hypothesis on historical data, and then launching it into production, we risk losing control over the efficiency of our robot’s work and, ultimately, over our capital.

Armed with the principles of building a trading strategy, we move on to the next steps of designing the trading robot:

Stay tuned as we tackle these challenges and move towards launching our trading robot.

Thank you for reading! Your comments and feedback are greatly appreciated.

--

--