Strategy vault / Machine learning
Quantitative Trading Strategy Based on 5 day Moving Average Band and GBS Buy Sell Signals
This strategy combines the 5-day moving average band and GBS buy/sell signals to identify trend direction and generate trading signals. The moving average band is used to judge the trend direction and major…

Overview
This strategy combines the 5-day moving average band and GBS buy/sell signals to identify trend direction and generate trading signals. The moving average band is used to judge the trend direction and major support/resistance levels, while the GBS buy/sell signals are used to find precise entry timing under the trend direction. This strategy is suitable for medium-term trend trading and can achieve excess returns in range-bound markets.
Strategy Principles
- Calculate the simple moving average of 5-day high and low prices to obtain the 5-day moving average band
- When the closing price breaks through the moving average band, it indicates a trend reversal
- When an uptrend is identified, long positions are taken if GBS buy signals are triggered; When a downtrend is identified, short positions are taken if GBS sell signals are triggered
- Set stop loss/take profit exit mechanisms, exit when drawdown exceeds certain threshold
Advantages of the Strategy
- The moving average band accurately judges the major trend direction
- GBS buy/sell signals have a relatively high winning rate
- The stop loss mechanism effectively controls risks and limits losses
Risks and Solutions
- False breakouts may occur frequently in range-bound markets, causing trading mistakes
- Solution: Widen the moving average band to ensure operations only during clear trends
- Risks relying on single indicator
- Solution: Add validation from other indicators e.g. MACD, RSI to avoid missing reversal signals
- Backtest overfitting risks
- Solution: Expand backtest timeframe, compare results across different products and parameters
Directions for Strategy Optimization
- Parameter optimization to find optimum parameter combinations
- Add validation signals from other indicators
- Develop adaptive moving average mechanisms
- Adjust stop loss level based on market conditions
- Add machine learning algorithms to automatically optimize the strategy
Conclusion
This strategy integrates the moving average band and GBS buy/sell signals, operating with high confidence after identifying a clear trend direction to filter out market noise. It can lock in medium-term profits and exit timely. The strategy is simple and efficient in capital utilization, providing stable profits for quant traders. Continuous optimizations and iterations can further improve the win rate and profitability.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 5 | Number of Candles for Average |
Source Pine Script
/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("5MABAND + GBS Buy & Sell Strategy", overlay=true)
// Command 1 - 5MABAND Calculation
length = input(5, title="Number of Candles for Average")
avgHigh = ta.sma(high, length)
avgLow = ta.sma(low, length)
// Plotting 5MABAND Bands
plot(avgHigh, color=color.green, title="5MABAND High Line", linewidth=1)
plot(avgLow, color=color.red, title="5MABAND Low Line", linewidth=1)
// Command 2 - GBS concept Buy Entry
gbsBuyCondition = close > open and high - close < close - open and open - low < close - open and close - open > close[1] - open[1] and close - open > close[2] - open[2] and close - open > close[3] - open[3] and close[1] < avgHigh and close[2] < avgHigh and close[3] < avgHigh and open[1] < avgHigh and open[2] < avgHigh and open[3] < avgHigh
// Command 3 - GBS Concept Sell Entry
gbsSellCondition = open - close > open[1] - close[1] and open - close > open[2] - close[2] and open - close > open[3] - close[3] and open[1] > avgLow and open[2] > avgLow and open[3] > avgLow and open - close > open - low and open - close > high - open
// Command 6 - 5MABAND Exit Trigger
exitTriggerCandle_5MABAND_Buy = low < avgLow
exitTriggerCandle_5MABAND_Sell = high > avgHigh
// Exit Signals for 5MABAND
exitBuySignal_5MABAND = close < avgLow
exitSellSignal_5MABAND = close > avgHigh
// Execute Buy and Sell Orders
strategy.entry("Buy", strategy.long, when = gbsBuyCondition)
strategy.close("Buy", when = exitBuySignal_5MABAND)
strategy.entry("Sell", strategy.short, when = gbsSellCondition)
strategy.close("Sell", when = exitSellSignal_5MABAND)
// Exit Buy and Sell Orders for 5MABAND
strategy.close("Buy", when = exitTriggerCandle_5MABAND_Buy)
strategy.close("Sell", when = exitTriggerCandle_5MABAND_Sell)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-05. 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/Quantitative-Trading-Strategy-Based-on-5-day-Moving-Average-Band-and-GBS-Buy-Sell-Signals.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
- Multi indicator Assisted StrategyPine Script · Machine learning · 1d
- Multi factor Quantitative Trading StrategyPine Script · Machine learning · 1d
- AI Powered Volatility Price System Divergence Trading StrategyPine Script · Machine learning · 1h
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- High Frequency Hybrid Technical Analysis Quantitative StrategyPine Script · Machine learning · 15m
- MACD Robot Trading StrategyPine Script · Machine learning · 1d