高速移動平均ダブルインジケータークロスオーバーロングとショート戦略


作成日: 2023-11-22 17:29:04 最終変更日: 2023-11-22 17:29:04
コピー: 0 クリック数: 615
1
フォロー
1617
フォロワー

高速移動平均ダブルインジケータークロスオーバーロングとショート戦略

概要

急速移動平均二指数交差多空戦略 (Dual Moving Average Crossover Trend Strategy) は,急速移動平均と遅い移動平均の交差を活用して買入シグナルを形成するトレンド追跡戦略である.この戦略は,MACD,RSIなどの複数の指標を同時に組み合わせてトレンド方向を決定し,強力なトレンド追跡能力を有している.

戦略原則

この戦略は,以下の指標に基づいて判断されます.

  1. 急速移動平均と遅い移動平均:高速線上を通る緩い線は買入信号,高速線下を通る緩い線は売り信号.

  2. MACD:MACD線がSignal線より高く,MACDの最低値が上昇すると多頭信号となる.

  3. RSI:RSIが50を超えると多頭シグナルで,50を下ると空頭シグナルである.

  4. 測定オシレータ (AO):AO上の0軸を穿越して買取信号,AOの下の0軸を穿越して売出信号である.

  5. 日線レベルの3つの移動平均:日線レベルのより短い周期の移動平均を,より長い周期の移動平均に穿え買い信号である。

この戦略は,複数の時間周期と複数の指標を統合して,買入と売却の判断の論理を形成する.複数の指標が同時に買入シグナルが出現するときに買入指示を生成し,複数の指標が同時に売出シグナルが出現するときに売出指示を生成し,トレンドの追跡を実現する.

優位分析

この戦略には以下の利点があります.

  1. 複数の指標を組み合わせて判断し,誤信号を回避し,判断精度を高めます.

  2. 複数のタイムサイクルを組み合わせることで,より大きなレベルのトレンドの方向性を識別できます.

  3. パラメータのパラメータが最適化され,好ましい収益率を持っています.

  4. 移動式止損は,リスクのコントロールと,損失の拡大を防ぐために使用されます.

  5. 自動トレンド追跡機能で,人工の介入を必要とせず,操作コストを削減します.

リスク分析

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

  1. 振動的な状況では,より多くの無効取引シグナルが生じることがあります.指標パラメータを最適化することで無効シグナルを減らすことができます.

  2. 突発的な出来事は,迅速な撤退を引き起こす可能性がある. 損失を制御するために移動停止を設定できます.

  3. 多空信号判定規則は複雑で,パラメータ最適化には大量の歴史データが必要である.

  4. トラッキング停止設定が不適切である場合,早めに停止することがあります. 最適なパラメータを決定するために繰り返しテストする必要があります.

最適化の方向

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

  1. 波動率指数,OBV指数など,より安定で正確な取引信号を探すために,より多くの指標の組み合わせをテストします.

  2. 指標パラメータを最適化し,無効取引の回数を減らす. 機械学習と遺伝的アルゴリズムの自動検索パラメータ.

  3. モデル統合技術を追加し,より多くの独立した戦略モデル判断結果を統合する. 安定性を向上させる.

  4. 高周波レベルでの入場,低周波レベルでの退出. 隠蔽されるリスクを減らす.

  5. 量化風制御モジュールを追加し,単発停止損失比率,最大撤回比率などを厳格に制御する.

要約する

速動平均線双指標交差多空策は,速動平均線と遅動平均線の交差によって取引信号を形成し,MACD,RSIなどの複数の指標と組み合わせてトレンドの方向性を判断し,自動化されたトレンド追跡を実現する.この戦略の最適化スペースは大きい.より多くの指標を導入し,パラメータを調整し,モデル統合などの手段によってより良い戦略効果が得られる.

ストラテジーソースコード
/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('SteffVans', shorttitle='SteffVans strategy', overlay=true, process_orders_on_close = true)

