ダブル移動平均クロスオーバー反転戦略


作成日: 2023-11-22 10:07:19 最終変更日: 2023-11-22 10:07:19
コピー: 1 クリック数: 605
1
フォロー
1617
フォロワー

ダブル移動平均クロスオーバー反転戦略

概要

この戦略の主な考えは,速い移動平均線と遅い移動平均線の交差を活用して市場のトレンドを判断し,短線と長い移動平均線が逆転したときに入場し,トレンドを追跡する効果を実現することである.

戦略原則

  1. 設定 急速移動平均線周期shortma (デフォルト 7 日) と 遅移動平均線周期longma (デフォルト 77 日)
  2. ショートラインが平均線上を長線を横切るときは買入信号として判断し, barssince ((mabuy)) と記録し,長線はトレンドへの入りを意味する. ショートラインが平均線下を長線を横切るときは売り信号として判断し, barssince ((masell)) と記録し,長線はトレンドの終了を意味する.
  3. barssinceの大きさを比較すると,短線平均線が上から下へと交差するバー数が多いほど,トレンドの持続期間が長くなる;逆に,短線平均線が下から上へと交差する数が多いほど,反転信号が強くなる.
  4. 売り信号のバー数が買信号のバー数より大きいときに買信号を発信する. 買信号のバー数が売り信号のバー数より大きいときに売信号を発信する
  5. such戦略は本質的に双均線の反転戦略であり,急速均線と遅い均線の反転によってトレンドの転換点を判断する.

戦略的優位性

  1. バイアスリーナリー判断で,部分的なノイズ取引信号をフィルターします.
  2. barssince比較を追加し,偽断ちとクローズ価格の反転による誤信号を回避する
  3. 簡単に理解し 実行できます
  4. 異なる周期と市場に適用できるカスタマイズ可能な移動平均線パラメータ

戦略リスク

  1. 双対一線戦略は,より多くのシグナルを生成しやすく,取引が頻繁に行われます.
  2. 移動平均線のパラメータを正しく設定しない場合,より長いトレンドのチャンスを逃す可能性があります.
  3. 長期平均線を突破すると,止まり点は遠く,大きな後退がある可能性があります.
  4. 市場を効率的にフィルターできない

戦略最適化の方向性

  1. 他の指標のフィルターを追加し,震動の状況に巻き込まれないようにする.
  2. 損失防止の強化
  3. 移動平均線参数组合を最適化する
  4. 市場周期の動向に調整された移動平均線パラメータ

要約する

この戦略は全体的に論理的にわかりやすく,急速な平均線と遅い平均線の逆転によって市場トレンドの転換点を判断し,理論的にはトレンドを効果的に追跡することができる.しかし,実用的には,戦略アルゴリズム自体とパラメータ設定を最適化して,より安定して実戦的にする必要がある.

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