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


作成日: 2023-11-21 17:00:49 最終変更日: 2023-11-21 17:00:49
コピー: 0 クリック数: 604
1
フォロー
1617
フォロワー

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

概要

この戦略は,MACD指標の双均線交差を計算することで,買入と売却のタイミングを判断する.これは,取引シグナルを提示するために,グラフに矢印の形を描画する.

原則

この戦略は,まず,速線 (EMA 12期),慢線 (EMA 26期) とMACDの差値を計算し,それから,速線と慢線の金叉死叉とMACDの差値の正負に基づいて,買入と売却のタイミングを判断する.

  1. 速線で遅線を穿越して (金叉) MACD差値で0を穿越すると買取信号として
  2. 速線下を通過して遅線 ((死叉) とMACD差値の下を通過して0で売り信号として

偽信号をフィルタリングするために,コードでは,前回のK線の信号状態も判断する.現在のK線が反転信号である場合にのみ,現在の信号がトリガーされる.

また,Kオンラインで購入・売却のタイミングを提示する矢印の図も描かれています.

利点

この戦略の利点は以下の通りです.

  1. 双均線交差判断を使用し,市場騒音を効果的にフィルターし,トレンドを識別します.
  2. MACD差値判断と組み合わせることで,欠落や誤判を回避できます.
  3. 矢印の提示で買い物や取引のタイミングを把握する.
  4. 規則はシンプルで明快で,理解し複製しやすい.

リスクと解決策

この戦略にはいくつかのリスクがあります.

  1. 双均線交差は偽信号を生じやすく,過剰取引を引き起こす可能性があります.均線パラメータを適切に調整したり,偽信号を減らすために他のフィルタリング条件を追加したりできます.
  2. トレンドの揺れが判定できない場合,損失が発生する可能性があります. トレンド指標であるADXと組み合わせることで,この状況を回避できます.
  3. 固定的な買取条件は,戦略を機械化し,市場の変化に適応できない. 機械学習などの自己適応方法を試して最適化することができます.

最適化の方向

この戦略は以下の方向から最適化できます.

  1. 異なるパラメータの組み合わせをテストし,最適のFast, Slow, MACDパラメータを見つけます.
  2. 入場条件を追加し,取引量突破で信号をフィルターする
  3. 単一損失を抑えるため,減損メカニズムを増やす.
  4. VIXなどの変動率指標と組み合わせたリスク偏好の判断
  5. 固定規則の代わりに機械学習モデルを試し,戦略の自主的な最適化を実現します.

要約する

この二均線交差矢印策は,全体的に比較的シンプルで実用的で,二均線交差判断とMACD差値フィルタによって,中長線傾向の買出点を識別し,価格転換を逃さないようにすることができる.矢印提示は,操作をより明確に明確にする.後期には,パラメータ最適化,フィルタ条件の追加などによって,戦略の安定性と収益率をさらに高めることができる.

ストラテジーソースコード
/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//Daniels stolen code
strategy(shorttitle="Daniels Stolen Code", title="Daniels Stolen Code", overlay=true, calc_on_order_fills=true, pyramiding=0)

//Define MACD Variables
fast = 12, slow = 26
fastMACD = ema(hlc3, fast)
slowMACD = ema(hlc3, slow)
macd = fastMACD - slowMACD
signal = sma(macd, 9)
hist = macd - signal
currMacd = hist[0]
prevMacd = hist[1]
currPrice = hl2[0]
prevPrice = hl2[1]

buy = currPrice > prevPrice and currMacd > prevMacd
sell = currPrice < prevPrice and currMacd < prevMacd
neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
//Plot Arrows

timetobuy = buy==1 and (sell[1]==1 or (neutral[1]==1 and sell[2]==1) or (neutral[1]==1 and neutral[2]==1 and sell[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and sell[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and sell[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and sell[6]==1))
timetosell = sell==1 and (buy[1]==1 or (neutral[1]==1 and buy[2]==1) or (neutral[1]==1 and neutral[2]==1 and buy[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and buy[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and buy[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and buy[6]==1))

plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
//plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)


//Test Strategy
// strategy.entry("long", true, 1, when = timetobuy and time > timestamp(2017, 01, 01, 01, 01)) // buy by market if current open great then previous high
// strategy.close("long", when = timetosell and time > timestamp(2017, 01, 01, 01, 01))

strategy.order("buy", true, 1, when=timetobuy==1 and time > timestamp(2019, 01, 01, 01, 01))
strategy.order("sell", false, 1, when=timetosell==1 and time > timestamp(2019, 01, 01, 01, 01))



// strategy.entry(id = "Short", long = false, when = enterShort())
// strategy.close(id = "Short", when = exitShort())

//strategy.entry("long", true, 1, when = open > high[1]) // enter long by market if current open great then previous high
// strategy.exit("exit", "long", profit = 10, loss = 5) // ge