How to Find the Hammer Candlestick in Your MetaTrader Candles with Python
Learn how to detect the Hammer Candle with Python on your trading bot
Learn how to detect the Hammer Candle with Python on your trading bot
Every time I hear about the Hammer Candlestick pattern, my mind instantly goes to the Hammer of Thor. Like a trading pattern crashing down in a giant explosion of lightning…
Anyways.
The Hammer Candlestick pattern bears very little resemblance to Mjolner, but it is a popular trading pattern and it can be incorporated into your trading bot.
In this article, I’ll show you how.
The hammer candlestick is thought to represent a market uptick. It typically occurs after a period of down-trending prices, and many traders use it to inform their trading.
It is a single-candle pattern.
I’ll assume that you have the following when looking to code this:
Here are the rules on how we’ll calculate the pattern:
wick_handle
) must be greater than 1.5 x the size of the wick bodywick_pommel
) must be less than 0.25 x the size of the wick bodyNote. You can definitely modify these values if you feel they’re incorrect.
Here’s the code:
# Function to calculate a green hammer
def check_green_hammer(dataframe):
"""
Function to calculate a green hammer
:param dataframe: Pandas Dataframe
:return: Boolean
"""
# Calculate bottom wick size
if dataframe.loc[0,'redorgreen'] == "Green":
bottom_wick = dataframe.loc[0,'open'] - dataframe.loc[0,'low']
top_wick = dataframe.loc[0,'high'] - dataframe.loc[0,'close']
body = dataframe.loc[0,'close'] - dataframe.loc[0, 'open']
wick_handle = bottom_wick/body
wick_pommel = top_wick/body
if wick_handle > 1.5 and wick_pommel < 0.25:
return True
return False
That’s it!
You can definitely use this code to extend your Trading Bot. For instance, in my open-source Python Trading Bot, I pass these indicators into strategies, or pass them to our website.
I love hearing from my readers, so feel free to reach out. It means a ton to me when you clap for my articles or drop a friendly comment — it helps me know that my content is helping.
❤