アダプティブ・ムービング・メアディアの多要素組み合わせ戦略

作者: リン・ハーンチャオチャン開催日:2023年12月15日11時09分
タグ:

img

I. 戦略の概要

多要素組み合わせ戦略と適応移動平均は,HA線,移動平均,ストカスティッククロスオーバー,日内バーの組み合わせによる複合戦略である.これは,より多くの取引機会を発見し,牛市中により高い累積的収益を達成することを目的としている.

戦略の論理

この戦略の主な論理は,複数の技術指標を組み合わせて,買い・売る信号をスコア化し,マッチング結果に基づいて異なる強度を持つ取引信号を生成することです.

具体的には,戦略で使用される4つの主要な技術指標は以下のとおりです.

  1. Intraday bar.この戦略は,価格動向を決定するために,イントラデイバーの色を使用する. 2つの連続した緑色の実体 HA バーは購入信号を与え, 2つの連続した赤い空洞 HA バーは販売信号を与える.

  2. 移動平均線. 戦略は,異なるパラメータ設定を同時に持つ高速,遅い,フィルター移動平均線を使用する. 速い線がスローラインの上を横切り,スローラインがフィルターライン上を横切ると,購入信号を与えます. そしてその逆です. 移動平均線は中長期トレンドを決定するのに良いです.

  3. ストカスティックインジケーター.このインジケーターは,上昇と下落のクロスオーバーのタイミングを決定します. %K線が下から%D線を突破すると,購入信号を表示します.そして%Kが上から%Dを突破すると,販売信号を表示します.

  4. マッチングスコアメカニズム.上記の要素のマッチングに基づいて,戦略はスコアメカニズムを採用する.マッチング要素が多くなるほど,対応する取引信号が強くなる.

複数の要因を総合的に判断することで,戦略は中期・短期間のより微妙な取引機会を把握し,牛市場での過剰収益を達成することができます.

III. 利点

この多要素戦略の最大の利点は,取引シグナルの信頼性を向上させることです.単一の技術指標は偽信号を生成する傾向があります.複数の指標を組み合わせることで,この戦略は偽信号による干渉を効果的に軽減することができます.

さらに,単一の指標に従うことと比べると,多要素の組み合わせは,取引の勝利率を向上させることができます.牛市中により高い累積的リターンを達成できます.

IV リスク

この戦略の主なリスクは,多要素の組み合わせ自体が戦略の複雑さを増加させるということです.パラメータ設定,複数の指標の頻繁な調整を同時に管理する必要があります.

また,熊市場では,保持時間があまりにも長くなる可能性があります.ストップロスの場合でも,重大な損失が発生することがあります.

さらに,ストカスティック線やHA線のような技術指標は,ブラック・スワンイベントの影響を受け,誤った信号を生み,不必要な損失を引き起こす傾向があります.

V. 改良のアイデア

戦略は以下の側面で最適化できます.

  1. 各指標のパラメータ設定を最適化して最適な組み合わせを見つけます.

  2. リアルタイムパラメータ最適化のためのモデルトレーニングと適応パラメータモジュールを追加します.

  3. ストップ・ロスの戦略を追加して最大引き上げを減らす

  4. ポジション制御モジュールを追加し,市場状況に基づいてポジションを動的に調整します.

  5. マシン学習アルゴリズムを組み込み 多要素スコアシステムのためのニューラルネットワークモデルを構築します

結論

多要素組み合わせ戦略と適応型移動平均は,複数の技術指標の強みを組み合わせます. これは信号品質を効果的に改善し,牛市中に過剰なリターンを達成できます. しかし,同時に,戦略の複雑さを増加させ,さらなるテストと最適化が必要です.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cyrule
//@version=4
strategy("2nd Grade Strategy", overlay=true, shorttitle="2GTS", max_lines_count = 500, max_labels_count = 500, calc_on_every_tick = true, calc_on_order_fills = true, pyramiding = 1, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)

