トレンド移動平均取引戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-21 20:34:43
タグ:

概要

この戦略は,トレンドトレードでトレンド方向を決定し,中期から長期間のトレンドを把握するために,高速移動平均値と遅い移動平均値の組み合わせを使用する.高速MAが遅いMAを超えると長くなって,高速MAが遅いMAを下回ると短くなってしまいます.これは典型的なトレンドフォロー戦略です.

戦略の論理

この戦略は,主に移動平均値の黄金十字と死十字を基に市場動向を決定する.特に,5期間の高速MAと21期間の遅いMAを使用する.

速いMAがスローMAを超えると,市場の上昇傾向を示し,戦略は次のバーのオープンでロングになります.速いMAがスローMAを下回ると,ダウントレンドを示し,戦略は次のバーのオープンでショートになります.

さらに,barsパラメータは偽ブレイクをフィルタリングするように設定されている.デフォルト値は2である.これは,長い信号をトリガーする前に,速いMAが遅いMAよりも2バー連続で閉じる必要があることを意味します.これは誤ったブレイクを効果的に回避します.

暗号取引では,戦略には極端な値論理も組み込まれています. 急速なMAsと遅いMAsが極端な領域に到達するときにのみ,取引信号が起動します. これにより,誤った信号がさらに回避されます.

ストップ・ロスは簡単で直線的です ストップ・ロスは直接です

利点

  • 二重MAシステムにより,動向を効果的に追跡できます.
  • 急速なMAはトレンド変化に迅速に対応する
  • ゆっくりとしたMAは全体的な方向性を決定します
  • barsパラメータは,いくつかの偽のブレイクをフィルターします.
  • 極端な値ガードが 臨界点の周りに散発的な誤った信号を避ける
  • ストップロスの移動はリスクを管理する

リスク

  • 双重MAシステムは傾向の逆転に負ける傾向があります
  • 移動ストップ損失は早めに停止する可能性があります.
  • barsフィルターは,有効な信号を見逃す可能性があります.
  • 極端な価値保護者は 時々良いエントリを見逃します
  • この戦略は,強いトレンド市場でよりうまく機能します

リスクは以下によって軽減できます.

  • barsパラメータの最適化
  • MACD のような他のフィルターを追加する
  • 早期停止を避けるためにストップ損失レベルを調整する
  • 再入国を検討する

オプティマイゼーションの方向性

戦略は以下の側面から改善できます.

  1. MA パラメータ調整

現在の市場に最適なパラメータを見つけるために,より多くのMA組み合わせをテストします.例えば,10期間の高速MAと50期間の遅いMAです.

  1. 他の指標を追加する

テストは,MACD,KDJ,その他の指標を足して,より厳格なエントリールールを設定し,誤った信号を回避します.

  1. エントリを最適化する

現在の単純な二重MAエントリが強化される:

  • MACDDIFF が 0 を越え,高速MA が遅いMA を越えるときのみ,長を入力する.
  • KDJが速いMAが遅いMAを上回るときに黄色の十字を表示する場合にのみ,ロングを入力します.
  1. 停止を最適化する

遅延停止などの他の停止メカニズムを試し,早速停止を避ける.

  1. 再入力を追加する

ストップが切れた後に再入荷を許可します 傾向を見逃さないようにするためです

概要

概要すると,この基本トレンドフォロー戦略は,シンプルで直接的なロジックを持っています.トレンド指向のためのダブルMAとリスク管理のための移動ストップを使用します.プロは理解しやすく,トレンドから利益を得ることができ,リスクを管理できます.しかし,統合中に悪い信号,早速ストップアウトなど,制限も存在します.フィルターを追加し,ストップを調整し,異なる市場環境に適応できるようにするために,ライブチューニングと最適化が必要です.導入トレンドトレーディング戦略として,それは初心者が学び,適用するのに適しています.しかし,その制限は注意すべきで,より高度な戦略は改善されるべきです.継続的な改善を通じてのみ,常に変化する市場で持続的な利益を達成することができます.


/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title = "Noro's Trend MAs Strategy v2.3", shorttitle = "Trend MAs str 2.3", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needex = input(true, defval = true, title = "Need extreme? (crypto/fiat only!!!)")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

src = close

//PriceChannel 1
lasthigh = highest(src, slowlen)
lastlow = lowest(src, slowlen)
center = (lasthigh + lastlow) / 2

//PriceChannel 2
lasthigh2 = highest(src, fastlen)
lastlow2 = lowest(src, fastlen)
center2 = (lasthigh2 + lastlow2) / 2

//Trend
trend = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]

//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Fast RSI
fastup = rma(max(change(close), 0), 2)
fastdown = rma(-min(change(close), 0), 2)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//CryptoBottom
mac = sma(close, 10)
len = abs(close - mac)
sma = sma(len, 100)
max = max(open, close)
min = min(open, close)

//Signals
up1 = trend == 1 and (low < center2 or usefastsma == false) and redbars == 1
dn1 = trend == -1 and (high > center2 or usefastsma == false) and greenbars == 1
up2 = high < center and high < center2 and bar == -1 and needex
dn2 = low > center and low > center2 and bar == 1 and needex
up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0

//Lines
plot(center2, color = red, linewidth = 3, transp = 0, title = "Fast MA")
plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA")

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 80)

//Trading
stoplong = up1 == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn1 == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

if up1 or up2 or up3
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    strategy.exit("Stop Long", "Long", stop = stoplong)

if dn1
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    strategy.exit("Stop Short", "Short", stop = stopshort)
    
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    

もっと