2つの移動平均逆転戦略

作者: リン・ハーンチャオチャン,日付: 2023-11-22 10:07:19
タグ:

img

概要

この戦略の主な考え方は,市場動向を判断し,短期および長期動向平均が逆転するときにポジションを取るために,高速移動平均と遅い移動平均のクロスオーバーを使用して,トレンドを追跡する効果を達成することです.

戦略の論理

  1. 短期の移動平均期間の shortma (デフォルト7日) と長期の移動平均期間の longma (デフォルト77日) を設定する
  2. 短いMAが長いMAを横切ると,それは買い信号と記録バーとして決定されます.長いMAは上昇傾向が始まることを意味します.短いMAが長いMAを下回ると,それは売り信号と記録バーとして決定されます.長いMAは上昇傾向が終わったことを意味します.
  3. バースシント値を比較する.ショートMAが下を横切った後,バース数が多くなるほど,上昇傾向は長く持続する.ショートMAが上を横切った後,バー数が多くなるほど,逆転信号が強くなる.
  4. 売り信号のバーシンスが買い信号のバーシンスより大きい場合,買い信号が起動します.
  5. 基本的には,この戦略は2つのMA逆転戦略であり,トレンド逆転点を検出するために,高速MAsと遅いMAのクロスオーバー逆転を使用する.

利点

  1. 偽信号をフィルタリングするためにダブルMAを使用します
  2. 比較が誤ったブレイクや接近価格の逆転を避けるため,追加されたバー
  3. 分かりやすく実行できます
  4. 調整可能なMAパラメータは,異なる期間と市場に適しています.

リスク

  1. 双 MA 戦略は,より頻繁な取引信号を生み出す傾向があります.
  2. MA パラメータの調節が不十分である場合,より長いトレンドを見逃す可能性があります.
  3. ストップ・ロスは,長期的MAsを破るときは遠ざかって,より大きな引き上げにつながる可能性があります.
  4. コイルと振動を効果的にフィルタリングできない

改善の方向性

  1. 他の指標を追加して,市場を変化させないようにする.
  2. ストップ損失メカニズムを追加する
  3. MA パラメータの組み合わせを最適化
  4. 市場サイクルに基づいて MA パラメータを動的に調整する

概要

戦略全体では,トレンド逆転点を検出するために,迅速かつ遅いMA逆転を使用して,明確で理解しやすい論理を持っています.理論的には,トレンドを効果的に追跡できます. しかし,実際の実装では,アルゴリズムそのものの最適化とパラメータの調整が必要で,より堅牢で実用的です.


/*backtest
start: 2022-11-15 00:00:00
end: 2023-11-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Up Down", "Up Down", precision = 6, pyramiding = 1, default_qty_type = strategy.percent_of_equity, default_qty_value = 99, commission_type = strategy.commission.percent, commission_value = 0.0, initial_capital = 1000, overlay = true)

buy = close > open and open > close[1]
sell = close < open and open < close[1]

longma = input(77,"Long MA Input")
shortma = input(7,"Short MA Input")
long = sma(close,longma)
short = sma(close, shortma)
mabuy = crossover(short,long) or buy and short > long
masell = crossunder(short,long) or sell and short > long

num_bars_buy = barssince(mabuy)
num_bars_sell = barssince(masell)
//plot(num_bars_buy, color = teal)
//plot(num_bars_sell, color = orange)

xbuy = crossover(num_bars_sell, num_bars_buy)
xsell = crossunder(num_bars_sell, num_bars_buy)
plotshape(xbuy,"Buy Up Arrow", shape.triangleup, location.belowbar, white, size = size.tiny)
plotshape(xsell,"Sell Down Arrow", shape.triangledown, location.abovebar, white, size = size.tiny)
plot(long,"Long MA", fuchsia, 2)

// Component Code Start
// Example usage:
// if testPeriod()
//   strategy.entry("LE", strategy.long)
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2019, "Backtest Stop Year")
testStopMonth = input(7, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
// Component Code Stop

if testPeriod()
    strategy.entry("buy", true, when = xbuy, limit = close)
    strategy.close("buy", when = xsell)


もっと