Strategy vault / Trend following
Dual Moving Average Crossover Strategy with Adaptive Stop Loss and Take Profit
This is an adaptive trading strategy based on dual moving average crossover signals. The strategy utilizes 14-period and 28-period Simple Moving Averages (SMA) to generate trading signals, combined with adjustable…

Overview
This is an adaptive trading strategy based on dual moving average crossover signals. The strategy utilizes 14-period and 28-period Simple Moving Averages (SMA) to generate trading signals, combined with adjustable stop-loss and take-profit mechanisms to achieve balanced risk-reward management. The strategy employs fixed money management with an initial capital of 2000 and 200 per trade.
Strategy Principles
The core logic is based on the crossover relationship between two SMAs of different periods. A long signal is generated when the short-term (14-period) MA crosses above the long-term (28-period) MA, and a short signal is generated when the short-term MA crosses below the long-term MA. The strategy incorporates percentage-based stop-loss and take-profit mechanisms set at 2% and 4% respectively, allowing for automatic adjustment of exit points based on market prices.
Strategy Advantages
- Clear Signals: The moving average crossover provides clear and objective signals, eliminating subjective judgment.
- Robust Risk Control: The percentage-based stop-loss and take-profit levels automatically adjust with market prices, adapting to different market conditions.
- Rational Money Management: The fixed allocation approach prevents risks associated with excessive leverage.
- Good Visualization: The strategy displays trading signals and moving average trends on the chart, facilitating understanding and monitoring.
- Flexible Parameters: Stop-loss and take-profit parameters can be adjusted according to different market conditions and personal risk preferences.
Strategy Risks
- Choppy Market Risk: Frequent crossovers during sideways markets may generate false signals.
- Slippage Risk: During high volatility periods, actual execution prices may deviate from signal prices.
- Fixed Stop-Loss Range: Although stop-loss points adjust with price, the fixed percentage may not suit all market conditions.
- Capital Efficiency: Fixed money allocation might lead to suboptimal capital utilization in certain scenarios.
Strategy Optimization Directions
- Implement Trend Filters: Add additional trend indicators like MACD or RSI to reduce false signals.
- Dynamic Stop-Loss Mechanism: Adjust stop-loss percentages based on market volatility for better adaptability.
- Optimize Money Management: Introduce volatility-based position sizing to improve capital efficiency.
- Add Time Filters: Implement trading time restrictions to avoid highly volatile periods.
- Incorporate Drawdown Control: Set maximum drawdown limits to pause trading when specific thresholds are reached.
Summary
This is a well-structured and logically sound trading strategy. It captures trading opportunities through dual moving average crossovers while controlling risks with adaptive stop-loss and take-profit mechanisms. While there is room for optimization, the overall design adheres to fundamental quantitative trading principles. Through the suggested optimization directions, the strategy's stability and profitability potential can be further enhanced.
Source Pine Script
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('My Custom Strategy', overlay = true)
// Parámetros de las SMAs (Medias Móviles Simples)
sma14 = ta.sma(close, 14)
sma28 = ta.sma(close, 28)
// Stop Loss y Take Profit configurables
stop_loss_percent = input.float(2, title="Stop Loss %", minval=0.1, step=0.1)
take_profit_percent = input.float(4, title="Take Profit %", minval=0.1, step=0.1)
// Cálculo de stop loss y take profit
stop_loss = close * (1 - stop_loss_percent / 100)
take_profit = close * (1 + take_profit_percent / 100)
// Condiciones de entrada para compra (long)
longCondition = ta.crossover(sma14, sma28)
if (longCondition)
strategy.entry('Long', strategy.long, stop=stop_loss, limit=take_profit)
plotshape(series=longCondition, color=color.new(color.blue, 0), style=shape.labelup, location=location.belowbar, text="BUY")
// Condiciones de entrada para venta (short)
shortCondition = ta.crossunder(sma14, sma28)
if (shortCondition)
strategy.entry('Short', strategy.short, stop=stop_loss, limit=take_profit)
plotshape(series=shortCondition, color=color.new(color.red, 0), style=shape.labeldown, location=location.abovebar, text="SELL")
// Visualización de las SMAs en el gráfico
plot(sma14, color=color.blue, title="SMA 14")
plot(sma28, color=color.red, title="SMA 28")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-27. 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/Dual-Moving-Average-Crossover-Strategy-with-Adaptive-Stop-Loss-and-Take-Profit.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
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual SMA Crossover StrategyPine Script · Trend following · 5m
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- EMA and RSI Trend Trading StrategyPine Script · Trend following · 1d