Doji Candlestick Reversal Trading Strategy

Author: ChaoZhang, Date: 2023-09-27 16:40:28


This strategy identifies doji candlestick patterns and combines SMA to determine reversals for trading. It generates trading signals when doji patterns form and the open/close prices are outside the SMA lines. Bullish signals are generated on hanging man lines and bearish signals on shooting star lines.


The main principles of this strategy are:

  1. Identifying doji patterns by calculating the range of open/close prices vs the overall price movement.

  2. Checking if previous close is above/below current high/low to avoid false signals.

  3. Judging open/close prices in relation to SMA lines to generate reversal signals.

  4. Generating long/short signals when qualified doji patterns are identified.

The main steps in the code are:

  1. Calculating SMA lines

  2. Looping through candles to identify doji patterns

  3. Checking previous close vs current high/low relationship

  4. Confirming reversal signals based on open/close and SMA relationship

  5. Plotting signal markers and outputting long/short signals


The advantages of this strategy include:

  1. Doji patterns are clear and easy to identify/implement.

  2. SMA filters help reduce false signals.

  3. Clear long/short signals make trading operations straightforward.

  4. Reversal trading captures short-term trends.

  5. Flexible parameters can adapt to different market conditions.

  6. Easy to understand and implement, beginner friendly.


Some potential risks:

  1. Reliance on single pattern, prone to false breakouts.

  2. No stop loss mechanism to control losses.

  3. Bad parameter tuning can lead to over-trading.

  4. Trend-reliant, underperforms in trending markets.

  5. Performance relies on parameter optimization.


  1. Add other filters to confirm signals.

  2. Implement stop loss to manage risks.

  3. Optimize parameters and limit trade frequency.

  4. Use mainly during range-bound markets.

  5. Continual backtesting and optimization.

Improvement Areas

Some ways to improve the strategy:

  1. Add volume filter to avoid false breakouts.

  2. Implement stop loss mechanisms like trailing stop loss.

  3. Optimize parameters based on market conditions like trends.

  4. Add other indicators to confirm signals, like MACD, KDJ etc.

  5. Add trend determination to avoid counter-trend trading.

  6. Optimize lookback period to balance frequency and quality.


This strategy uses doji patterns with SMA for efficient reversal trading. It has advantages like simple rules and easy trading. But also has risks and areas for improvement. With continual optimization it can become a solid short-term trading system.


start: 2022-09-20 00:00:00
end: 2023-09-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

strategy("Doji Reversal", overlay=true)

smaPeriod = input(title="SMA Period", defval=10, minval=0)
tolerance = input(title="Tolerance", defval=0.1, minval=0)

lookbackEnd = input(title="End", defval=2, minval=0)

avg = sma(close, smaPeriod)
signal_long = bool(false)
signal_short = bool(false)

for i = 1 to lookbackEnd
    is_doji = (abs(close[i] - open[i]) / (high[i] - low[i])) < tolerance
    signal_long := signal_long or ( is_doji and (close[i-1] <= high[i] or i == 1) and close[i-1] > high[i] and high[i] < avg and close > open )
    signal_short := signal_short or ( is_doji and (close[i-1] >= low[i] or i == 1) and close[i-1] < low[i] and low[i] > avg and close < open )

plotshape(signal_long, "LONG", style=shape.triangleup, size=size.normal)
plotshape(signal_short, "SHORT", style=shape.triangledown, size=size.normal)

strategy.entry("LONG", strategy.long, when=signal_long)
strategy.entry("SHORT", strategy.short, when=signal_short)