Turning Candlestick Reversal Patterns in Objective Rules for Algo-Trading

Certain candlestick patterns have been found to be potential indicators for trend reversals across a wide array of markets. We sometimes run into an issue, however, in that, with the huge number of options we have available to us in terms of currencies equities, commodities, etc. we may miss out on catching these reversals, essentially leaving money on the table when we could have jumped on a trend right at its apex. This article represents the first step of systematizing these patterns so that we can roll them out for hundreds of markets without having to actually keep our eyes on every chart ourselves. My goal for this article is defined as follows -> to take common candlestick reversal patterns and turn them into systematic rules and/or pseudo-code so that they can then be incorporated into algorithms.Points to NotesMy coding background is centered around Python, so some of the lexicon that I use is similar to what you might find in a typical Python program. I’ve tried to keep any code as close to pseudo-code as possible, but I wanted to clarify a couple of points just before you read on in this article.

  • The letters and numbers above any 2 or 3 candlestick patterns represent the index that we would find that specific candle in an array. For example, the first candle in a two candlestick pattern might be found at index i and the second might be found at index i+1.I have assumed that we have 4 arrays available to use which are named by the data that they represent (the variable Open will contain all historical opening prices of our asset in question).To access the i-th element of the closing prices variable, we use the notation Close[i].Close[i-26:i] means take all previous 26 values of the dataset. This will be used to calculate any simple moving averages, which are denoted as SMA.The function abs() will return the absolute (positive) value of the sum calculated within. This is useful if we don’t know if a candle is red or green and that doesn’t impact the presence of a reversal pattern.

EngulfingBearish and bullish engulfing are 2 candlestick patterns. They involve a small red or green candle initially, followed by a much larger candle of the opposite color. From a fundamental standpoint, we usually tend to view these moments as the final resistance from the few remaining bulls or bears. The opposing investors take over and drive the price against the previous direction. The size of the second candle is significant, as its purpose is to entirely “engulf” the first candle, signaling a strong intent to reverse the trend.

HammerThe hammer tends to occur after a downtrend. It is a bullish signal, as it symbolizes a loss of momentum for bears in the market. The long lower shadow is indicative of a strong push from bears earlier on in the time period, but ultimately the distance between the low and the close tells us that towards the end, momentum swung back to the bulls and they closed with an advantage. A small upper shadow also tells us that there wasn’t much bear pressure bringing the price back down. We expect the price to rise after this candle.

Hanging ManThe hanging man looks exactly the same as the hammer but occurs in an uptrend. As we did in the previous example, we use the position relative to a moving average to determine the direction an asset is trending. This is the first condition that should be assessed and if this is not met, we wouldn’t be looking for this candle at that specific point in time.

Size is another significant feature that has to be considered here. The size will naturally vary depending on the asset class you’re looking at. I try to stay as far away from specific numbers where possible since this won’t translate to every situation and that’s the goal we are trying to achieve. Having a body of maximum length 15 might be acceptable when looking at Tesla stock for example, but would be if we were studying the GBP/USD currency rate. The best solution I have found is to use relative calculations. I compare the lower shadow with the body, the upper shadow with the lower shadow, to ensure that the overall shape of the candle is kept constant.

StarsThe stars are 3 candle patterns and consists of two types, the Evening Star and the Morning Star. The Evening Star is our bearish indicator and begins with a large green candle. It is followed by a smaller candle which can be either red or green and which I define to be less than half the length of the original candle. The smaller candle is then followed by a large red candle, which must be at least the same size as the original candle. The Morning Star is our bullish version and essentially looks exactly the same as the Evening Star, but the colors are flipped.

There are many more candlestick reversal patterns that we can look to turn into a set of concrete rules. In further articles, I will look to systematize more complex patterns, such as a head and shoulders, cup and handle and double bottoms. I will also add some writing on the next step of our process, in which we convert this pseudo-code into actual Python code, so keep an eye out for that!

#algorithmic-trading #forex-trading #algorithms

Turning Candlestick Reversal Patterns in Objective Rules for Algo-Trading
1.55 GEEK