EMA Trend Momentum Candlestick Pattern Strategy
This strategy uses the Exponential Moving Average (EMA) and Awesome Oscillator (AO) to determine the market trend direction and utilizes candlestick patterns to confirm buy signals. When the EMA indicates an upward…

Overview
This strategy uses the Exponential Moving Average (EMA) and Awesome Oscillator (AO) to determine the market trend direction and utilizes candlestick patterns to confirm buy signals. When the EMA indicates an upward market trend, the AO is positive, and a bullish engulfing pattern appears, the strategy generates a buy signal. This strategy only takes long positions and does not short sell. Additionally, the strategy sets a stop-loss point to manage risk.
Strategy Principle
The core principle of this strategy is to use the EMA and AO indicators to determine the market trend direction and utilize candlestick patterns to confirm buy signals. Specifically:
- Calculate the EMA for a specified period. When the market price is above the EMA, it is considered an upward trend.
- Calculate the AO indicator. When the AO is positive, it is considered an upward market trend.
- Determine if a bullish engulfing pattern appears, i.e., the current candle closes higher than it opens, the previous candle closes lower than it opens, the current candle opens lower than the previous candle's close, and the current candle closes higher than the previous candle's high.
- When all three conditions above are met simultaneously, a buy signal is generated.
- Set a stop-loss point. When the market price falls below the stop-loss point, the position is closed to stop loss.
Strategy Advantages
- By using both the EMA and AO indicators to determine the trend, false signals can be effectively filtered out, improving the accuracy of the strategy.
- Utilizing candlestick patterns to confirm buy signals allows for capturing good entry points while confirming the trend.
- Setting a stop-loss point can effectively control strategy risk and avoid significant drawdowns.
- The strategy logic is clear and easy to understand and implement.
Strategy Risks
- This strategy is only suitable for trending markets and may generate many false signals in sideways markets.
- The choice of strategy parameters has a significant impact on strategy performance, and different parameters may lead to different results.
- The setting of the stop-loss point may cause the strategy to close positions prematurely, missing subsequent upward movements.
- This strategy only takes long positions and does not short sell, which may result in significant opportunity costs during downward trends.
Strategy Optimization Directions
- Consider adding more technical indicators, such as RSI and MACD, to further confirm trends and signals.
- Optimize the stop-loss strategy, such as using trailing stop-loss or tracking stop-loss, to better control risk.
- Introduce a position sizing strategy to adjust position sizes based on the strength of market trends and signal quality.
- Consider adding a short-selling mechanism to adapt to different market conditions.
Summary
This strategy uses EMA, AO, and candlestick patterns to determine trends and generate trading signals. It has the characteristics of clear logic and easy implementation. At the same time, the strategy sets a stop-loss point to control risk. However, this strategy also has some limitations, such as only being suitable for trending markets and being sensitive to parameter selection. In the future, the strategy's performance can be further improved by adding more technical indicators, optimizing the stop-loss strategy, introducing position sizing, and other methods.
Source Pine Script
/*backtest
start: 2023-05-23 00:00:00
end: 2024-05-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA & K-Pattern Trend Trading (Long Only)", overlay=true)
// Input Parameters
emaLength = input.int(50, title="EMALength")
aoShortLength = input.int(5, title="AOShort term length")
aoLongLength = input.int(34, title="AOLong term length")
stopLossPct = input.float(2, title="Stop Loss Percentage") / 100 // Stop Loss Percentage
// CalculationEMAandAOIndicator
ema = ta.ema(close, emaLength)
ao = ta.sma(high, aoShortLength) - ta.sma(low, aoLongLength)
// Define trend direction
isBullish = close > ema
// DefinitionKLine Pattern
bullishK = close > open and close[1] < open[1] and open < close[1] and close > high[1] // Bullish engulfing pattern
// Define buy signal
longCondition = bullishK and isBullish and ao > 0
// DrawEMA
plot(ema, title="EMA", color=color.blue)
// Calculate stop-loss point
stopLossLevelLong = close * (1 - stopLossPct)
// Execute the strategy and label the signal
if (longCondition)
strategy.entry("go long", strategy.long)
label.new(bar_index, high, text="buy", style=label.style_label_up, color=color.green, textcolor=color.white)
strategy.exit("stop loss", from_entry="go long", stop=stopLossLevelLong)Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-29. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/EMA-Trend-Momentum-Candlestick-Pattern-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- MACD Momentum Indicator Backtest StrategyPine Script · Momentum · 1h
- MoonFlag MACD Momentum StochRSI Trading StrategyPine Script · Momentum · 1d
- Multi Indicator Trend Momentum Trading Strategy with Dynamic Risk Management SystemPine Script · Momentum · 1h
- Multi factor Adaptive Momentum Tracking StrategyPine Script · Momentum · 3m
- Dual Momentum Oscillator Smart Timing Trading StrategyPine Script · Momentum · 1h