Strategy vault / Mean reversion
Dual Moving Average Reversal Trading Strategy 431664
This strategy is designed based on the golden cross and dead cross of fast and slow moving averages. When the fast MA crosses above the slow MA, go long. When the fast MA crosses below the slow MA, go short. This…

Overview
This strategy is designed based on the golden cross and dead cross of fast and slow moving averages. When the fast MA crosses above the slow MA, go long. When the fast MA crosses below the slow MA, go short. This strategy is suitable for medium-to-long term trading and can capture trend reversals in the market.
Strategy Logic
The strategy uses exponential moving average (EMA) to calculate the fast and slow lines. The fast MA length is 10 periods and the slow MA length is 30 periods. The strategy first calculates the fast EMA and slow EMA, then plots the lines and shows different colored backgrounds to indicate the trend direction.
When today's close is above the fast MA and the fast MA is above the slow MA, the background is green, indicating an upward trend. When today's close is below the fast MA and the fast MA is below the slow MA, the background is red, indicating a downward trend.
In an upward trend, if there is a red candlestick (close below open) and yesterday was also a red candlestick, go long. Set stop loss at 300 points and take profit by closing short position.
In a downward trend, if there is a green candlestick (close above open) and yesterday was also a green candlestick, go short. Set stop loss at 300 points and take profit by closing long position.
After opening a position in each direction, if the holding time exceeds 1008000000 milliseconds (about 2 weeks), force close the position to prevent deadlock.
Advantage Analysis
- The dual EMA system can effectively filter market noise and identify trend reversal points
- Fast and slow MAs combined with candlestick colors provide reliable entry signals
- Stop loss and take profit strategies reduce losses for individual trades
- Forced position close mechanism avoids huge losses from deadlocks
Risk Analysis
- EMA system is less sensitive to price spikes, may miss some trading opportunities
- Improper fast and slow MA parameter settings may cause false signals
- Stop loss point too tight increases risk of liquidation. Stop loss too wide may cause unnecessary losses
- Improper forced close time setting may lead to premature exit or holding too long
Optimization Directions
- Test profitability of EMA systems under different parameters to optimize fast and slow MA lengths
- Consider adding other indicators like MACD for confirmation to improve signal accuracy
- Link stop loss to daily volume changes
- Dynamically adjust forced close time based on market volatility
Conclusion
Overall this strategy is quite balanced, using dual EMA for trend and candlestick filters with additional rules to avoid false signals. But EMA parameters and stop loss/profit rules need further optimization. It is a reliable trend trading strategy on the whole.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 10 | Fast Average Length |
| v_input_int_2 | 30 | Slow Average Length |
| v_input_source_1_close | 0 | Average Data Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
Source Pine Script
/*backtest
start: 2023-10-10 00:00:00
end: 2023-11-09 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yeainshukla
//@version=5
strategy('BuyRedSellGreen4H', overlay = true)
greenCandle = close > open
redCandle = open > close
start = timestamp(2023,9,18,0,00)
end = timestamp(2023,12,31,0,00)
fastLength = input.int(10, title="Fast Average Length")
slowLength = input.int(30, title="Slow Average Length")
averageData = input.source(close, title="Average Data Source")
// Calculate exponential moving averages
fastAverage = ta.ema(averageData, fastLength)
slowAverage = ta.ema(averageData, slowLength)
// Plot averages
plot(fastAverage, color=color.navy, title="Fast EMA")
plot(slowAverage, color=color.fuchsia, linewidth=2, title="Slow EMA")
// Show the moving average trend with a coloured background
backgroundColor = if close > fastAverage and fastAverage > slowAverage
color.new(color.green, 85)
else if close < fastAverage and fastAverage < slowAverage
color.new(color.red, 85)
else
color.new(color.orange, 90)
bgcolor(backgroundColor, title="EMA Background")
if time >= start and time < end
if(close < open)
if(close[1] < open[1])
strategy.entry("Enter Long", strategy.long)
strategy.exit("Exit Long", from_entry="Enter Long")
strategy.close("Enter Short")
else
if(close[1] > open[1])
strategy.entry("Enter Short", strategy.short)
strategy.exit("Exit Short", from_entry="Enter Short")
strategy.close("Enter Long")
if strategy.position_size < 0 or strategy.position_size > 0// short and long is opened.
if((time - strategy.opentrades.entry_time(strategy.opentrades - 1)) > 1008000000)
strategy.close("Enter Short")
strategy.close("Enter Long")Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-10. 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-Reversal-Trading-Strategy-431664.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
- 1 2 3 Pattern Quantitative Trading Strategy with EMAs MACD and 4th Candle ExtensionPine Script · Mean reversion · 1h
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- BONK Multi Factor Trading StrategyPine Script · Mean reversion · 1d
- Chaikin Oscillator StrategyPine Script · Mean reversion · 3h
- Customizable Non Repainting HTF MACD MFI Scalable Bot StrategyPine Script · Mean reversion · 1d