Strategy vault / Trend following
Adaptive Trend Following Strategy Based on Moving Average Crossover
This strategy is a trend following system based on dual moving average crossover, which captures market trends through the intersection of short-term and long-term moving averages, using a 1:3 risk-reward ratio for…

Overview
This strategy is a trend following system based on dual moving average crossover, which captures market trends through the intersection of short-term and long-term moving averages, using a 1:3 risk-reward ratio for trade risk management. The strategy employs fixed stop-loss and take-profit targets, combined with a trailing stop mechanism to protect profits.
Strategy Principle
The strategy utilizes a 74-period Short SMA and a 70-period Long SMA as primary indicators. A long signal is generated when the short-term moving average crosses above the long-term moving average, while a short signal is triggered when the short-term moving average crosses below the long-term moving average. Each trade has a fixed position size of 0.002, with a stop-loss set at $353 and a take-profit target at three times the stop-loss ($1,059). The strategy also includes date range restrictions, executing trades only within the specified backtesting period (February 13, 2025, to March 31, 2025).
Strategy Advantages
- Comprehensive risk management: Uses a fixed 1:3 risk-reward ratio, contributing to stable returns in long-term trading
- Clear signals: Employs classic moving average crossover strategy, with clear and easy-to-understand trading signals
- High degree of automation: Includes complete entry and exit logic, requiring no manual intervention
- Trailing stop protection: Effectively locks in realized profits through trailing stop mechanism
- Strict position control: Fixed position size prevents excessive risk-taking
Strategy Risks
- Moving average lag: Moving averages are inherently lagging indicators, potentially generating delayed signals in rapidly volatile markets
- Ineffective in ranging markets: May generate frequent false signals in sideways markets, leading to consecutive losses
- Fixed stop-loss risk: Dollar-based fixed stops may lack flexibility during extreme price volatility
- Time range limitation: Strategy operates only within specific time ranges, potentially missing important trading opportunities
Strategy Optimization Directions
- Dynamic adjustment of moving average periods: Automatically adjust periods based on market volatility to improve strategy adaptability
- Introduction of volatility filters: Add ATR or other volatility indicators to adjust stop-loss levels during high volatility periods
- Position management optimization: Implement dynamic position sizing based on account equity to improve capital efficiency
- Market environment filtering: Introduce trend strength indicators to automatically reduce trading frequency in ranging markets
- Exit mechanism improvement: Develop more flexible profit-taking mechanisms by incorporating price breakouts or momentum indicators
Summary
This is a well-structured trend following strategy with clear logic. It captures trends through moving average crossovers, employing strict risk management and position control, suitable for medium to long-term trading. While inherent drawbacks like moving average lag exist, the strategy's stability and profitability can be further enhanced through the suggested optimization directions, particularly by introducing dynamic parameter adjustment and market environment filtering.
Source Pine Script
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-17 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bitcoin Strategy by Jag", overlay=true)
// Input Parameters
shortSMALength = input.int(74, title="Short SMA Length")
longSMALength = input.int(70, title="Long SMA Length")
trailStopOffset = input.float(353, title="Trailing Stop Offset (USD)") // Trailing Stop Loss Offset in USD
tradeSize = input.float(1, title="Trade Size")
// Automatically set Take Profit as 3 times Stop Loss
fixedTakeProfit = trailStopOffset * 3
// Backtesting Date Range
startDate = timestamp(2025, 02,13, 0, 0)
endDate = timestamp(2025, 03, 31, 23, 59)
withinDateRange = true
// Indicators
shortSMA = ta.sma(close, shortSMALength)
longSMA = ta.sma(close, longSMALength)
// Crossover Conditions
longCondition = withinDateRange and ta.crossover(shortSMA, longSMA)
shortCondition = withinDateRange and ta.crossunder(shortSMA, longSMA)
// Entry Logic
if (strategy.position_size == 0) // Only allow new trades if no position is open
if (longCondition)
strategy.entry("Long", strategy.long, tradeSize)
if (shortCondition)
strategy.entry("Short", strategy.short, tradeSize)
// Exit Logic for Long Position
if (strategy.position_size > 0)
strategy.exit("Long exit", "Long", stop=strategy.position_avg_price - trailStopOffset, limit=strategy.position_avg_price + fixedTakeProfit) // Using stop and limit
// Exit Logic for Short Position
if (strategy.position_size < 0)
strategy.exit("Short Exit", "Short", stop=strategy.position_avg_price + trailStopOffset, limit=strategy.position_avg_price - fixedTakeProfit) // Using stop and limit
// Plot Moving Averages
plot(shortSMA, color=color.blue, title="Short SMA")
plot(longSMA, color=color.black, title="Long SMA")
// Visual Signals
plotshape(series=longCondition and strategy.position_size == 0, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=shortCondition and strategy.position_size == 0, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)
Published by ChaoZhang on the FMZ strategy square · last modified 2025-02-18. 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-Trend-Following-Strategy-Based-on-Moving-Average-Crossover.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
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h
- Adaptive Volatility Based Trend Following Short Strategy with Time Delay and Stop Loss ProtectionPine Script · Trend following · 2m
- BB Percentage Index Trend Fading StrategyPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m