
二重移動平均トレンド追跡戦略は,2つの異なる周期の移動平均に基づいて市場のトレンド方向を判断する量的な取引戦略である.この戦略は,急速な移動平均と遅い移動平均の多空状態を使用してトレンド方向を決定し,トレンド方向に取引する.
この戦略は,2つの移動平均を使用し,高速移動平均 (例えば10周期) と遅い移動平均 (例えば30周期) を含む.両移動平均が上昇した場合,多頭トレンドと判断し,両移動平均が低下した場合,空頭トレンドと判断する.
具体的には,戦略はまず,急速移動平均と遅い移動平均を計算する.そして,現在の急速移動平均と前の周期の大きさの関係を比較する.現在の大きさは,前の周期と比べて,値が1で表示されるので,上向きに表示される.それ以外の場合は,値が-1で表示されるので,下向きに表示される.遅い移動平均は,同じ判断をする.
最後に,2つの移動平均の判断値を判断する.両方の判断値が1である場合,最終判断は1で,多頭傾向を表す.両方の判断値が-1である場合,最終判断は-1で,空頭傾向を表す.判断値が一致しない場合は,前の周期の傾向判断を維持する.
トレンドの方向を判断した後に,多頭トレンドで多開,空頭トレンドで空開する.
この戦略の利点は以下の通りです.
この戦略にはリスクもあります.
上記のリスクを軽減するために,移動平均周期パラメータをより合理的に設定し,補助判断として他の技術指標を導入し,ストップ・ストップ・ルールを設定し,またはポジションを適切に調整することができます.
この戦略は,以下の点で最適化できます.
双移動平均トレンドトラッキング戦略の全体的な考え方は明確で分かりやすい.双移動平均のフィルターによる振動,トレンド方向を判断し,判断結果に従って取引する.これは典型的なトレンドトラッキング戦略である.この戦略は,個人の好みに応じて,多量または空白のみを選択することができ,柔軟でシンプルで,操作が容易である.同時に,戦略には一定の利潤リスクがあり,リスクを制御するために補助技術指標,止損ストップなどの追加が必要である.
/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
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/
// © noro
// 2020
//@version=4
strategy(title = "Noro's TrendMA Strategy", shorttitle = "TrendMA str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, commission_value = 0.1)
//Settings
needlong = input(true, title = "Long")
needshort = input(true, title = "Short")
fast = input(10, minval = 1, title = "MA Fast (red)")
slow = input(30, minval = 2, title = "MA Slow (blue)")
type = input(defval = "SMA", options = ["SMA", "EMA"], title = "MA Type")
src = input(ohlc4, title = "MA Source")
showma = input(true, title = "Show MAs")
showbg = input(false, title = "Show Background")
//MAs
fastma = type == "EMA" ? ema(src, fast) : sma(src, fast)
slowma = type == "EMA" ? ema(src, slow) : sma(src, slow)
//Lines
colorfast = showma ? color.red : na
colorslow = showma ? color.blue : na
plot(fastma, color = colorfast, title = "MA Fast")
plot(slowma, color = colorslow, title = "MA Slow")
//Trend
trend1 = fastma > fastma[1] ? 1 : -1
trend2 = slowma > slowma[1] ? 1 : -1
trend = 0
trend := trend1 == 1 and trend2 == 1 ? 1 : trend1 == -1 and trend2 == -1 ? -1 : trend[1]
//Backgrouns
colbg = showbg == false ? na : trend == 1 ? color.lime : trend == -1 ? color.red : na
bgcolor(colbg, transp = 80)
//Trading
if trend == 1
if needlong
strategy.entry("Long", strategy.long)
if needlong == false
strategy.close_all()
if trend == -1
if needshort
strategy.entry("Short", strategy.short)
if needshort == false
strategy.close_all()