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


作成日: 2023-09-21 20:34:43 最終変更日: 2023-09-21 20:34:43
コピー: 0 クリック数: 675
1
フォロー
1621
フォロワー

概要

この戦略は,速い平均線と遅い平均線の組み合わせを使用して,トレンドの方向を判断し,中長い平均線のトレンドを捕捉するためにトレンド取引を行う.速い平均線上での遅い平均線を横切るときに多行し,速い平均線下での遅い平均線を横切るときに空きをすることは,典型的なトレンド追跡戦略である.

戦略原則

この戦略は,市場動向を判断するために,主に均線の金叉死叉に依存する.具体的には,戦略は,5周期の急速平均線と21周期の遅い平均線を使用する.

急速平均線上を通過すると,市場トレンドが多転し,その戦略は次のK線開盤時に多動する.急速平均線下を通過すると,市場トレンドが逆転し,その戦略は次のK線開盤時に空きをする.

さらに,策略はbarsパラメータを偽突破をフィルタリングするために設定した.このパラメータのデフォルト値は2である.つまり,高速平均線は,遅い速度平均線の上に2つの連続したK線が発信されるだけなら,偽突破を効果的にフィルタリングすることができる.

暗号通貨では,策略には極限判断論理が加えられている. 取引信号は,速平均線と遅平均線が同時に極限領域にある場合にのみ発信される. これは,偽突破をさらに避けるためでもある.

戦略的な退出ルールは簡単で直接的なもので,価格がストップ・ロスを触発すると,現在のポジションを退出する.

戦略的優位性

  • ツイン・均線システムにより,トレンドを効果的に追跡できます.
  • 急速平均線は短く,トレンドの変化を把握できます.
  • ゆっくりとした平均線の長さは,主方向を判定できる
  • barsパラメータは,部分的な偽突破をフィルターします.
  • 極限判定は,鍵点の近くでの偶発的な偽突破を回避する.
  • 移動式ストップを使用してリスクを制御する

戦略リスク

  • 傾向の転換点で損失を起こす可能性が高い
  • 移動停止は,早めに停止する可能性があります.
  • bars 参数フィルタリングは不十分で,買点を見逃す可能性があります
  • 極限判断は,特定の状況で買い点を逃す
  • この戦略は強気なトレンド市場には適しており,振動的な市場には適していません.

リスクは以下の方法で軽減できます.

  • バランスの取れたbarsパラメータを最適化
  • MACDなどの他の指標をフィルターしてみましょう.
  • ストップポイントを調整し,早期のストップを防止する
  • 再入学制度への参加を検討

最適化の方向

この戦略は以下の点で最適化できます.

  1. 平均線参数最適化

より多くの組み合わせをテストして,現在の市場に適した平均線パラメータを見つけることができます.例えば,快線を10周期,慢線を50周期に調整します.

  1. 判断の他の指標に追加

MACD,KDJなどの他の指標をテストすることができ,偽突破を避けるためにより厳しい条件を設定します.

  1. 入学制度の最適化

現在,入学は平均線に依存しすぎているので,以下のように最適化できます.

  • 速線でスローラインを突破すると,MACDDIFFも0を突破して入場する.
  • KDJは,速線でスローラインを切り抜けると,金叉が通っているかどうかを判断して入場する.
  1. 損失防止の最適化

価格を追跡し,早期にストップが発動しないようにするなど,他のストップ方法をテストすることができます.

  1. 復帰へのメカニズム

ポジションが止まった後,再入場が可能で,そうすることで,トレンドを逃した状態の停止を減らすことができます.

要約する

本策は,基礎的なトレンド追跡策として,核心構想はシンプルで直接で,双均線でトレンド判断方向と移動止損を用いることでリスクを制御する.優点は,容易に理解し,実現でき,トレンドに順応して利益を得ることができ,リスクも制御できるという点である.しかし,同時に,いくつかの欠陥があり,市場を整合する際にシグナルが不正確で,止損が早すぎに誘発されやすいという問題がある.これは,我々が市場を整合する際に,継続的に最適化を調整し,他の技術指標を加え,戦略をより異なる市場環境に適応させるためのフィルターを行うことを要求する.全体的に,本策は,トレンド追跡入門策として,初心者にも適しており,学ぶ価値があり,適用性がある.しかし,我々はその限界を注意し,他の高度な戦略の方法を常に学び,継続的に最適化すれば,複雑な市場の変化の中で安定した利益を得ることができる.

ストラテジーソースコード
/*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()