Strategy vault / Trend following
Trend Tracking Strategy Based on Moving Average Crossover
This strategy is a quantitative trading strategy that judges market trend direction based on moving average crossover and tracks the trend. It uses the crossovers of simple moving averages with different parameters…

Overview
This strategy is a quantitative trading strategy that judges market trend direction based on moving average crossover and tracks the trend. It uses the crossovers of simple moving averages with different parameters to determine the entry and exit points.
Strategy Principle
The main judgment rules of this strategy are:
When the short-term moving average crosses above the long-term moving average from the bottom, it indicates that the market may be entering an uptrend, then go long;
When the short-term moving average crosses below the long-term moving average from the top, it indicates that the market may be entering a downtrend, then go short;
Use moving averages with different parameters to judge trends at different timescales and track trends at different levels.
Specifically, the strategy uses 5 moving averages - 20-day, 30-day, 50-day, 60-day and 200-day. When 20-day MA crosses above 50-day MA, it is a buy signal; When 10-day MA crosses below 30-day MA, it is a sell signal. Using MAs of different parameters can tell trends in both longer and shorter timescales.
Advantages
This trend tracking strategy based on MA crossover has the following advantages:
- Simple to understand and implement;
- Can effectively determine market trend direction and strength;
- Different parameter settings allow tracking trends at different timescales;
- Highly customizable based on needs by adjusting MA parameters.
Risks
There are also some risks with this strategy:
- MAs have lagging nature, which may cause certain delays;
- Wrong MA parameter settings may lead to excessive trading signals and unnecessary losses;
- Avoid using this strategy during market consolidation, use it only during obvious trending markets.
To reduce risks, we can adjust MA parameters, optimize parameter settings, and use other indicators to aid decision making.
Improvement Areas
We can optimize this strategy in the following areas:
- Optimize MA parameters to find the optimal parameter combination, reduce trading frequency while improving profit rate;
- Incorporate other technical indicators like RSI, KD to improve decision accuracy;
- Add stop loss strategies to control risks effectively;
- Combine complex machine learning models for parameter optimization and strategy evaluation, continuously iterate and upgrade.
Conclusion
This is a very basic trend tracking strategy. It uses MA crossover principle to determine market trend direction, simple and effective, easy to understand and implement. We can make lots of expansions and optimizations to make it suitable for more complex quantitative trading. Overall this is a great strategy framework to build upon.
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Grafik Formasyonları Alım-Satım Stratejisi", overlay=true)
// Inverse Head and Shoulders (İnverse Omuz-Baş-Omuz)
ihs_condition = ta.crossover(ta.sma(close, 50), ta.sma(close, 200))
// Head and Shoulders (Omuz-Baş-Omuz)
hs_condition = ta.crossunder(ta.sma(close, 50), ta.sma(close, 200))
// Flag Pattern (Bayrak Formasyonu)
flag_condition = ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
// Triangle Pattern (Trekgen Formasyonu)
triangle_condition = ta.crossover(ta.sma(close, 20), ta.sma(close, 50))
// Pennant Pattern (Ters Bayrak Formasyonu)
pennant_condition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20))
// Inverse Triangle Pattern (Ters Üçgen Formasyonu)
inverse_triangle_condition = ta.crossunder(ta.sma(close, 30), ta.sma(close, 60))
// Alım-Satım Sinyalleri
if (ihs_condition)
strategy.entry("İHS_Long", strategy.long)
if (hs_condition)
strategy.close("İHS_Long")
if (flag_condition)
strategy.entry("Flag_Long", strategy.long)
if (triangle_condition)
strategy.entry("Triangle_Long", strategy.long)
if (pennant_condition)
strategy.entry("Pennant_Short", strategy.short)
if (inverse_triangle_condition)
strategy.close("Pennant_Short")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-22. 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/Trend-Tracking-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
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- BB Percentage Index Trend Fading StrategyPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Crypto RSI Mini Sniper Quick Response Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual Mode Adaptive Trend Trading Strategy EMA Crossover with ATR Volatility Based Risk Management SystemPine Script · Trend following · 1d