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:
Identifying doji patterns by calculating the range of open/close prices vs the overall price movement.
Checking if previous close is above/below current high/low to avoid false signals.
Judging open/close prices in relation to SMA lines to generate reversal signals.
Generating long/short signals when qualified doji patterns are identified.
The main steps in the code are:
Calculating SMA lines
Looping through candles to identify doji patterns
Checking previous close vs current high/low relationship
Confirming reversal signals based on open/close and SMA relationship
Plotting signal markers and outputting long/short signals
The advantages of this strategy include:
Doji patterns are clear and easy to identify/implement.
SMA filters help reduce false signals.
Clear long/short signals make trading operations straightforward.
Reversal trading captures short-term trends.
Flexible parameters can adapt to different market conditions.
Easy to understand and implement, beginner friendly.
Some potential risks:
Reliance on single pattern, prone to false breakouts.
No stop loss mechanism to control losses.
Bad parameter tuning can lead to over-trading.
Trend-reliant, underperforms in trending markets.
Performance relies on parameter optimization.
Solutions:
Add other filters to confirm signals.
Implement stop loss to manage risks.
Optimize parameters and limit trade frequency.
Use mainly during range-bound markets.
Continual backtesting and optimization.
Some ways to improve the strategy:
Add volume filter to avoid false breakouts.
Implement stop loss mechanisms like trailing stop loss.
Optimize parameters based on market conditions like trends.
Add other indicators to confirm signals, like MACD, KDJ etc.
Add trend determination to avoid counter-trend trading.
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.
[/trans]
/*backtest 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"}] */ //@version=4 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)