Add the Doji Star Candlestick Detector to Your AutoTrading Bot
Doji Star patterns are one of the most important tools for analyzing financial markets, especially for Forex and Crypto traders. By understanding these patterns, traders can better analyze and predict trends in the market — and even potentially identify profit opportunities.
But how can you implement this pattern detection into your trading bot? Here’s what you need to know.
What Is a Doji Star Candlestick Pattern?
A Doji Star candlestick pattern occurs when the open and close of the candlestick are close together, with relatively long wicks. Here’s an example I constructed using the AlgoQuant AutoTrading Bot and the code I’m about to demonstrate. This occurred on the USDJPY Raw pair, 30 Minute timeframe, February 18, 2023:
How can the Doji Star pattern help my AutoTrading Bot?
Many traders believe that a Doji Star candlestick indicates a potential reversal in a pricing direction. Specific types of Doji Stars, such as dragonfly, gravestone, and long-legged can be used to provide clearer indicators of price movements or consolidation.
Adding a Doji Star pattern detector to your trading bot provides you with a few options:
- Enacting an ‘emergency sell’ provision to reduce risk on a potential market reversal.
- Enacting opposite side BUY / SELL trades based on predicted price movements.
- Changing algorithm application if the market is indicating consolidation / breakout
Here’s How to Implement Doji Star Candlestick Detection on Your AutoTrading Bot
Step 1: Install TA-Lib
TA-Lib is the premier indicator analysis library for any kind of technical analysis. It’s blazingly fast, powerful, and used by many of the worlds top traders and platforms.
Installing it is pretty simple (if a little time-consuming). I’ve included the five basic steps below:
- Download TA-Lib from here
- Unzip and move to
C:\
- Get and install Windows Build Tools (this takes the most time!)
- Compile TA-Lib
- Install
pip install TA-Lib
If you’re looking for a more in-depth tutorial, including common error messages, here’s a link to a post on the subject.
Step 2: Add the following code to your indicator library
Filename: doji_star.py
import talib
def doji_star(dataframe):
"""
Function to calculate the doji star indicator. This is a candlestick pattern, more details can be found here:
:param data: dataframe object where the Doji Star patterns should be detected on
:return: dataframe with Doji Star patterns identified
"""
# Copy the dataframe
dataframe = dataframe.copy()
# Add doji star column to dataframe
dataframe['doji_star'] = 0
# Calculate doji star on dataframe
dataframe['doji_star'] = talib.CDLDOJISTAR(
dataframe['open'],
dataframe['high'],
dataframe['low'],
dataframe['close']
)
return dataframe
Step 3: Use the Function
Here’s how the function works:
- Pass the function a dataframe with the columns
open
,high
,low
close
. These values are required to determine a Doji Star candlestick. - The dataframe can be any arbitrary value — I’ve tested it on up to 50,000 candles with no discernable lag
- The function will return a dataframe with the following values in the
doji_star
column. 0 = No Star. 100 = Green Star Candle, -100 = Red Star Candle - Add this to your autotrading bot and then your own decision logic afterwards
Use the AlgoQuant AutoTrading Bot
If you’d like to skip all these steps and simply get straight into it, head to the AlgoQuant AutoTrading Bot GitHub and download. Then, run one of the following commands:
- To get a dataframe of a symbol from MetaTrader:
python .\main.py --Exchange 'metatrader' --doji_star -timeframe "M30" --symbol "USDJPY.a"
- To add in a Plotly Graph (fantastic for exploring the data):
python .\main.py --Exchange "metatrader" --Explore --doji_star --timeframe "M30" --symbol "USDJPY.a" --Display
If you run the second command, here’s an example of what you might get (options symbol=BTCUSD.a
, timeframe=M30
):