Strategy vault / Trend following
Dual Moving Average Crossover Strategy 427090
This strategy generates trading signals based on the crossover of two moving averages with different periods. The strategy allows users to choose the type and length of moving averages. The types include SMA, EMA…
This strategy generates trading signals based on the crossover of two moving averages with different periods.
Strategy Logic
The strategy allows users to choose the type and length of moving averages. The types include SMA, EMA, VWMA, etc. The length determines the period of the moving averages.
Two moving averages are calculated based on the user's selection. If the faster line crosses above the slower line, a golden cross is formed and a buy signal is generated. If the faster line crosses below the slower line, a death cross is formed and a sell signal is generated.
When the short-term average price is above the long-term average price, it is considered an uptrend and long positions should be taken. When the short-term price is below the long-term price, it is considered a downtrend and short positions should be taken.
Advantage Analysis
- The strategy logic is simple and clear, easy to understand and implement.
- Moving averages can effectively filter market noise and identify trends.
- The MA type and parameters can be flexibly chosen to adapt to different products and timeframes.
- Easy to optimize by combining various indicators.
Risk Analysis
- May generate multiple false signals when the market is ranging.
- Inappropriate parameter selection may lead to poor strategy performance.
- Signals are lagging, unable to timely capture turning points.
- Exposed to sudden price shocks.
Risks can be managed by optimizing parameters, combining other indicators for signal generation, implementing stop loss/take profit, etc.
Optimization Directions
- Test different types and length of MAs to find optimal parameters.
- Add other indicators for signal filtering, e.g. volume, volatility indicators.
- Add stop loss/take profit logic to reduce drawdown.
- Incorporate trend evaluation to avoid unsuitable market conditions.
- Optimize money management such as position sizing, risk budgeting.
Conclusion
The strategy has a simple and clear logic of generating signals with dual MAs crossover. It allows flexible parameter tuning and combinations with other strategies for optimization, but risks of ranging markets should be monitored and money management is crucial. Overall it is a strategy worth considering.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 30 | MA length |
| v_input_2 | true | Type |
| v_input_3_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
Source Pine Script
/*backtest
start: 2023-09-09 00:00:00
end: 2023-09-13 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy(title = "Noro's MAs Tests", shorttitle = "MAs tests", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)
len = input(30, defval = 30, minval = 2, maxval = 1000, title = "MA length")
type = input(1, defval = 1, minval = 1, maxval = 7, title = "Type")
src = input(close, defval = close, title = "Source")
//DEMA
dema = 2 * ema(src, len) - ema(ema(close, len), len)
//TEMA
xPrice = close
xEMA1 = ema(src, len)
xEMA2 = ema(xEMA1, len)
xEMA3 = ema(xEMA2, len)
tema = 3 * xEMA1 - 3 * xEMA2 + xEMA3
//KAMA
xvnoise = abs(src - src[1])
nfastend = 0.20
nslowend = 0.05
nsignal = abs(src - src[len])
nnoise = sum(xvnoise, len)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2)
kama = nz(kama[1]) + nsmooth * (src - nz(kama[1]))
//PriceChannel
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2
ma = type == 1 ? sma(src, len) : type == 2 ? ema(src, len) : type == 3 ? vwma(src, len) : type == 4 ? dema : type == 5 ? tema : type == 6 ? kama : type == 7 ? center : 0
plot(ma, color = blue, linewidth = 3, transp = 0)
trend = low > ma ? 1 : high < ma ? -1 : trend[1]
longCondition = trend == 1 and trend[1] == -1
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = trend == -1 and trend[1] == 1
if (shortCondition)
strategy.entry("Short", strategy.short)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-17. 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-427090.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