Strategy vault / Trend following
Moving Average Turning Point Crossover Trading Strategy
The Moving Average Turning Point Crossover Trading Strategy is a classic technical indicator strategy. The core idea of this strategy is to generate buy and sell signals by combining moving averages of different…

Overview
The Moving Average Turning Point Crossover Trading Strategy is a classic technical indicator strategy. The core idea of this strategy is to generate buy and sell signals by combining moving averages of different periods and further optimize trade exits using moving average turning points. This strategy is suitable for various timeframes and products and can achieve stable returns.
Strategy Principle
The strategy mainly uses two moving averages, one with a shorter period as the fast line and the other with a longer period as the slow line. When the fast line breaks through the slow line upward, a buy signal is generated. When the fast line breaks through the slow line downward, a sell signal is generated. This is the trading signal generation mechanism of the classic moving average crossover strategy.
Furthermore, the strategy exits trades using the turning points of the moving averages. When the fast line turns from rising to falling, long positions will exit. When the fast line turns from falling to rising, short positions will exit. Moving average turning points can capture short-term market reversal points, which helps the strategy to cut losses or take profits in time, thereby improving overall return.
Advantage Analysis
The Moving Average Turning Point Crossover Trading Strategy has the following advantages:
Simple to implement. The strategy only uses two indicators: Moving Average and ROC indicator. The code is not complicated.
Strong ability to withstand consecutive losses. The inherent lag and price smoothing characteristics of moving averages can filter out some noise and avoid generating too many invalid trades in ranging trends.
Can effectively control unilateral losses. Timely stop losses using moving average turning points can reduce large unilateral losses.
Wide applicability. The strategy principle is simple and can be applied to different products and trading timeframes such as daily and hourly bars. Large parameter optimization space.
Stable returns. Compared with strategies chasing market hotspots, this strategy focuses more on risk control instead of pursuing super high returns, but it can obtain stable positive returns.
Risk Analysis
The Moving Average Turning Point Crossover Trading Strategy also has some risks, mainly in the following aspects:
Lagging of moving averages. When fast market comes, the crossover signals of moving averages will lag, possibly missing the best entry point.
Long empty holding periods. This strategy has timely exits but slower entry signals. This can lead to excessive empty holding periods. Profit opportunities are missed during empty holding periods.
Difficult parameter optimization. The choice of parameters like moving average length and ROC cycle will have great impact on the strategy's performance. But parameter optimization requires a lot of historical data for backtesting, posing difficulties in optimization.
Poor performance in high volatility trends. In high volatility ranging trends, moving averages will generate multiple invalid crossovers, impairing the strategy's performance.
Optimization Directions
The trading strategy can be further optimized in the following aspects:
Incorporate trend filtering indicators. Add indicators like ADX and ATR to judge trend status. Disable the strategy when there is no clear trend to avoid useless trades.
Combine multiple timeframes. Identify main trend direction on higher timeframes to avoid trading against main trend.
Adaptive parameter optimization. Enable parameters like moving average length to adjust adaptively based on real-time market volatility to improve parameter robustness.
Introducing pattern recognition. Identify candlestick patterns at MA crossover points to filter out false signals.
Summary
Overall, the Moving Average Turning Point Crossover Trading Strategy balances risk and returns. It has advantages like ease of implementation, resistance to consecutive losses, and stable returns. It also has disadvantages like the lagging issue of MAs and excessive empty holding periods. By optimizing parameters, incorporating trend judgment, pattern recognition etc, the strategy's performance can be further improved.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_2 | 25 | 1st MA Length |
| v_input_3 | 0 | 1st MA Type: SMA | EMA |
| v_input_4 | 50 | 2nd MA Length |
| v_input_5 | 0 | 2nd MA Type: SMA | EMA |
| v_input_6 | true | Lookback 1 |
| v_input_7 | 2 | Minimum slope magnitude * 100 |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//study(title="MA Crossover Strategy", overlay = true)
strategy("MA Crossover Strategy with MA Turning Point Exits", overlay=true)
src = input(close, title="Source")
price = request.security(syminfo.tickerid, timeframe.period, src)
ma1 = input(25, title="1st MA Length")
type1 = input("SMA", "1st MA Type", options=["SMA", "EMA"])
ma2 = input(50, title="2nd MA Length")
type2 = input("SMA", "2nd MA Type", options=["SMA", "EMA"])
price1 = if (type1 == "SMA")
sma(price, ma1)
else
ema(price, ma1)
price2 = if (type2 == "SMA")
sma(price, ma2)
else
ema(price, ma2)
//plot(series=price, style=line, title="Price", color=black, linewidth=1, transp=0)
plot(series=price1, style=line, title="1st MA", color=blue, linewidth=2, transp=0)
plot(series=price2, style=line, title="2nd MA", color=green, linewidth=2, transp=0)
longCondition = crossover(price1, price2)
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = crossunder(price1, price2)
if (shortCondition)
strategy.entry("Short", strategy.short)
lookback1 = input(1, "Lookback 1")
roc1 = roc(price1, lookback1)
ma1up = false
ma1down = false
ma2up = false
ma2down = false
ma1up := nz(ma1up[1])
ma1down := nz(ma1down[1])
ma2up := nz(ma2up[1])
ma2down := nz(ma2down[1])
trendStrength1 = input(2, title="Minimum slope magnitude * 100", type=float) * 0.01
if crossover(roc1, trendStrength1)
ma1up := true
ma1down := false
if crossunder(roc1, -trendStrength1)
ma1up := false
ma1down := true
shortexitCondition = ma1up and ma1down[1]
if (shortexitCondition)
strategy.close("Short")
longexitCondition = ma1down and ma1up[1]
if (longexitCondition)
strategy.close("Long")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-29. 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/Moving-Average-Turning-Point-Crossover-Trading-Strategy.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
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Bollinger Band Moving Average Crossover StrategyPine Script · Trend following · 1h
- Bollinger Bands and EMA Trend Following StrategyPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Candlestick Pattern Trend Filter StrategyPine Script · Trend following · 1d