Strategy vault / Trend following
Dual Moving Average Crossover Strategy 437640
This strategy uses simple moving average crossovers and average true range indicator to generate buy and sell signals. It belongs to trend following strategies. It mainly uses 50-day and 100-day moving average…

Overview
This strategy uses simple moving average crossovers and average true range indicator to generate buy and sell signals. It belongs to trend following strategies. It mainly uses 50-day and 100-day moving average crossovers to determine the trend and sets stop loss based on ATR to control risks.
Strategy Logic
- Calculate 50-day simple moving average SMA1 and 100-day simple moving average SMA2
- When SMA1 crosses over SMA2, a buy signal is generated. When SMA1 crosses below SMA2, a sell signal is generated.
- Calculate 14-day ATR
- ATR multiplied by a set factor is used as stop loss point
- When a buy signal is triggered, the closing price minus the stop loss point is the stop loss sell point. When a sell signal is triggered, the closing price plus the stop loss point is the stop loss buy point.
It can be seen that this strategy mainly relies on the trend judging capability of moving averages and the risk control capability of ATR. The logic is simple and easy to understand and implement.
Advantages
- Simple logic easy to implement, suitable for beginners
- Moving averages can effectively track trends
- ATR stop loss can effectively control losses from individual black swan events
- Parameters can be easily adjusted for different market environments
Risks
- Many false signals may be triggered during range-bound markets, missing reversal points
- ATR may not react sensitively enough to fast changing markets, leading to larger than expected losses
- The parameter settings and ATR multiplier rely on experience. Improper settings may affect strategy performance
- The dual moving averages themselves have lagging effect, may miss turning points
Risk Management:
- Shorten moving average periods to make the indicator more sensitive
- Dynamically adjust ATR multiplier for more flexible stop loss
- Add other indicators to filter false signals
- Operate based on larger time frame structure judgments
Optimization Directions
- Try other types of moving averages, like EMAs that filter better
- Consider dynamic stop loss with Keltner Channels etc. to replace ATR
- Add supporting indicators like volume to filter signals
- Identify trend key points with concepts like Elliott Waves, support resistance etc.
Summary
This is a typical trend following strategy, using moving averages to determine trend direction and ATR stop loss to control risks. The logic is simple and easy to grasp. But it has certain lagging and false signal risks. Improvements can be made through parameter tuning, indicator optimization, incorporating more factors etc. to make the strategy more adaptive. Overall this strategy is suitable for beginner practice and optimization, but need to be careful when apply it in actual trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 50 | 50 SMA Length |
| v_input_int_2 | 100 | 100 SMA Length |
| v_input_int_3 | 14 | ATR Length |
| v_input_int_4 | 4 | ATR Multiplier |
Source Pine Script
/*backtest
start: 2023-12-27 00:00:00
end: 2024-01-03 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SMA and ATR Strategy", overlay=true)
// Step 1. Define strategy settings
lengthSMA1 = input.int(50, title="50 SMA Length")
lengthSMA2 = input.int(100, title="100 SMA Length")
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.int(4, title="ATR Multiplier")
// Step 2. Calculate strategy values
sma1 = ta.sma(close, lengthSMA1)
sma2 = ta.sma(close, lengthSMA2)
atr = ta.atr(atrLength)
// Step 3. Output strategy data
plot(sma1, color=color.blue, title="50 SMA")
plot(sma2, color=color.red, title="100 SMA")
// Step 4. Determine trading conditions
longCondition = ta.crossover(sma1, sma2)
shortCondition = ta.crossunder(sma1, sma2)
longStopLoss = close - (atr * atrMultiplier)
shortStopLoss = close + (atr * atrMultiplier)
// Step 5. Execute trades based on conditions
if (longCondition)
strategy.entry("Buy", strategy.long)
strategy.exit("Sell", "Buy", stop=longStopLoss)
if (shortCondition)
strategy.entry("Sell", strategy.short)
strategy.exit("Buy", "Sell", stop=shortStopLoss)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-04. 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-437640.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 Trend Following Strategy 433078Pine Script · Trend following
- CCIRSIKC Trend Filter Bi Directional Trading StrategyPine Script · Trend following · 2h
- Dual directional Trailing Stop Moving Average Trend StrategyPine Script · Trend following · 1m
- Golden Cross Keltner Channel Trend Following StrategyPine Script · Trend following · 1d
- Trend Following Strategy Based on SSL BaselinePine Script · Trend following · 1h
- A Trend Following Strategy Based on Keltner ChannelsPine Script · Trend following · 1d