Strategy vault / Trend following
Dynamic Moving Average and Bollinger Bands Cross Strategy with Fixed Stop Loss Optimization Model
This strategy is a trend-following trading system that combines Moving Average (MA) and Bollinger Bands indicators. It identifies market trends by analyzing price relationships with the 200-period moving average and…

Overview
This strategy is a trend-following trading system that combines Moving Average (MA) and Bollinger Bands indicators. It identifies market trends by analyzing price relationships with the 200-period moving average and Bollinger Bands position, while incorporating a fixed percentage stop-loss mechanism for risk control. The strategy employs a 2.86% position management, compatible with 35x leverage, demonstrating prudent fund management principles.
Strategy Principles
The core logic of the strategy is based on the following key elements:
- Uses 200-period moving average as the primary trend indicator
- Combines 20-period Bollinger Bands' upper and lower channels for volatility range assessment
- Opens long positions when:
- Price is above the 200 MA
- Bollinger Bands middle band is above 200 MA
- Price crosses above the lower Bollinger Band
- Opens short positions when:
- Price is below the 200 MA
- Bollinger Bands middle band is below 200 MA
- Price crosses below the upper Bollinger Band
- Implements 3% fixed stop-loss percentage for risk control
- Closes long positions at upper Bollinger Band, shorts at lower band
Strategy Advantages
- Strong Trend Following Capability
- Effectively identifies long-term trends using 200 MA
- Bollinger Bands assist in detecting medium-short term trend changes
- Comprehensive Risk Control
- Fixed stop-loss mechanism effectively controls per-trade risk
- Dynamic take-profit design enhances profit opportunities
- Flexible Parameter Optimization
- MA period and Bollinger Bands parameters adjustable to market characteristics
- Stop-loss percentage adjustable to risk tolerance
- High Systematization
- Clear trading signals without subjective judgment
- Suitable for automated trading execution
Strategy Risks
- Sideways Market Risk
- False breakout signals may occur frequently in ranging markets
- Recommended to trade only in clear trending markets
- Slippage Risk
- Significant slippage possible during volatile periods
- Recommend setting reasonable slippage protection
- Systematic Risk
- Market events may cause stop-loss failure
- Recommend combining with other risk control measures
- Parameter Optimization Risk
- Over-optimization may lead to overfitting
- Recommend backtesting across different timeframes
Strategy Optimization Directions
- Dynamic Stop-Loss Optimization
- Introduce ATR indicator for dynamic stop-loss adjustment
- Adjust stop-loss percentage based on market volatility
- Entry Signal Optimization
- Add volume confirmation indicators
- Implement trend strength filters
- Position Management Optimization
- Implement dynamic position sizing
- Adjust leverage based on market volatility
- Trading Timing Optimization
- Add market sentiment indicators
- Implement time filters
Summary
This strategy builds a complete trading system by combining classic technical indicators, demonstrating good trend capture ability and risk control effects. The core advantages lie in its high systematization and parameter adjustability, while achieving effective risk control through fixed stop-loss mechanisms. Although performance may be suboptimal in ranging markets, implementing the suggested optimizations can further enhance strategy stability and profitability. Traders are advised to consider market conditions when implementing live trading and adjust parameters according to their risk tolerance.
Source Pine Script
/*backtest
start: 2024-11-26 00:00:00
end: 2024-12-25 08:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA 200 and Bollinger Bands Strategy", overlay=true) // 2.86% for 35x leverage
// inputs
ma_length = input(200, title="MA Length")
bb_length = input(20, title="Bollinger Bands Length")
bb_mult = input(2.0, title="Bollinger Bands Multiplier")
// calculations
ma_200 = ta.sma(close, ma_length)
bb_basis = ta.sma(close, bb_length)
bb_upper = bb_basis + (ta.stdev(close, bb_length) * bb_mult)
bb_lower = bb_basis - (ta.stdev(close, bb_length) * bb_mult)
// plot indicators
plot(ma_200, color=color.blue, title="200 MA")
plot(bb_upper, color=color.red, title="Bollinger Upper Band")
plot(bb_basis, color=color.gray, title="Bollinger Basis")
plot(bb_lower, color=color.green, title="Bollinger Lower Band")
// strategy logic
long_condition = close > ma_200 and bb_basis > ma_200 and ta.crossover(close, bb_lower)
short_condition = close < ma_200 and bb_basis < ma_200 and ta.crossunder(close, bb_upper)
// fixed stop loss percentage
fixed_stop_loss_percent = 3.0 / 100.0
if (long_condition)
strategy.entry("Long", strategy.long)
strategy.exit("Stop Long", "Long", stop=strategy.position_avg_price * (1 - fixed_stop_loss_percent))
if (short_condition)
strategy.entry("Short", strategy.short)
strategy.exit("Stop Short", "Short", stop=strategy.position_avg_price * (1 + fixed_stop_loss_percent))
// take profit conditions
close_long_condition = close >= bb_upper
close_short_condition = close <= bb_lower
if (close_long_condition)
strategy.close("Long")
if (close_short_condition)
strategy.close("Short")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-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/Dynamic-Moving-Average-and-Bollinger-Bands-Cross-Strategy-with-Fixed-Stop-Loss-Optimization-Model.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
- Relative Volume Trend Following Trading StrategyPine Script · Trend following · 1d
- AlphaTrend Dual Tracking StrategyPine Script · Trend following · 1h
- Moving Average Crossover Strategy 430371Pine Script · Trend following · 1h
- Multi Moving Average and Bollinger Bands Crossover Options Quantitative Trading StrategyPine Script · Trend following · 5m
- Multi Indicator Trend Following Strategy with Bollinger Bands and ATR Dynamic Stop LossPine Script · Trend following · 1d
- Multi Indicator Filtered Trading Strategy with Bollinger Bands and Woodies CCIPine Script · Trend following · 1d