// Input settings
macd_fast_length = input(12)
macd_slow_length = input(26)
macd_signal_length = input(9)

// Calculate MACD values
[macd_line, signal_line, _] = ta.macd(close, macd_fast_length, macd_slow_length, macd_signal_length)
mg = ta.lowest(signal_line, 30) >= -0

// RSI
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1)
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
RSI = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))


//  AO
AO = ta.sma((high + low) / 2, 5) - ta.sma((high + low) / 2, 34)
crossaosell = AO < AO[1] and AO[1] < AO[2] and AO[2] > AO[3]  and ta.lowest(low,3)

// Uptrend sma
len1 = input.int(5, minval=1)
len2 = input.int(10, minval=1)
len3 = input.int(20, minval=1)
src = input(close)

out1 = ta.sma(src, len1)
out2 = ta.sma(src, len2)
out3 = ta.sma(src, len3)



// Timeframe 
macdl60 = request.security(syminfo.tickerid, "60", signal_line,lookahead = barmerge.lookahead_on)
ao = request.security(syminfo.tickerid, "60", AO,lookahead = barmerge.lookahead_on)
rsi = request.security(syminfo.tickerid, "60", RSI,lookahead = barmerge.lookahead_on)
good = request.security(syminfo.tickerid, "60", mg,lookahead = barmerge.lookahead_on)
bad = request.security(syminfo.tickerid, "60", crossaosell,lookahead = barmerge.lookahead_on)

ma1 = request.security(syminfo.tickerid, "D", out1,lookahead = barmerge.lookahead_on)
ma2 = request.security(syminfo.tickerid, "D", out2, lookahead = barmerge.lookahead_on)
ma3 = request.security(syminfo.tickerid, "D", out3, lookahead = barmerge.lookahead_on)






// Kriteria BUY and SELL
uptrend1 =  request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) > ma1 and ma1 > ma3 and ma2 > ma3
uptrend2 = ta.lowest(ma1,12) > ta.lowest(ma3,12) and ta.lowest(ma2,12) > ta.lowest(ma3,12) 


 

// Triger BUY and SELL 
cross1 = ao > ao[1] and ao[1] < ao[2] and ao > 0 and good and rsi >= 60 and uptrend1
cross2 = ao > 0 and ao[1] < 0 and good and rsi >=50 and uptrend1
cross3 =  ao > 0 and ao[1] < 0 and not good and uptrend2 and uptrend1
cross4 =  ao > ao[1] and ao[1] > ao[2] and ao[2] < ao[3] and ao[3] < ao[4]  and not good and uptrend2 and uptrend1

s1 = ao < ao[1] and ao[1] < ao[2] and ao[2] < ao[3] and ao > 0 and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1
s2 =  ao < 0 and ao < ao[2] and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1 

// Variabel Buy dan Sell
buySignal = false
sellSignal = false

// Syarat masuk Buy
buyCondition =  cross1 or cross2 or cross3 or cross4
if buyCondition
    buySignal := true

// Syarat masuk Sell
sellCondition = s1 or s2
if sellCondition
    sellSignal := true

// Reset sinyal jika ada sinyal berulang
if buySignal and sellSignal
    sellSignal := false
if sellSignal and buySignal
    buySignal := false

// Logika perdagangan
if buySignal
    strategy.entry("Buy", strategy.long, comment = "BUY")
if sellSignal
    strategy.close("Buy")


plotshape(cross1,title = "Stefkuy1", style = shape.labelup, location = location.belowbar, color = color.green,text = "1", textcolor = color.white,size = size.small)
plotshape(cross2,title = "Stefkuy2", style = shape.labelup, location = location.belowbar, color = color.green, text = "2", textcolor= color.white, size = size.small)
plotshape(cross3,title = "StefVan1", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "3", textcolor= color.white,size = size.small)
plotshape(cross4,title = "StefVan2", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "4", textcolor= color.white,size = size.small)