Dual Moving Average Intelligent Tracking Trading Strategy
The dual moving average intelligent tracking trading strategy is a trend following strategy based on moving averages and specific indicators. The strategy uses two moving averages with different parameter settings to…

Overview
The dual moving average intelligent tracking trading strategy is a trend following strategy based on moving averages and specific indicators. The strategy uses two moving averages with different parameter settings to build a channel and combines the OTT indicator to set the upper and lower limits of the channel to intelligently track price trends. When prices break through the channel, buy or sell operations are executed.
Strategy Principle
The core methodology of this strategy is to construct an adaptive channel using two moving averages and the OTT indicator, specifically:
Calculate the fast line MAvg using CLOSE and custom moving average as input, with a length of 5 periods;
Calculate the long line position LongStop and short line position ShortStop for the channel based on MAvg and preset percentage;
Calculate the channel stop loss MT in OTT indicator, and channel price OTT based on long/short direction;
Generate trading signals when price breaks through OTT.
The above process enables real-time tracking of price trend changes, generating trading signals.
Strategy Advantages
The advantages of this strategy include:
- The dual moving average channel structure effectively captures price trends;
- OTT indicator sets channel stop loss to control risks;
- Adaptive channel structure responds quickly to price changes;
- Flexible parameter tuning for different products and timeframes.
Strategy Risks
There are also some risks:
- Dual moving averages can form divergence resulting in false signals;
- Improper OTT parameter settings may be too aggressive or conservative;
- The strategy relies solely on technical indicators without considering fundamentals.
Risks can be addressed through parameter optimization, integrating other indicators and fundamentals filters.
Optimization Directions
The strategy can be optimized in several aspects:
- Optimize moving average parameters for proper product and timeframes;
- Optimize channel width parameters balancing sensitivity and stability;
- Add filters based on trading volume;
- Set direction filters based on fundamentals.
Summary
In summary, this is a trend following strategy based on a dual moving average channel and OTT indicator. The core idea is constructing an adaptive channel and generating signals when prices breakout. The strategy has merits but also room for improvements. With parameter tuning and logic optimization, it has the potential to become an efficient quant trading strategy worth deploying.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 5 | Period |
| v_input_2 | true | Sihirli Yüzde |
| v_input_3 | 0 | Hareketli Ortalama Türü: VAR | EMA | WMA | TMA | SMA | WWMA | ZLEMA | TSF |
| v_input_4 | 10 | Kanal Periyodu |
| v_input_5 | 21 | Averaj Uzunluğu |
| v_input_6 | 20200101 | Başlangıç Tarihi (YYYYMMDD) |
| v_input_7 | 20201231 | Bitiş Tarihi (YYYYMMDD) |
Source Pine Script
/*backtest
start: 2023-02-11 00:00:00
end: 2024-02-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="BugRA_Trade_Strategy", shorttitle="BugRA_Trade_Strategy", overlay=true)
// Kullanıcı Girdileri
length = input(5, title="Period", minval=1)
percent = input(1, title="Sihirli Yüzde", type=input.float, step=0.1, minval=0)
mav = input(title="Hareketli Ortalama Türü", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])
wt_n1 = input(10, title="Kanal Periyodu")
wt_n2 = input(21, title="Averaj Uzunluğu")
src = close
// Tarih Aralığı Girdileri
startDate = input(20200101, title="Başlangıç Tarihi (YYYYMMDD)")
endDate = input(20201231, title="Bitiş Tarihi (YYYYMMDD)")
// Tarih Filtresi Fonksiyonu
isDateInRange() => true
// Özel Fonksiyonlar
Var_Func(src, length) =>
valpha = 2 / (length + 1)
vud1 = src > src[1] ? src - src[1] : 0
vdd1 = src < src[1] ? src[1] - src : 0
vUD = sum(vud1, length)
vDD = sum(vdd1, length)
vCMO = (vUD - vDD) / (vUD + vDD)
varResult = 0.0
varResult := nz(valpha * abs(vCMO) * src + (1 - valpha * abs(vCMO)) * nz(varResult[1]))
varResult
Wwma_Func(src, length) =>
wwalpha = 1 / length
wwma = 0.0
wwma := wwalpha * src + (1 - wwalpha) * nz(wwma[1])
wwma
Zlema_Func(src, length) =>
zxLag = floor(length / 2)
zxEMAData = src + (src - src[zxLag])
zlema = ema(zxEMAData, length)
zlema
Tsf_Func(src, length) =>
lrc = linreg(src, length, 0)
lrs = lrc - linreg(src, length, 1)
tsf = lrc + lrs
tsf
getMA(src, length) =>
ma = mav == "SMA" ? sma(src, length) :
mav == "EMA" ? ema(src, length) :
mav == "WMA" ? wma(src, length) :
mav == "TMA" ? sma(sma(src, ceil(length / 2)), floor(length / 2) + 1) :
mav == "VAR" ? Var_Func(src, length) :
mav == "WWMA" ? Wwma_Func(src, length) :
mav == "ZLEMA" ? Zlema_Func(src, length) :
mav == "TSF" ? Tsf_Func(src, length) : na
// Strateji Hesaplamaları
MAvg = getMA(src, length)
fark = MAvg * percent * 0.01
longStop = MAvg - fark
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop
shortStop = MAvg + fark
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
MT = dir==1 ? longStop: shortStop
OTT = MAvg > MT ? MT*(200+percent)/200 : MT*(200-percent)/200
plot(OTT, title="BugRA", color=color.rgb(251, 126, 9))
// Alım ve Satım Koşulları
longCondition = crossover(src, OTT) and isDateInRange()
shortCondition = crossunder(src, OTT) and isDateInRange()
// Strateji Giriş ve Çıkış Emirleri
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.close("Long")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-18. 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-Intelligent-Tracking-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
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- BB Breakout StrategyPine Script · Breakout · 1d
- BMSB Breakout Strategy BMSBPine Script · Breakout · 1h
- Bollinger Band T3 Moving Average StrategyPine Script · Breakout · 10m
- Bollinger Bands Dual track Breakthrough StrategyPine Script · Breakout · 30m
- Bollinger Breakout StrategyPine Script · Breakout · 30m