Strategy vault / Trend following
Adaptive Price Crossing Moving Average Trading Strategy
The Adaptive Price-Crossing Moving Average Trading Strategy is a quantitative trading method based on the Hull Moving Average (HMA). This strategy generates buy and sell signals using price crossovers with the HMA…

Overview
The Adaptive Price-Crossing Moving Average Trading Strategy is a quantitative trading method based on the Hull Moving Average (HMA). This strategy generates buy and sell signals using price crossovers with the HMA, while implementing fixed stop-loss and take-profit levels to manage risk and reward. The strategy employs a 104-period HMA as its primary indicator, combined with price crossovers to trigger trades.
Strategy Principle
The core of this strategy is the use of the Hull Moving Average (HMA) as the primary indicator. HMA is an advanced moving average that responds quickly to price changes while reducing lag. The strategy logic is as follows:
- Calculate the 104-period HMA.
- Open a long position when the price crosses above the HMA.
- Open a short position when the price crosses below the HMA.
- Set fixed stop-loss ($1.25) and take-profit ($37.5) levels for each trade.
- Use 2 contracts for each trade.
The strategy tracks open positions to ensure no new positions are opened while an existing one is active. Once a trade is closed, the system resets flags to allow new trade signals to take effect.
Strategy Advantages
- Adaptability: HMA quickly adapts to market changes, reducing false signals.
- Risk Management: Uses fixed stop-loss and take-profit levels, effectively controlling risk for each trade.
- Simplicity: Trading rules are clear, easy to understand and execute.
- Bi-directional Trading: Captures both upward and downward opportunities, increasing profit potential.
- Automation: The strategy can be fully automated, reducing human intervention and emotional influence.
Strategy Risks
- Frequent Trading: May generate excessive trading signals in volatile markets, increasing transaction costs.
- Fixed Stop-Loss/Take-Profit: May not be suitable for all market conditions, potentially exiting too early or missing large trends in some cases.
- Reliance on a Single Indicator: Depending solely on HMA may underperform in certain market environments.
- Lag: Although HMA reduces lag, it may still react insufficiently at sharp turning points.
- Lack of Market Environment Filtering: Does not consider overall market trends or volatility, potentially trading in unsuitable market conditions.
Strategy Optimization Directions
- Introduce Additional Indicators: Combine with other technical indicators (such as RSI or MACD) to confirm signals and improve accuracy.
- Dynamic Stop-Loss/Take-Profit: Adjust stop-loss and take-profit levels based on market volatility to adapt to different market environments.
- Add Market Filters: Incorporate trend strength or volatility filters to avoid trading in unfavorable market conditions.
- Optimize HMA Parameters: Test different HMA periods to find the most suitable parameters for specific markets.
- Implement Position Management: Dynamically adjust trade size based on market risk and account size.
- Add Time Filters: Avoid trading during periods of high market volatility, such as during important economic data releases.
Summary
The Adaptive Price-Crossing Moving Average Trading Strategy is a simple yet effective quantitative trading method. By leveraging the advantages of the Hull Moving Average, this strategy can capture market trends while protecting capital through fixed risk management measures. Although the strategy has some potential risks, it can be further improved and adapted through continuous optimization. For traders seeking automated trading solutions, this is a worthwhile basic strategy framework to consider.
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-03-23 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SHIESTD", overlay=true)
// Function to calculate Hull Moving Average (HMA)
hma(src, length) =>
wma1 = ta.wma(src, length)
wma2 = ta.wma(src, length / 2)
hma = ta.wma(2 * wma2 - wma1, math.round(math.sqrt(length)))
hma
// Parameters
hma_length = 104
// Calculate Hull Moving Average
hma_value = hma(close, hma_length)
// Plot HMA
plot(hma_value, title="104-period Hull Moving Average", color=color.blue, linewidth=2)
// Define SL and TP values in dollars
long_sl_amount = 1.25
long_tp_amount = 37.5
short_sl_amount = 1.25
short_tp_amount = 37.5
// Number of contracts
contracts = 2
// Function to calculate SL and TP prices based on entry price and dollar amounts
long_sl_price(entry_price) =>
entry_price - long_sl_amount
long_tp_price(entry_price) =>
entry_price + long_tp_amount
short_sl_price(entry_price) =>
entry_price + short_sl_amount
short_tp_price(entry_price) =>
entry_price - short_tp_amount
// Trading conditions
price_intersects_hma = ta.crossover(close, hma_value) or ta.crossunder(close, hma_value)
// Long and Short Conditions based on price intersecting HMA
long_condition = ta.crossover(close, hma_value)
short_condition = ta.crossunder(close, hma_value)
// Track open positions
var bool long_open = false
var bool short_open = false
// Handle Long Positions
if (long_condition and not long_open)
entry_price = close
strategy.entry("Long", strategy.long, qty=contracts)
strategy.exit("Exit Long", from_entry="Long", stop=long_sl_price(entry_price), limit=long_tp_price(entry_price))
long_open := true
// Handle Short Positions
if (short_condition and not short_open)
entry_price = close
strategy.entry("Short", strategy.short, qty=contracts)
strategy.exit("Exit Short", from_entry="Short", stop=short_sl_price(entry_price), limit=short_tp_price(entry_price))
short_open := true
// Reset flags when the position is closed
if (strategy.opentrades == 0)
long_open := false
short_open := false
Published by ChaoZhang on the FMZ strategy square · last modified 2024-09-26. 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/Adaptive-Price-Crossing-Moving-Average-Trading-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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Advanced Multi Indicator Multi Dimensional Trend Cross Quantitative StrategyPine Script · Trend following · 3h
- Advanced Supertrend Indicator Trading Mechanism Optimization StrategyPine Script · Trend following · 1d
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual Indicator Dynamic Trend Trading Strategy Multi dimensional Technical Analysis System Based on RSI and MACDPine Script · Trend following