source = input(close, title = "Source")

// **********************
// * Heikin-Ahshi       *
// * kudos to garethyeo *
// **********************
showHA   = input(true, title = "Show Heikin Ashi?", group = "Heikin Ashi")
ha_open  = security(heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high  = security(heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low   = security(heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = security(heikinashi(syminfo.tickerid), timeframe.period, close)

bgcolor(iff(showHA and ha_open < ha_close , color.new(#53b987, transp = 92.5), na), title = 'Green HA')
bgcolor(iff(showHA and ha_open >= ha_close, color.new(#eb4d5c, transp = 92.5), na), title = 'Red HA'  )


// ******************
// * Moving Average *
// ******************
// MA Settings
showMA         = input(true, title = "Show Moving Averages?", group = "Moving Averages")
fastMALength   = input(title = "Fast MA Length", minval = 1, step = 1, defval = 20, group = "Moving Averages")
slowMALength   = input(title = "Slow MA Length", minval = 1, step = 1, defval = 50, group = "Moving Averages")
maType         = input(title = "Moving Average Type", defval = "SMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")
filterMALength = input(title = "Filter MA Length", minval = 1, step = 1, defval = 200, group = "Moving Averages")
filterMAType   = input(title = "Filter MA Type", defval = "EMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")

// Calculate MA
var float maFast   = na
var float maSlow   = na
var float maFilter = na

if (maType   == "SMA")
    maFast   := sma(source, fastMALength)
    maSlow   := sma(source, slowMALength)
if (maType   == "EMA")
    maFast   := ema(source, fastMALength)
    maSlow   := ema(source, slowMALength)
if (maType   == "RMA")
    maFast   := rma(source, fastMALength)
    maSlow   := rma(source, slowMALength)
    maFilter := rma(source, filterMALength)
if (maType   == "WMA")
    maFast   := wma(source, fastMALength)
    maSlow   := wma(source, slowMALength)
if (maType   == "VWMA")
    maFast   := vwma(source, fastMALength)
    maSlow   := vwma(source, slowMALength)

if (filterMAType == "SMA")
    maFilter     := sma(source, filterMALength)
if (filterMAType == "EMA")
    maFilter     := ema(source, filterMALength)
if (filterMAType == "RMA")
    maFilter     := rma(source, filterMALength)
if (filterMAType == "WMA")
    maFilter     := wma(source, filterMALength)
if (filterMAType == "VWMA")
    maFilter     := vwma(source, filterMALength)

BiruAtasMerah = (maFast >= maSlow) and (maSlow >= maFilter)
MerahAtasBiru = (maFast <= maSlow) and (maSlow <= maFilter)

// Lukis MA
plot(series = showMA ? maFast   : na, color = color.blue, title = "MA Fast")
plot(series = showMA ? maSlow   : na, color = color.red,  title = "MA Slow")
plot(series = showMA ? maFilter : na, color = #FFCC00,    title = "MA Filter")


// **************
// * Stochastic *
// **************
// Stochastic Settings
showSSC = input(true, title = "Show Stochastic Crossovers?", group = "Stochastic")
Length = input (10, minval = 1, title = "%K Length", group = "Stochastic")
SmoothK = input (3, minval = 1, title = "%K Smoothing", group = "Stochastic")
SmoothD = input (3, minval = 1, title = "%D Smoothing", group = "Stochastic")

// Calculate Stochastic
var float K = na
var float D = na

if (maType ==  "SMA")
	K      := sma(stoch(source, high, low, Length), SmoothK)
	D      := sma(K, SmoothD)
if (maType ==  "EMA")
	K      := ema(stoch(source, high, low, Length), SmoothK)
	D      := ema(K, SmoothD)
if (maType ==  "RMA")
	K      := rma(stoch(source, high, low, Length), SmoothK)
	D      := rma(K, SmoothD)
if (maType ==  "WMA")
	K      := wma(stoch(source, high, low, Length), SmoothK)
	D      := wma(K, SmoothD)
if (maType ==  "VWMA")
	K      := vwma(stoch(source, high, low, Length), SmoothK)
	D      := vwma(K, SmoothD)

StochasticCrossOver  = crossover(K, D)
StochasticCrossUnder = crossunder(K, D)

// Lukis SS
plotshape(showSSC and StochasticCrossOver  and K <=  20            ? K : na, text = "Golden\nCrossover",  color = color.new(color.green, transp = 25), location = location.belowbar, size = size.tiny, title = "Golden Crossover" )
plotshape(showSSC and StochasticCrossUnder and K >=  80            ? D : na, text = "Deadly\nCrossover",  color = color.new(color.red, transp = 25),   location = location.belowbar, size = size.tiny, title = "Deadly Crossover" )
plotshape(showSSC and StochasticCrossOver  and K <=  80 and K > 20 ? K : na, text = "Bullish\nCrossover", color = color.new(color.green, transp = 50), location = location.belowbar, size = size.tiny, title = "Bullish Crossover")
plotshape(showSSC and StochasticCrossUnder and K >=  20 and K < 80 ? D : na, text = "Bearish\nCrossover", color = color.new(color.red, transp = 50),   location = location.belowbar, size = size.tiny, title = "Bearish Crossover")

showBull = input(true, title = "Show Bullish Signal?", group = "Signal")
showBear = input(false, title = "Show Bearish Signal?", group = "Signal")

bullishCriteria = 0
if (ha_open < ha_close) and (ha_open[1] < ha_close[1]) and (ha_open[2] >= ha_close[2])
    bullishCriteria := bullishCriteria + 1
if (maFast > maSlow) and (maSlow > maFilter)
    bullishCriteria := bullishCriteria + 1
if (K > D) and (K > K[1]) and (D > D[1])
    bullishCriteria := bullishCriteria + 1

bearishCriteria = 0
if (ha_open >= ha_close) and (ha_open[1] >= ha_close[1]) and (ha_open[2] < ha_close[2])
    bearishCriteria := bearishCriteria + 1
if (maFast < maSlow) and (maSlow < maFilter)
    bearishCriteria := bearishCriteria + 1
if (K < D) and (K < K[1]) and (D < D[1])
    bearishCriteria := bearishCriteria + 1

signal = color.new(color.white, transp = 0)
if bearishCriteria == 2
    signal := color.new(color.orange, transp = 50)
if bearishCriteria == 3
    signal := color.new(color.red, transp = 50)
if bullishCriteria == 2
    signal := color.new(color.aqua, transp = 50)
if bullishCriteria == 3
    signal := color.new(color.green, transp = 50)

bullishCriteria := showBull ? bullishCriteria : 0
bearishCriteria := showBear ? bearishCriteria : 0

bgcolor(iff(bullishCriteria > 1, signal, na), title = 'Bullish Signal')
bgcolor(iff(bearishCriteria > 1, signal, na), title = 'Bearish Signal')

longTPPerc  = input(title = "Take Profit Threshold (%)"            , minval = 0.0, step = 0.5, defval = 2.5, group = "Trading") / 100
profitRatio = input(title = "Profit-to-Loss ratio (risk tolerance)", minval = 1.0, step = 0.1, defval = 1.4, group = "Trading")
longSLPerc  = longTPPerc / profitRatio
takeProfit  = strategy.position_avg_price * (1 + longTPPerc)
stopLoss    = strategy.position_avg_price * (1 - longSLPerc)
strategy.initial_capital = 50000
strategy.entry("Long" , strategy.long , floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bullishCriteria > 1)
strategy.entry("Short", strategy.short, floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bearishCriteria > 1)
strategy.close("Long" , when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))
strategy.close("Short", when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))

plotshape(bullishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))
plotshape(bearishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))

もっと